Type remaining new fns in dashboard/utils/tempVars.ts
parent
a15a950992
commit
77b475cd6b
|
@ -1,7 +1,14 @@
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
import {TEMPLATE_VARIABLE_QUERIES} from 'src/dashboards/constants'
|
import {TEMPLATE_VARIABLE_QUERIES} from 'src/dashboards/constants'
|
||||||
import {Template, TemplateQuery, URLQueries} from 'src/types/tempVars'
|
import {
|
||||||
|
Dashboard,
|
||||||
|
Template,
|
||||||
|
TemplateQuery,
|
||||||
|
TemplateValue,
|
||||||
|
URLQueries,
|
||||||
|
} from 'src/types'
|
||||||
|
import {TemplateUpdate} from 'src/types/tempVars'
|
||||||
|
|
||||||
interface PartialTemplateWithQuery {
|
interface PartialTemplateWithQuery {
|
||||||
query: string
|
query: string
|
||||||
|
@ -90,10 +97,15 @@ export const generateURLQueriesFromTempVars = (
|
||||||
return urlQueries
|
return urlQueries
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isValidTempVarOverride = (values, overrideValue) =>
|
export const isValidTempVarOverride = (
|
||||||
!!values.find(({value}) => value === overrideValue)
|
values: TemplateValue[],
|
||||||
|
overrideValue: string
|
||||||
|
): boolean => !!values.find(({value}) => value === overrideValue)
|
||||||
|
|
||||||
const reconcileTempVarsWithOverrides = (currentTempVars, tempVarOverrides) => {
|
const reconcileTempVarsWithOverrides = (
|
||||||
|
currentTempVars: Template[],
|
||||||
|
tempVarOverrides: URLQueries
|
||||||
|
): Template[] => {
|
||||||
if (!tempVarOverrides) {
|
if (!tempVarOverrides) {
|
||||||
return currentTempVars
|
return currentTempVars
|
||||||
}
|
}
|
||||||
|
@ -126,9 +138,9 @@ const reconcileTempVarsWithOverrides = (currentTempVars, tempVarOverrides) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applyDashboardTempVarOverrides = (
|
export const applyDashboardTempVarOverrides = (
|
||||||
dashboard,
|
dashboard: Dashboard,
|
||||||
tempVarOverrides
|
tempVarOverrides: URLQueries
|
||||||
) => ({
|
): Dashboard => ({
|
||||||
...dashboard,
|
...dashboard,
|
||||||
templates: reconcileTempVarsWithOverrides(
|
templates: reconcileTempVarsWithOverrides(
|
||||||
dashboard.templates,
|
dashboard.templates,
|
||||||
|
@ -136,7 +148,10 @@ export const applyDashboardTempVarOverrides = (
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const findUpdatedTempVarsInURLQuery = (tempVars, urlQueries) => {
|
export const findUpdatedTempVarsInURLQuery = (
|
||||||
|
tempVars: Template[],
|
||||||
|
urlQueries: URLQueries
|
||||||
|
): TemplateUpdate[] => {
|
||||||
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
||||||
urlQueries,
|
urlQueries,
|
||||||
(acc, v, k) => {
|
(acc, v, k) => {
|
||||||
|
@ -159,7 +174,10 @@ export const findUpdatedTempVarsInURLQuery = (tempVars, urlQueries) => {
|
||||||
return urlQueryTempVarsWithInvalidValues
|
return urlQueryTempVarsWithInvalidValues
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findInvalidTempVarsInURLQuery = (tempVars, urlQueries) => {
|
export const findInvalidTempVarsInURLQuery = (
|
||||||
|
tempVars: Template[],
|
||||||
|
urlQueries: URLQueries
|
||||||
|
): TemplateUpdate[] => {
|
||||||
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
||||||
urlQueries,
|
urlQueries,
|
||||||
(acc, v, k) => {
|
(acc, v, k) => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {LayoutCell, LayoutQuery} from './layouts'
|
||||||
import {Service, NewService} from './services'
|
import {Service, NewService} from './services'
|
||||||
import {AuthLinks, Organization, Role, User, Me} from './auth'
|
import {AuthLinks, Organization, Role, User, Me} from './auth'
|
||||||
import {Cell, CellQuery, Legend, Axes, Dashboard} from './dashboard'
|
import {Cell, CellQuery, Legend, Axes, Dashboard} from './dashboard'
|
||||||
import {Template, URLQueries} from './tempVars'
|
import {Template, TemplateQuery, TemplateValue, URLQueries} from './tempVars'
|
||||||
import {
|
import {
|
||||||
GroupBy,
|
GroupBy,
|
||||||
Query,
|
Query,
|
||||||
|
@ -36,6 +36,8 @@ export {
|
||||||
User,
|
User,
|
||||||
Organization,
|
Organization,
|
||||||
Template,
|
Template,
|
||||||
|
TemplateQuery,
|
||||||
|
TemplateValue,
|
||||||
Cell,
|
Cell,
|
||||||
CellQuery,
|
CellQuery,
|
||||||
Legend,
|
Legend,
|
||||||
|
|
|
@ -24,6 +24,11 @@ export interface Template {
|
||||||
query?: TemplateQuery
|
query?: TemplateQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TemplateUpdate {
|
||||||
|
key: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface URLQueries {
|
export interface URLQueries {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue