mirror of https://github.com/grafana/grafana
Variables: Improves inspection performance and unknown filtering (#31811)
* Refactor: moves inspect calculation to Redux * Refactor: adds valid filters and testspull/31823/head
parent
d60727311e
commit
63746d027b
@ -0,0 +1,29 @@ |
||||
import { reducerTester } from '../../../../test/core/redux/reducerTester'; |
||||
import { initialVariableInspectState, initInspect, variableInspectReducer } from './reducer'; |
||||
import { textboxBuilder } from '../shared/testing/builders'; |
||||
|
||||
describe('variableInspectReducer', () => { |
||||
describe('when initInspect is dispatched', () => { |
||||
it('then state should be correct', () => { |
||||
const variable = textboxBuilder().withId('text').withName('text').build(); |
||||
reducerTester() |
||||
.givenReducer(variableInspectReducer, { ...initialVariableInspectState }) |
||||
.whenActionIsDispatched( |
||||
initInspect({ |
||||
unknownExits: true, |
||||
unknownsNetwork: [{ edges: [], nodes: [], showGraph: true, variable }], |
||||
usagesNetwork: [{ edges: [], nodes: [], showGraph: true, variable }], |
||||
usages: [{ variable, tree: {} }], |
||||
unknown: [{ variable, tree: {} }], |
||||
}) |
||||
) |
||||
.thenStateShouldEqual({ |
||||
unknownExits: true, |
||||
unknownsNetwork: [{ edges: [], nodes: [], showGraph: true, variable }], |
||||
usagesNetwork: [{ edges: [], nodes: [], showGraph: true, variable }], |
||||
usages: [{ variable, tree: {} }], |
||||
unknown: [{ variable, tree: {} }], |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,46 @@ |
||||
import { UsagesToNetwork, VariableUsageTree } from './utils'; |
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
||||
|
||||
export interface VariableInspectState { |
||||
unknown: VariableUsageTree[]; |
||||
usages: VariableUsageTree[]; |
||||
unknownsNetwork: UsagesToNetwork[]; |
||||
usagesNetwork: UsagesToNetwork[]; |
||||
unknownExits: boolean; |
||||
} |
||||
|
||||
export const initialVariableInspectState: VariableInspectState = { |
||||
unknown: [], |
||||
usages: [], |
||||
unknownsNetwork: [], |
||||
usagesNetwork: [], |
||||
unknownExits: false, |
||||
}; |
||||
|
||||
const variableInspectReducerSlice = createSlice({ |
||||
name: 'templating/inspect', |
||||
initialState: initialVariableInspectState, |
||||
reducers: { |
||||
initInspect: ( |
||||
state, |
||||
action: PayloadAction<{ |
||||
unknown: VariableUsageTree[]; |
||||
usages: VariableUsageTree[]; |
||||
unknownsNetwork: UsagesToNetwork[]; |
||||
usagesNetwork: UsagesToNetwork[]; |
||||
unknownExits: boolean; |
||||
}> |
||||
) => { |
||||
const { unknown, usages, unknownExits, unknownsNetwork, usagesNetwork } = action.payload; |
||||
state.usages = usages; |
||||
state.unknown = unknown; |
||||
state.unknownsNetwork = unknownsNetwork; |
||||
state.unknownExits = unknownExits; |
||||
state.usagesNetwork = usagesNetwork; |
||||
}, |
||||
}, |
||||
}); |
||||
|
||||
export const variableInspectReducer = variableInspectReducerSlice.reducer; |
||||
|
||||
export const { initInspect } = variableInspectReducerSlice.actions; |
Loading…
Reference in new issue