From d845aacbdc8bff3e5daa7efddc7817bbb261e126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 19 Mar 2019 17:44:58 +0100 Subject: [PATCH] refactor: merged types and updated references --- .../SharedPreferences/SharedPreferences.tsx | 19 ++++++++++++-- public/app/core/services/backend_srv.ts | 25 ++----------------- public/app/core/services/search_srv.ts | 5 ++-- public/app/types/search.ts | 17 ++++++++++--- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.tsx index 171e0e8109e..a39eefcec4b 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.tsx +++ b/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 { 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 { homeDashboardId: prefs.homeDashboardId, theme: prefs.theme, timezone: prefs.timezone, - dashboards: [{ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' }, ...dashboards], + dashboards: [defaultDashboardHit, ...dashboards], }); } diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 53ab3ab6ce7..0d7d098dcea 100644 --- a/public/app/core/services/backend_srv.ts +++ b/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 { + search(query): Promise { return this.get('/api/search', query); } diff --git a/public/app/core/services/search_srv.ts b/public/app/core/services/search_srv.ts index 4a605d3fc50..068fe3ffbc3 100644 --- a/public/app/core/services/search_srv.ts +++ b/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
; @@ -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; } diff --git a/public/app/types/search.ts b/public/app/types/search.ts index e5e17288de1..e15797f41a3 100644 --- a/public/app/types/search.ts +++ b/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; }