Browse Source

ref(fixtures): Refactor Dashboard & Widget fixtures to tsx (#55291)

Ryan Albrecht 1 year ago
parent
commit
5029373a8a

+ 0 - 13
fixtures/js-stubs/dashboard.js

@@ -1,13 +0,0 @@
-import {Widget} from './widget';
-
-const DEFAULT_WIDGETS = [Widget()];
-
-export function Dashboard(widgets = DEFAULT_WIDGETS, props = {}) {
-  return {
-    id: 1,
-    title: 'Dashboard',
-    createdBy: '',
-    widgets,
-    ...props,
-  };
-}

+ 20 - 0
fixtures/js-stubs/dashboard.tsx

@@ -0,0 +1,20 @@
+import type {
+  DashboardDetails as TDashboardDetails,
+  DashboardFilters as TDashboardFilters,
+  Widget as TWidget,
+} from 'sentry/views/dashboards/types';
+
+export function Dashboard(
+  widgets: TWidget[],
+  props: Partial<TDashboardDetails> = {}
+): TDashboardDetails {
+  return {
+    id: '1',
+    filters: [] as TDashboardFilters,
+    dateCreated: new Date().toISOString(),
+    projects: undefined,
+    title: 'Dashboard',
+    widgets,
+    ...props,
+  };
+}

+ 0 - 39
fixtures/js-stubs/widget.js

@@ -1,39 +0,0 @@
-const DEFAULT_QUERIES = {
-  discover: [
-    {
-      name: 'Known Users',
-      fields: [],
-      columns: [],
-      aggregates: ['count()'],
-      conditions: [['user.email', 'IS NOT NULL', null]],
-      aggregations: [['uniq', 'user.email', 'Known Users']],
-      limit: 1000,
-
-      orderby: '-time',
-      groupby: ['time'],
-      rollup: 86400,
-    },
-    {
-      name: 'Anonymous Users',
-      fields: [],
-      columns: [],
-      aggregates: ['count()'],
-      conditions: [['user.email', 'IS NULL', null]],
-      aggregations: [['count()', null, 'Anonymous Users']],
-      limit: 1000,
-
-      orderby: '-time',
-      groupby: ['time'],
-      rollup: 86400,
-    },
-  ],
-};
-
-export function Widget(queries = {...DEFAULT_QUERIES}, options) {
-  return {
-    type: 'line',
-    queries,
-    title: 'Widget',
-    ...options,
-  };
-}

+ 15 - 0
fixtures/js-stubs/widget.tsx

@@ -0,0 +1,15 @@
+import type {
+  Widget as TWidget,
+  WidgetQuery as TWidgetQuery,
+} from 'sentry/views/dashboards/types';
+import {DisplayType} from 'sentry/views/dashboards/types';
+
+export function Widget(queries: TWidgetQuery[], options: Partial<TWidget>): TWidget {
+  return {
+    displayType: DisplayType.LINE,
+    interval: '1d',
+    queries,
+    title: 'Widget',
+    ...options,
+  };
+}

+ 1 - 1
static/app/views/dashboards/types.tsx

@@ -91,7 +91,7 @@ export type DashboardDetails = {
   dateCreated: string;
   dateCreated: string;
   filters: DashboardFilters;
   filters: DashboardFilters;
   id: string;
   id: string;
-  projects: number[];
+  projects: undefined | number[];
   title: string;
   title: string;
   widgets: Widget[];
   widgets: Widget[];
   createdBy?: User;
   createdBy?: User;