From 6886a7a12f5a46b4972abef6b4fa4126c610ecb7 Mon Sep 17 00:00:00 2001 From: drdelambre Date: Fri, 3 Apr 2020 12:47:59 -0700 Subject: [PATCH 1/7] fix: hierarchy of variables is back --- ui/src/dashboards/actions/thunks.ts | 2 +- ui/src/timeMachine/actions/queries.ts | 3 +++ ui/src/variables/actions/thunks.ts | 4 ++-- ui/src/variables/selectors/index.tsx | 8 ++++++++ ui/src/variables/utils/buildVarsOption.ts | 2 +- ui/src/variables/utils/hydrateVars.ts | 3 +++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ui/src/dashboards/actions/thunks.ts b/ui/src/dashboards/actions/thunks.ts index a18d64f1999..c0c3b793ef5 100644 --- a/ui/src/dashboards/actions/thunks.ts +++ b/ui/src/dashboards/actions/thunks.ts @@ -286,7 +286,7 @@ export const getDashboard = (dashboardID: string) => async ( throw new Error(resp.data.message) } - dispatch(hydrateVariables()) + dispatch(hydrateVariables(true)) const normDash = normalize( resp.data, diff --git a/ui/src/timeMachine/actions/queries.ts b/ui/src/timeMachine/actions/queries.ts index 8badd09b173..a350715fcfd 100644 --- a/ui/src/timeMachine/actions/queries.ts +++ b/ui/src/timeMachine/actions/queries.ts @@ -12,6 +12,7 @@ import {runStatusesQuery} from 'src/alerting/utils/statusEvents' // Actions import {notify} from 'src/shared/actions/notifications' +import {hydrateVariables} from 'src/variables/actions/thunks' // Constants import {rateLimitReached, resultTooLarge} from 'src/shared/copy/notifications' @@ -115,6 +116,8 @@ export const executeQueries = () => async (dispatch, getState: GetState) => { try { dispatch(setQueryResults(RemoteDataState.Loading, [], null)) + await dispatch(hydrateVariables()) + //TODO: replace with activeContext selector const contextID = activeTimeMachine.contextID || state.timeMachines.activeTimeMachineID diff --git a/ui/src/variables/actions/thunks.ts b/ui/src/variables/actions/thunks.ts index 8833d829f6e..090ec5a919e 100644 --- a/ui/src/variables/actions/thunks.ts +++ b/ui/src/variables/actions/thunks.ts @@ -97,7 +97,7 @@ export const getVariables = () => async ( } } -export const hydrateVariables = () => async ( +export const hydrateVariables = (skipCache: boolean) => async ( dispatch: Dispatch, getState: GetState ) => { @@ -107,7 +107,7 @@ export const hydrateVariables = () => async ( const vals = await hydrateVars(vars, getAllVariablesFromState(state), { orgID: org.id, url: state.links.query.self, - skipCache: true, + skipCache, }).promise vars diff --git a/ui/src/variables/selectors/index.tsx b/ui/src/variables/selectors/index.tsx index 7cee083e7fe..b123395ed65 100644 --- a/ui/src/variables/selectors/index.tsx +++ b/ui/src/variables/selectors/index.tsx @@ -175,6 +175,11 @@ export const getVariable = ( if (!vari.selected) { if (vari.arguments.type === 'map') { vari.selected = [Object.keys(vari.arguments.values)[0]] + } else if ( + vari.arguments.type === 'query' && + vari.arguments.values.results + ) { + vari.selected = [vari.arguments.values.results[0]] } else { vari.selected = [vari.arguments.values[0]] } @@ -252,6 +257,9 @@ export const asAssignment = (variable: Variable): VariableAssignment => { } if (variable.arguments.type === 'query') { + if (!variable.selected[0]) { + return null + } out.init = { type: 'StringLiteral', value: variable.selected[0], diff --git a/ui/src/variables/utils/buildVarsOption.ts b/ui/src/variables/utils/buildVarsOption.ts index 203deb191a6..077a6ef097b 100644 --- a/ui/src/variables/utils/buildVarsOption.ts +++ b/ui/src/variables/utils/buildVarsOption.ts @@ -20,7 +20,7 @@ export const buildVarsOption = (variables: VariableAssignment[]): File => ({ }, init: { type: 'ObjectExpression', - properties: variables.map(assignmentToProperty), + properties: variables.filter(v => !!v).map(assignmentToProperty), }, }, }, diff --git a/ui/src/variables/utils/hydrateVars.ts b/ui/src/variables/utils/hydrateVars.ts index 4fdaeec9a41..5357d309c30 100644 --- a/ui/src/variables/utils/hydrateVars.ts +++ b/ui/src/variables/utils/hydrateVars.ts @@ -372,7 +372,10 @@ export const hydrateVars = ( node.status === RemoteDataState.Loading try { + // TODO: remove the concept of node.values, just use node.variable node.values = await hydrateVarsHelper(node, options) + node.variable.arguments.values.results = node.values.values + node.variable.selected = node.values.selected node.status = RemoteDataState.Done return Promise.all(node.parents.filter(readyToResolve).map(resolve)) From f49d1b4ba8d1a8f34fafb845c5b5991e5e95b2a9 Mon Sep 17 00:00:00 2001 From: Alex Boatwright Date: Fri, 3 Apr 2020 12:56:59 -0700 Subject: [PATCH 2/7] fix: make it optional --- ui/src/variables/actions/thunks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/variables/actions/thunks.ts b/ui/src/variables/actions/thunks.ts index 090ec5a919e..16762821669 100644 --- a/ui/src/variables/actions/thunks.ts +++ b/ui/src/variables/actions/thunks.ts @@ -97,7 +97,7 @@ export const getVariables = () => async ( } } -export const hydrateVariables = (skipCache: boolean) => async ( +export const hydrateVariables = (skipCache?: boolean) => async ( dispatch: Dispatch, getState: GetState ) => { From 3234379badfa8264f1914629af8f19e9816d13a9 Mon Sep 17 00:00:00 2001 From: Alex Boatwright Date: Fri, 3 Apr 2020 14:32:12 -0700 Subject: [PATCH 3/7] fix: omgolly jest data --- ui/src/variables/selectors/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/variables/selectors/index.tsx b/ui/src/variables/selectors/index.tsx index b123395ed65..bd55cfb0735 100644 --- a/ui/src/variables/selectors/index.tsx +++ b/ui/src/variables/selectors/index.tsx @@ -257,7 +257,7 @@ export const asAssignment = (variable: Variable): VariableAssignment => { } if (variable.arguments.type === 'query') { - if (!variable.selected[0]) { + if (!variable.selected || !variable.selected[0]) { return null } out.init = { From 5c92448be03d1516bdfdca6b8f326770c7645ffd Mon Sep 17 00:00:00 2001 From: drdelambre Date: Fri, 3 Apr 2020 14:59:55 -0700 Subject: [PATCH 4/7] fix: thanks tests --- ui/src/variables/utils/hydrateVars.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/src/variables/utils/hydrateVars.ts b/ui/src/variables/utils/hydrateVars.ts index 5357d309c30..2a9894c2045 100644 --- a/ui/src/variables/utils/hydrateVars.ts +++ b/ui/src/variables/utils/hydrateVars.ts @@ -374,7 +374,11 @@ export const hydrateVars = ( try { // TODO: remove the concept of node.values, just use node.variable node.values = await hydrateVarsHelper(node, options) - node.variable.arguments.values.results = node.values.values + if (node.variable.arguments.type === 'query') { + node.variable.arguments.values.results = node.values.values + } else { + node.variable.arguments.values = node.values.values + } node.variable.selected = node.values.selected node.status = RemoteDataState.Done From b7845765020f2788b1206240e5e3174f74c79ae8 Mon Sep 17 00:00:00 2001 From: Alex Boatwright Date: Fri, 3 Apr 2020 15:21:59 -0700 Subject: [PATCH 5/7] fix: stretching out those types a bit --- ui/src/types/variables.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ui/src/types/variables.ts b/ui/src/types/variables.ts index 8722d10ba6c..275fdf962f9 100644 --- a/ui/src/types/variables.ts +++ b/ui/src/types/variables.ts @@ -1,8 +1,13 @@ import {Variable as GenVariable, Label} from 'src/client' -import {VariableProperties as GenVariableProperties} from 'src/client' +import { + QueryVariableProperties as GenQueryVariableProperties, + ConstantVariableProperties as GenConstantVariableProperties, + MapVariableProperties as GenMapVariableProperties, +} from 'src/client' import { VariableArgumentType, + VariableMapObject, QueryArguments, MapArguments, CSVArguments, @@ -16,9 +21,19 @@ export interface SystemVariableProperties { type?: 'system' values?: any } +export interface QueryVariableProperties + extends Omit { + values?: { + query?: string + language?: string + results?: string[] | VariableMapObject + } +} export type VariableProperties = | SystemVariableProperties - | GenVariableProperties + | QueryVariableProperties + | GenConstantVariableProperties + | GenMapVariableProperties export interface Variable extends Omit, 'arguments'> { From fd2866606445e221dbd37775c86687b9ddb94818 Mon Sep 17 00:00:00 2001 From: Alex Boatwright Date: Fri, 3 Apr 2020 15:57:31 -0700 Subject: [PATCH 6/7] fix: that filters itself out now --- ui/src/external/monaco.flux.server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/external/monaco.flux.server.ts b/ui/src/external/monaco.flux.server.ts index 74cdc307676..fb10bba0961 100644 --- a/ui/src/external/monaco.flux.server.ts +++ b/ui/src/external/monaco.flux.server.ts @@ -202,7 +202,7 @@ export class LSPServer { // drift between the parser and the internal representation const variables = getAllVariables(state, contextID) .map(v => asAssignment(v)) - .filter(v => !(v.init.type === 'StringLiteral' && !v.init.value)) + .filter(v => !!v) const file = buildVarsOption(variables) From 00aeb6a74b017d12c6b0a6a8d7c4d7b364b344e3 Mon Sep 17 00:00:00 2001 From: Alex Boatwright Date: Fri, 3 Apr 2020 16:00:49 -0700 Subject: [PATCH 7/7] fix: better intent --- ui/src/dashboards/actions/thunks.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/src/dashboards/actions/thunks.ts b/ui/src/dashboards/actions/thunks.ts index c0c3b793ef5..9aa061233eb 100644 --- a/ui/src/dashboards/actions/thunks.ts +++ b/ui/src/dashboards/actions/thunks.ts @@ -286,7 +286,8 @@ export const getDashboard = (dashboardID: string) => async ( throw new Error(resp.data.message) } - dispatch(hydrateVariables(true)) + const skipCache = true + dispatch(hydrateVariables(skipCache)) const normDash = normalize( resp.data,