mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Variables: Fixes so constants set from url get completed state (#28257)
* Variables: Fixes so constant set from url get completed state * Tests: fixes broken test
This commit is contained in:
@@ -250,7 +250,7 @@ export const processVariable = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for variables that aren't updated via url or refresh let's simulate the same state changes
|
// for variables that aren't updated via url or refresh let's simulate the same state changes
|
||||||
dispatch(variableStateCompleted(toVariablePayload(variable)));
|
dispatch(completeVariableLoading(identifier));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -276,11 +276,6 @@ export const setOptionFromUrl = (
|
|||||||
await dispatch(updateOptions(toVariableIdentifier(variable)));
|
await dispatch(updateOptions(toVariableIdentifier(variable)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variable.hasOwnProperty('refresh') && (variable as QueryVariableModel).refresh === VariableRefresh.never) {
|
|
||||||
// for variables that have refresh to never simulate the same state changes
|
|
||||||
dispatch(variableStateCompleted(toVariablePayload(variable)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get variable from state
|
// get variable from state
|
||||||
const variableFromState = getVariable<VariableWithOptions>(variable.id, getState());
|
const variableFromState = getVariable<VariableWithOptions>(variable.id, getState());
|
||||||
if (!variableFromState) {
|
if (!variableFromState) {
|
||||||
@@ -452,6 +447,8 @@ export const variableUpdated = (
|
|||||||
|
|
||||||
// if we're initializing variables ignore cascading update because we are in a boot up scenario
|
// if we're initializing variables ignore cascading update because we are in a boot up scenario
|
||||||
if (getState().templating.transaction.status === TransactionStatus.Fetching) {
|
if (getState().templating.transaction.status === TransactionStatus.Fetching) {
|
||||||
|
// for all variable types with updates that go the setValueFromUrl path in the update let's make sure their state is set to Done.
|
||||||
|
dispatch(completeVariableLoading(identifier));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,7 +621,7 @@ export const updateOptions = (identifier: VariableIdentifier, rethrow = false):
|
|||||||
try {
|
try {
|
||||||
dispatch(variableStateFetching(toVariablePayload(variableInState)));
|
dispatch(variableStateFetching(toVariablePayload(variableInState)));
|
||||||
await variableAdapters.get(variableInState.type).updateOptions(variableInState);
|
await variableAdapters.get(variableInState.type).updateOptions(variableInState);
|
||||||
dispatch(variableStateCompleted(toVariablePayload(variableInState)));
|
dispatch(completeVariableLoading(identifier));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(variableStateFailed(toVariablePayload(variableInState, { error })));
|
dispatch(variableStateFailed(toVariablePayload(variableInState, { error })));
|
||||||
|
|
||||||
@@ -648,3 +645,11 @@ export const createVariableErrorNotification = (
|
|||||||
`${identifier ? `Templating [${identifier.id}]` : 'Templating'}`,
|
`${identifier ? `Templating [${identifier.id}]` : 'Templating'}`,
|
||||||
`${message} ${error.message}`
|
`${message} ${error.message}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const completeVariableLoading = (identifier: VariableIdentifier): ThunkResult<void> => (dispatch, getState) => {
|
||||||
|
const variableInState = getVariable(identifier.id, getState());
|
||||||
|
|
||||||
|
if (variableInState.state !== LoadingState.Done) {
|
||||||
|
dispatch(variableStateCompleted(toVariablePayload(variableInState)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ describe('processVariable', () => {
|
|||||||
await tester.thenDispatchedActionsShouldEqual(
|
await tester.thenDispatchedActionsShouldEqual(
|
||||||
setCurrentVariableValue(
|
setCurrentVariableValue(
|
||||||
toVariablePayload({ type: 'custom', id: 'custom' }, { option: { text: 'B', value: 'B', selected: false } })
|
toVariablePayload({ type: 'custom', id: 'custom' }, { option: { text: 'B', value: 'B', selected: false } })
|
||||||
)
|
),
|
||||||
|
variableStateCompleted(toVariablePayload(custom))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -212,13 +213,13 @@ describe('processVariable', () => {
|
|||||||
.whenAsyncActionIsDispatched(processVariable(toVariableIdentifier(queryNoDepends), queryParams), true);
|
.whenAsyncActionIsDispatched(processVariable(toVariableIdentifier(queryNoDepends), queryParams), true);
|
||||||
|
|
||||||
await tester.thenDispatchedActionsShouldEqual(
|
await tester.thenDispatchedActionsShouldEqual(
|
||||||
variableStateCompleted(toVariablePayload({ type: 'query', id: 'queryNoDepends' })),
|
|
||||||
setCurrentVariableValue(
|
setCurrentVariableValue(
|
||||||
toVariablePayload(
|
toVariablePayload(
|
||||||
{ type: 'query', id: 'queryNoDepends' },
|
{ type: 'query', id: 'queryNoDepends' },
|
||||||
{ option: { text: 'B', value: 'B', selected: false } }
|
{ option: { text: 'B', value: 'B', selected: false } }
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
variableStateCompleted(toVariablePayload({ type: 'query', id: 'queryNoDepends' }))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -360,13 +361,13 @@ describe('processVariable', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await tester.thenDispatchedActionsShouldEqual(
|
await tester.thenDispatchedActionsShouldEqual(
|
||||||
variableStateCompleted(toVariablePayload({ type: 'query', id: 'queryDependsOnCustom' })),
|
|
||||||
setCurrentVariableValue(
|
setCurrentVariableValue(
|
||||||
toVariablePayload(
|
toVariablePayload(
|
||||||
{ type: 'query', id: 'queryDependsOnCustom' },
|
{ type: 'query', id: 'queryDependsOnCustom' },
|
||||||
{ option: { text: 'AB', value: 'AB', selected: false } }
|
{ option: { text: 'AB', value: 'AB', selected: false } }
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
variableStateCompleted(toVariablePayload({ type: 'query', id: 'queryDependsOnCustom' }))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user