2023-11-06 19:28:44 +08:00
|
|
|
import { TypedVariableModel } from '@grafana/data';
|
|
|
|
|
2022-02-18 13:06:04 +08:00
|
|
|
import { getPreloadedState } from '../../app/features/variables/state/helpers';
|
2023-11-06 19:28:44 +08:00
|
|
|
import { VariablesState } from '../../app/features/variables/state/types';
|
2025-07-09 12:15:33 +08:00
|
|
|
import { StoreState } from '../../app/types/store';
|
2020-04-03 15:38:14 +08:00
|
|
|
|
2023-11-06 19:28:44 +08:00
|
|
|
export const convertToStoreState = (key: string, models: TypedVariableModel[]): StoreState => {
|
|
|
|
const variables = models.reduce<VariablesState>((byName, variable) => {
|
2022-02-18 13:06:04 +08:00
|
|
|
byName[variable.name] = variable;
|
|
|
|
return byName;
|
|
|
|
}, {});
|
2020-04-03 15:38:14 +08:00
|
|
|
return {
|
2022-02-18 13:06:04 +08:00
|
|
|
...getPreloadedState(key, { variables }),
|
2020-04-03 15:38:14 +08:00
|
|
|
} as StoreState;
|
|
|
|
};
|