feat(v2/views): Add read views api util (#999)

feat(v2/views): Add read views api util
pull/10616/head
Delmer 2018-10-10 10:08:41 -04:00 committed by GitHub
parent beed7c7ad7
commit 03236c2d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -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<View> => {
const {data} = await AJAX({url})
@ -35,3 +38,21 @@ export const updateView = async (
return data
}
export const readViews = async (
url: string,
params?: ViewParams
): Promise<View[]> => {
try {
const response = await AJAX({
method: 'GET',
url,
params,
})
return getDeep<View[]>(response, 'data.views', [])
} catch (error) {
console.error(error)
return []
}
}

View File

@ -270,3 +270,7 @@ export interface DashboardSwitcherLinks {
active?: DashboardSwitcherLink
links: DashboardSwitcherLink[]
}
export interface ViewParams {
type: ViewType
}

View File

@ -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,
}