diff --git a/chronograf/ui/src/dashboards/apis/v2/view.ts b/chronograf/ui/src/dashboards/apis/v2/view.ts index 2851b1052f..badff4d79c 100644 --- a/chronograf/ui/src/dashboards/apis/v2/view.ts +++ b/chronograf/ui/src/dashboards/apis/v2/view.ts @@ -1,8 +1,11 @@ // Libraries import AJAX from 'src/utils/ajax' +// Utils +import {getDeep} from 'src/utils/wrappers' + // Types -import {View} from 'src/types/v2' +import {View, ViewParams} from 'src/types/v2' export const readView = async (url: string): Promise => { const {data} = await AJAX({url}) @@ -35,3 +38,21 @@ export const updateView = async ( return data } + +export const readViews = async ( + url: string, + params?: ViewParams +): Promise => { + try { + const response = await AJAX({ + method: 'GET', + url, + params, + }) + + return getDeep(response, 'data.views', []) + } catch (error) { + console.error(error) + return [] + } +} diff --git a/chronograf/ui/src/types/v2/dashboards.ts b/chronograf/ui/src/types/v2/dashboards.ts index 7bcfd87f8b..034342f653 100644 --- a/chronograf/ui/src/types/v2/dashboards.ts +++ b/chronograf/ui/src/types/v2/dashboards.ts @@ -270,3 +270,7 @@ export interface DashboardSwitcherLinks { active?: DashboardSwitcherLink links: DashboardSwitcherLink[] } + +export interface ViewParams { + type: ViewType +} diff --git a/chronograf/ui/src/types/v2/index.ts b/chronograf/ui/src/types/v2/index.ts index e30823aacc..4fbb57b063 100644 --- a/chronograf/ui/src/types/v2/index.ts +++ b/chronograf/ui/src/types/v2/index.ts @@ -11,6 +11,7 @@ import { View, ViewType, ViewShape, + ViewParams, DashboardQuery, } from 'src/types/v2/dashboards' import {Links} from 'src/types/v2/links' @@ -36,6 +37,7 @@ export { View, ViewType, ViewShape, + ViewParams, TimeRange, DashboardSwitcherLinks, }