import {Fragment} from 'react';
import styled from '@emotion/styled';
import Feature from 'sentry/components/acl/feature';
import FeatureDisabled from 'sentry/components/acl/featureDisabled';
import {Button} from 'sentry/components/button';
import ButtonBar from 'sentry/components/buttonBar';
import Confirm from 'sentry/components/confirm';
import {Hovercard} from 'sentry/components/hovercard';
import Tooltip from 'sentry/components/tooltip';
import {IconAdd, IconEdit} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import space from 'sentry/styles/space';
import {Organization} from 'sentry/types';
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
import {UNSAVED_FILTERS_MESSAGE} from './detail';
import {DashboardListItem, DashboardState, MAX_WIDGETS} from './types';
type Props = {
dashboardState: DashboardState;
dashboards: DashboardListItem[];
onAddWidget: () => void;
onCancel: () => void;
onCommit: () => void;
onDelete: () => void;
onEdit: () => void;
organization: Organization;
widgetLimitReached: boolean;
hasUnsavedFilters?: boolean;
};
function Controls({
organization,
dashboardState,
dashboards,
hasUnsavedFilters,
widgetLimitReached,
onEdit,
onCommit,
onDelete,
onCancel,
onAddWidget,
}: Props) {
function renderCancelButton(label = t('Cancel')) {
return (
);
}
if ([DashboardState.EDIT, DashboardState.PENDING_DELETE].includes(dashboardState)) {
return (
{renderCancelButton()}
);
}
if (dashboardState === DashboardState.CREATE) {
return (
{renderCancelButton()}
);
}
if (dashboardState === DashboardState.PREVIEW) {
return (
{renderCancelButton(t('Go Back'))}
);
}
return (
{hasFeature => (
{hasFeature ? (
}
onClick={() => {
trackAdvancedAnalyticsEvent(
'dashboards_views.widget_library.opened',
{
organization,
}
);
onAddWidget();
}}
>
{t('Add Widget')}
) : null}
)}
);
}
const DashboardEditFeature = ({
children,
}: {
children: (hasFeature: boolean) => React.ReactNode;
}) => {
const renderDisabled = p => (
}
>
{p.children(p)}
);
return (
{({hasFeature}) => children(hasFeature)}
);
};
const StyledButtonBar = styled(ButtonBar)`
@media (max-width: ${p => p.theme.breakpoints.small}) {
grid-auto-flow: row;
grid-row-gap: ${space(1)};
width: 100%;
}
`;
export default Controls;