Преглед на файлове

refactor: merged types and updated references

Hugo Häggmark преди 6 години
родител
ревизия
d845aacbdc

+ 17 - 2
public/app/core/components/SharedPreferences/SharedPreferences.tsx

@@ -3,7 +3,7 @@ import React, { PureComponent } from 'react';
 import { FormLabel, Select } from '@grafana/ui';
 import { getBackendSrv, BackendSrv } from 'app/core/services/backend_srv';
 
-import { DashboardSearchHit } from 'app/types';
+import { DashboardSearchHit, DashboardSearchHitType } from 'app/types';
 
 export interface Props {
   resourceUri: string;
@@ -41,6 +41,21 @@ export class SharedPreferences extends PureComponent<Props, State> {
   async componentDidMount() {
     const prefs = await this.backendSrv.get(`/api/${this.props.resourceUri}/preferences`);
     const dashboards = await this.backendSrv.search({ starred: true });
+    const defaultDashboardHit: DashboardSearchHit = {
+      id: 0,
+      title: 'Default',
+      tags: [],
+      type: '' as DashboardSearchHitType,
+      uid: '',
+      uri: '',
+      url: '',
+      folderId: 0,
+      folderTitle: '',
+      folderUid: '',
+      folderUrl: '',
+      isStarred: false,
+      slug: '',
+    };
 
     if (prefs.homeDashboardId > 0 && !dashboards.find(d => d.id === prefs.homeDashboardId)) {
       const missing = await this.backendSrv.search({ dashboardIds: [prefs.homeDashboardId] });
@@ -53,7 +68,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
       homeDashboardId: prefs.homeDashboardId,
       theme: prefs.theme,
       timezone: prefs.timezone,
-      dashboards: [{ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' }, ...dashboards],
+      dashboards: [defaultDashboardHit, ...dashboards],
     });
   }
 

+ 2 - 23
public/app/core/services/backend_srv.ts

@@ -3,28 +3,7 @@ import coreModule from 'app/core/core_module';
 import appEvents from 'app/core/app_events';
 import config from 'app/core/config';
 import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
-
-export enum HitType {
-  DashHitDB = 'dash-db',
-  DashHitHome = 'dash-home',
-  DashHitFolder = 'dash-folder',
-}
-
-export interface Hit {
-  id: number;
-  uid: string;
-  title: string;
-  uri: string;
-  url: string;
-  slug: string;
-  type: HitType;
-  tags: string[];
-  isStarred: boolean;
-  folderId: number;
-  folderUid: string;
-  folderTitle: string;
-  folderUrl: string;
-}
+import { DashboardSearchHit } from 'app/types/search';
 
 export class BackendSrv {
   private inFlightRequests = {};
@@ -259,7 +238,7 @@ export class BackendSrv {
     return this.request({ url: '/api/login/ping', method: 'GET', retry: 1 });
   }
 
-  search(query): Promise<Hit[]> {
+  search(query): Promise<DashboardSearchHit[]> {
     return this.get('/api/search', query);
   }
 

+ 3 - 2
public/app/core/services/search_srv.ts

@@ -7,8 +7,9 @@ import coreModule from 'app/core/core_module';
 import impressionSrv from 'app/core/services/impression_srv';
 import store from 'app/core/store';
 import { contextSrv } from 'app/core/services/context_srv';
-import { BackendSrv, Hit } from './backend_srv';
+import { BackendSrv } from './backend_srv';
 import { Section } from '../components/manage_dashboards/manage_dashboards';
+import { DashboardSearchHit } from 'app/types/search';
 
 interface Sections {
   [key: string]: Partial<Section>;
@@ -128,7 +129,7 @@ export class SearchSrv {
     });
   }
 
-  private handleSearchResult(sections: Sections, results: Hit[]): any {
+  private handleSearchResult(sections: Sections, results: DashboardSearchHit[]): any {
     if (results.length === 0) {
       return sections;
     }

+ 14 - 3
public/app/types/search.ts

@@ -1,9 +1,20 @@
+export enum DashboardSearchHitType {
+  DashHitDB = 'dash-db',
+  DashHitHome = 'dash-home',
+  DashHitFolder = 'dash-folder',
+}
 export interface DashboardSearchHit {
   id: number;
-  tags: string[];
-  title: string;
-  type: string;
   uid: string;
+  title: string;
   uri: string;
   url: string;
+  slug: string;
+  type: DashboardSearchHitType;
+  tags: string[];
+  isStarred: boolean;
+  folderId: number;
+  folderUid: string;
+  folderTitle: string;
+  folderUrl: string;
 }