Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(variable_hydration): limiting variable hydration to changing variables #18071

Merged
merged 9 commits into from
May 20, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

1. [18066](https://github.com/influxdata/influxdb/pull/18066): Fixed bug that wasn't persisting timeFormat for Graph + Single Stat selections
1. [17959](https://github.com/influxdata/influxdb/pull/17959): Authorizer now exposes full permission set
1. [18071](https://github.com/influxdata/influxdb/pull/18071): Fixed issue that was causing variable selections to hydrate all variable values

### UI Improvements

Expand Down
6 changes: 3 additions & 3 deletions ui/src/shared/components/graph_tips/GraphTips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const GraphTips: FC = () => (
color={ComponentColor.Primary}
testID="graphtips-question-mark"
tooltipContents={
<span>
<>
<h1>Graph Tips:</h1>
<p>
<code>Click + Drag</code> Zoom in (X or Y)
Expand All @@ -22,11 +22,11 @@ const GraphTips: FC = () => (
</p>
<h1>Static Legend Tips:</h1>
<p>
<code>Click</code>Focus on single Series
<code>Click</code> Focus on single Series
<br />
<code>Shift + Click</code> Show/Hide single Series
</p>
</span>
</>
}
/>
</>
Expand Down
33 changes: 30 additions & 3 deletions ui/src/variables/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ export const hydrateVariables = (skipCache?: boolean) => async (
await hydration.promise
}

export const hydrateChangedVariable = (variableID: string) => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
const state = getState()
const org = getOrg(state)
const variable = getVariableFromState(state, variableID)
const hydration = hydrateVars([variable], getAllVariablesFromState(state), {
orgID: org.id,
url: state.links.query.self,
skipCache: true,
})
hydration.on('status', (variable, status) => {
if (status === RemoteDataState.Loading) {
dispatch(setVariable(variable.id, status))
return
}
if (status === RemoteDataState.Done) {
const _variable = normalize<Variable, VariableEntities, string>(
variable,
variableSchema
)
dispatch(setVariable(variable.id, RemoteDataState.Done, _variable))
}
})
await hydration.promise
}

export const getVariable = (id: string) => async (
dispatch: Dispatch<Action>
) => {
Expand Down Expand Up @@ -397,15 +425,14 @@ export const selectValue = (variableID: string, selected: string) => async (
const state = getState()
const contextID = currentContext(state)
const variable = getVariableFromState(state, variableID)

// Validate that we can make this selection
const vals = normalizeValues(variable)
if (!vals.includes(selected)) {
return
}

await dispatch(selectValueInState(contextID, variableID, selected))

dispatch(hydrateVariables(true))
// only hydrate the changedVariable
dispatch(hydrateChangedVariable(variableID))
dispatch(updateQueryVars({[variable.name]: selected}))
}
13 changes: 10 additions & 3 deletions ui/src/variables/components/VariableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,16 @@ class VariableDropdown extends PureComponent<Props> {
}

private handleSelect = (selectedValue: string) => {
const {variableID, onSelectValue, onSelect} = this.props

onSelectValue(variableID, selectedValue)
const {
variableID,
onSelectValue,
onSelect,
selectedValue: prevSelectedValue,
} = this.props

if (prevSelectedValue !== selectedValue) {
onSelectValue(variableID, selectedValue)
}

if (onSelect) {
onSelect()
Expand Down
Loading