utils.tsx 946 B

12345678910111213141516171819202122232425262728293031323334
  1. import cloneDeep from 'lodash/cloneDeep';
  2. import {GlobalSelection} from 'app/types';
  3. import {getUtcDateString} from 'app/utils/dates';
  4. import EventView from 'app/utils/discover/eventView';
  5. import {DashboardDetails, WidgetQuery} from './types';
  6. export function cloneDashboard(dashboard: DashboardDetails): DashboardDetails {
  7. return cloneDeep(dashboard);
  8. }
  9. export function eventViewFromWidget(
  10. title: string,
  11. query: WidgetQuery,
  12. selection: GlobalSelection
  13. ): EventView {
  14. const {start, end, period: statsPeriod} = selection.datetime;
  15. const {projects, environments} = selection;
  16. return EventView.fromSavedQuery({
  17. id: undefined,
  18. name: title,
  19. version: 2,
  20. fields: query.fields,
  21. query: query.conditions,
  22. orderby: query.orderby,
  23. projects,
  24. range: statsPeriod,
  25. start: start ? getUtcDateString(start) : undefined,
  26. end: end ? getUtcDateString(end) : undefined,
  27. environment: environments,
  28. });
  29. }