123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import {useMemo} from 'react';
- import {openCreateDashboardFromScratchpad} from 'sentry/actionCreators/modal';
- import {convertToDashboardWidget} from 'sentry/utils/metrics/dashboard';
- import {MetricQueryType} from 'sentry/utils/metrics/types';
- import useOrganization from 'sentry/utils/useOrganization';
- import usePageFilters from 'sentry/utils/usePageFilters';
- import useRouter from 'sentry/utils/useRouter';
- import {useDDMContext} from 'sentry/views/ddm/context';
- export function useCreateDashboard() {
- const router = useRouter();
- const organization = useOrganization();
- const {widgets} = useDDMContext();
- const {selection} = usePageFilters();
- return useMemo(() => {
- return function () {
- const newDashboard = {
- title: 'Metrics Dashboard',
- description: '',
- widgets: widgets
- // TODO(aknaus): Remove filtering once dashboard supports metrics formulas
- .filter(widget => widget.type === MetricQueryType.QUERY && !!widget.mri)
- .map(widget =>
- // @ts-expect-error TODO(ogi): fix this
- convertToDashboardWidget(widget, widget.displayType)
- )
- // Only import the first 30 widgets because of dashboard widget limit
- .slice(0, 30),
- projects: selection.projects,
- environment: selection.environments,
- start: selection.datetime.start as string,
- end: selection.datetime.end as string,
- period: selection.datetime.period as string,
- filters: {},
- utc: selection.datetime.utc ?? false,
- id: 'ddm-scratchpad',
- dateCreated: '',
- };
- openCreateDashboardFromScratchpad({newDashboard, router, organization});
- };
- }, [selection, widgets, organization, router]);
- }
|