import { ReactElement, ReactNode } from 'react'; import { StoreApi } from 'zustand'; import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system'; import { VariableName, VariableValue, VariableDefinition, BuiltinVariableDefinition, TextVariableDefinition, ListVariableDefinition, ExternalVariableDefinition } from '@perses-dev/core'; /** * This store is used to manipulate and read the definition of the variables and their state. * - being local or external variables. * - being text or list variables. * - being of any state (value, options, loading, error, ...) check {@VariableState} * Go and read each property documentation for more details. */ type VariableDefinitionStore = { /** * List of local variables definitions. * This is typically the variable definition that can be modified through the setVariableDefinition setter. * * In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local. * Note that depending on the form, we can reuse this store to modify higher scope variables. For example, * when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify * them. */ variableDefinitions: VariableDefinition[]; /** * List of external variable definitions. * This is static variable definitions that won´t be modified under this context. * You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for * more details. * * In Perses App ecosystem, this is typically the project or global scope variables. * Note that depending on the form, we can reuse this store to modify higher scope variables. For example, * when we modify the variable of a project, we'll set this field with global scope variables. Which means we * won't be able to modify them from this form. */ externalVariableDefinitions: ExternalVariableDefinition[]; /** * Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for. * This can be heavily modified under this context, using the different setters available. * Note that the state of local AND external variables can be modified. */ variableState: VariableStoreStateMap; /** * Allow to modify the `value` property of a variable in the state map. * @param variableName identify the variable * @param value new value * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition} */ setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void; /** * Allow to modify the `options` property of a variable in the state map. * @param variableName identify the variable * @param options new value * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition} */ setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void; /** * Allow to modify the `loading` property of a variable in the state map. * @param variableName identify the variable * @param laoding new value * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition} */ setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void; setVariableDefinitions: (definitions: VariableDefinition[]) => void; setVariableDefaultValues: () => VariableDefinition[]; getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[]; }; }; export declare function useVariableDefinitionStoreCtx(): StoreApi; export declare function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap; /** * Get the state and definition of a variable from the variables context. * @param name name of the variable * @param source if given, it searches in the external variables */ export declare function useVariableDefinitionAndState(name: string, source?: string): { definition: TextVariableDefinition | ListVariableDefinition | undefined; state: VariableState | undefined; }; export declare function useVariableDefinitionActions(): { setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void; getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[]; }; setVariableDefaultValues: () => VariableDefinition[]; setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void; setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void; setVariableDefinitions: (definitions: VariableDefinition[]) => void; }; export declare function useVariableDefinitions(): VariableDefinition[]; export declare function useExternalVariableDefinitions(): ExternalVariableDefinition[]; /** * The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static. * It means that you won´t be able to update them from the dashboard itself, but you will see them appear and will be able * to modify their runtime value as any other variable. * If one of the external variable has the same name as a local one, it will be marked as overridden. * You can define one list of variable definition by source and as many source as you want. * The order of the sources is important as first one will take precedence on the following ones, in case they have same names. */ export interface VariableProviderProps { children: ReactNode; initialVariableDefinitions?: VariableDefinition[]; externalVariableDefinitions?: ExternalVariableDefinition[]; builtinVariableDefinitions?: BuiltinVariableDefinition[]; } export declare function VariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, }: VariableProviderProps): ReactElement; export declare function VariableProviderWithQueryParams({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions: builtinVariables, }: VariableProviderProps): ReactElement; export {}; //# sourceMappingURL=VariableProvider.d.ts.map