@perses-dev/dashboards 0.54.0-beta.1 → 0.54.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cjs/components/Panel/Panel.js +4 -1
  2. package/dist/cjs/components/Variables/VariableEditor.js +51 -17
  3. package/dist/cjs/context/DatasourceStoreProvider.js +4 -1
  4. package/dist/cjs/context/VariableProvider/VariableProvider.js +10 -6
  5. package/dist/components/AddGroupButton/AddGroupButton.js +1 -1
  6. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
  7. package/dist/components/AddPanelButton/AddPanelButton.js +1 -1
  8. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  9. package/dist/components/Dashboard/Dashboard.js +1 -1
  10. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  11. package/dist/components/DashboardLinks/DashboardLinksEditor.js +1 -1
  12. package/dist/components/DashboardLinks/DashboardLinksEditor.js.map +1 -1
  13. package/dist/components/DashboardLinks/EditDashboardLinksButton.js +1 -1
  14. package/dist/components/DashboardLinks/EditDashboardLinksButton.js.map +1 -1
  15. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +1 -1
  16. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  17. package/dist/components/DashboardToolbar/DashboardToolbar.js +1 -1
  18. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  19. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  20. package/dist/components/Datasources/DatasourceEditor.js +1 -1
  21. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  22. package/dist/components/Datasources/EditDatasourcesButton.js +1 -1
  23. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
  24. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  25. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  26. package/dist/components/DownloadButton/DownloadButton.js +1 -1
  27. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  28. package/dist/components/EditButton/EditButton.js +1 -1
  29. package/dist/components/EditButton/EditButton.js.map +1 -1
  30. package/dist/components/EditJsonButton/EditJsonButton.js +1 -1
  31. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  32. package/dist/components/EditJsonDialog/EditJsonDialog.js +1 -1
  33. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  34. package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
  35. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
  36. package/dist/components/GridLayout/GridContainer.js +1 -1
  37. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  38. package/dist/components/GridLayout/GridItemContent.js +1 -1
  39. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  40. package/dist/components/GridLayout/GridLayout.js +1 -1
  41. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  42. package/dist/components/GridLayout/GridTitle.js +1 -1
  43. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  44. package/dist/components/GridLayout/Row.js +1 -1
  45. package/dist/components/GridLayout/Row.js.map +1 -1
  46. package/dist/components/LeaveDialog/LeaveDialog.js +1 -1
  47. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  48. package/dist/components/LinksDisplay/LinksDisplay.js +1 -1
  49. package/dist/components/LinksDisplay/LinksDisplay.js.map +1 -1
  50. package/dist/components/Panel/Panel.js +5 -2
  51. package/dist/components/Panel/Panel.js.map +1 -1
  52. package/dist/components/Panel/PanelActions.js +1 -1
  53. package/dist/components/Panel/PanelActions.js.map +1 -1
  54. package/dist/components/Panel/PanelContent.js +1 -1
  55. package/dist/components/Panel/PanelContent.js.map +1 -1
  56. package/dist/components/Panel/PanelHeader.js +1 -1
  57. package/dist/components/Panel/PanelHeader.js.map +1 -1
  58. package/dist/components/Panel/PanelPluginLoader.js +1 -1
  59. package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
  60. package/dist/components/Panel/useSelectionItemActions.js +1 -1
  61. package/dist/components/Panel/useSelectionItemActions.js.map +1 -1
  62. package/dist/components/PanelDrawer/PanelDrawer.js +1 -1
  63. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  64. package/dist/components/PanelDrawer/PanelEditorForm.js +1 -1
  65. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  66. package/dist/components/PanelDrawer/PanelPreview.js +1 -1
  67. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  68. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +1 -1
  69. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
  70. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  72. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  73. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  74. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +1 -1
  75. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  76. package/dist/components/QueryViewerDialog/QueryViewerDialog.js +1 -1
  77. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -1
  78. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +1 -1
  79. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  80. package/dist/components/Variables/EditVariablesButton.js +1 -1
  81. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  82. package/dist/components/Variables/ListVariableListBox.js +1 -1
  83. package/dist/components/Variables/ListVariableListBox.js.map +1 -1
  84. package/dist/components/Variables/Variable.js +2 -2
  85. package/dist/components/Variables/Variable.js.map +1 -1
  86. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  87. package/dist/components/Variables/VariableEditor.js +56 -22
  88. package/dist/components/Variables/VariableEditor.js.map +1 -1
  89. package/dist/components/Variables/VariableList.js +1 -1
  90. package/dist/components/Variables/VariableList.js.map +1 -1
  91. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  92. package/dist/context/DashboardProvider/DashboardProvider.js +1 -1
  93. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  94. package/dist/context/DatasourceStoreProvider.d.ts +1 -1
  95. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  96. package/dist/context/DatasourceStoreProvider.js +5 -2
  97. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  98. package/dist/context/PanelEditorProvider/PanelEditorProvider.js +1 -1
  99. package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
  100. package/dist/context/VariableProvider/VariableProvider.d.ts +2 -1
  101. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  102. package/dist/context/VariableProvider/VariableProvider.js +12 -8
  103. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  104. package/dist/keyboard-shortcuts/PanelFocusProvider.js +1 -1
  105. package/dist/keyboard-shortcuts/PanelFocusProvider.js.map +1 -1
  106. package/dist/test/datasource-provider.d.ts +1 -1
  107. package/dist/test/datasource-provider.d.ts.map +1 -1
  108. package/dist/test/datasource-provider.js.map +1 -1
  109. package/dist/test/render.js +1 -1
  110. package/dist/test/render.js.map +1 -1
  111. package/dist/views/ViewDashboard/DashboardApp.js +1 -1
  112. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  113. package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
  114. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  115. package/package.json +6 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, ReactNode, useContext, useMemo, useState } from 'react';\nimport { createStore, StoreApi, useStore } from 'zustand';\nimport { useStoreWithEqualityFn } from 'zustand/traditional';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\nimport { shallow } from 'zustand/shallow';\nimport { produce } from 'immer';\nimport {\n VariableContext,\n VariableStateMap,\n VariableState,\n VariableStoreStateMap,\n VariableOption,\n BuiltinVariableContext,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport { intervalToPrometheusDuration } from '@perses-dev/core'; // TODO weird to have something related to prometheus in the dashboard package\nimport {\n DEFAULT_ALL_VALUE as ALL_VALUE,\n VariableName,\n VariableValue,\n VariableDefinition,\n formatDuration,\n BuiltinVariableDefinition,\n TextVariableDefinition,\n ListVariableDefinition,\n} from '@perses-dev/spec';\nimport { ExternalVariableDefinition } from '../../model/VariableDefinition';\nimport { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';\nimport { hydrateVariableDefinitionStates as hydrateVariableDefinitionStates } from './hydrationUtils';\nimport { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';\n\n/**\n * This store is used to manipulate and read the definition of the variables and their state.\n * - being local or external variables.\n * - being text or list variables.\n * - being of any state (value, options, loading, error, ...) check {@VariableState}\n * Go and read each property documentation for more details.\n */\ntype VariableDefinitionStore = {\n /**\n * List of local variables definitions.\n * This is typically the variable definition that can be modified through the setVariableDefinition setter.\n *\n * In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify\n * them.\n */\n variableDefinitions: VariableDefinition[];\n /**\n * List of external variable definitions.\n * This is static variable definitions that won´t be modified under this context.\n * You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for\n * more details.\n *\n * In Perses App ecosystem, this is typically the project or global scope variables.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with global scope variables. Which means we\n * won't be able to modify them from this form.\n */\n externalVariableDefinitions: ExternalVariableDefinition[];\n /**\n * Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for.\n * This can be heavily modified under this context, using the different setters available.\n * Note that the state of local AND external variables can be modified.\n */\n variableState: VariableStoreStateMap;\n /**\n * Allow to modify the `value` property of a variable in the state map.\n * @param variableName identify the variable\n * @param value new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;\n /**\n * Allow to modify the `options` property of a variable in the state map.\n * @param variableName identify the variable\n * @param options new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;\n /**\n * Allow to modify the `loading` property of a variable in the state map.\n * @param variableName identify the variable\n * @param laoding new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n setVariableDefaultValues: () => VariableDefinition[];\n getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[] };\n};\n\n/**\n * Context object for {@link VariableDefinitionStore}.\n */\nconst VariableDefinitionStoreContext = createContext<StoreApi<VariableDefinitionStore> | undefined>(undefined);\nexport function useVariableDefinitionStoreCtx(): StoreApi<VariableDefinitionStore> {\n const context = useContext(VariableDefinitionStoreContext);\n if (!context) {\n throw new Error('VariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap {\n const store = useVariableDefinitionStoreCtx();\n return useStoreWithEqualityFn(\n store,\n (s) => {\n const varStates: VariableStateMap = {};\n\n // Collect values of local variables, from the variable state\n const names = variableNames ?? s.variableDefinitions.map((value) => value.spec.name);\n names.forEach((name) => {\n const varState = s.variableState.get({ name });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n\n // Collect values of external variables, from the variable state\n s.externalVariableDefinitions.forEach((d) => {\n const source = d.source;\n d.definitions.forEach((value) => {\n const name = value.spec.name;\n const varState = s.variableState.get({ name, source });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n });\n\n return varStates;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n}\n\n/**\n * Get the state and definition of a variable from the variables context.\n * @param name name of the variable\n * @param source if given, it searches in the external variables\n */\nexport function useVariableDefinitionAndState(\n name: string,\n source?: string\n): {\n definition: TextVariableDefinition | ListVariableDefinition | undefined;\n state: VariableState | undefined;\n} {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => {\n const state = s.variableState.get({ name, source });\n const definitions = source\n ? s.externalVariableDefinitions.find((v) => v.source === source)?.definitions\n : s.variableDefinitions;\n const definition = (definitions || []).find((v) => v.spec.name === name);\n\n return { state, definition };\n });\n}\n\nexport function useVariableDefinitionActions(): {\n setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;\n getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[] };\n setVariableDefaultValues: () => VariableDefinition[];\n setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n} {\n const store = useVariableDefinitionStoreCtx();\n return useStoreWithEqualityFn(\n store,\n (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n setVariableDefaultValues: s.setVariableDefaultValues,\n getSavedVariablesStatus: s.getSavedVariablesStatus,\n };\n },\n shallow\n );\n}\n\nexport function useVariableDefinitions(): VariableDefinition[] {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useExternalVariableDefinitions(): ExternalVariableDefinition[] {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.externalVariableDefinitions);\n}\n\ninterface PluginProviderProps {\n children: ReactNode;\n builtinVariables?: BuiltinVariableDefinition[];\n}\n\nfunction PluginProvider({ children, builtinVariables }: PluginProviderProps): ReactElement {\n const originalValues = useVariableDefinitionStates();\n const definitions = useVariableDefinitions();\n const externalDefinitions = useExternalVariableDefinitions();\n const { absoluteTimeRange } = useTimeRange();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n\n if (v.value === ALL_VALUE) {\n const definition = findVariableDefinitionByName(name, definitions, externalDefinitions);\n // If the variable is a list variable and has a custom all value, then use that value instead\n if (definition?.kind === 'ListVariable' && definition.spec.customAllValue) {\n v.value = definition.spec.customAllValue;\n } else {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues, definitions, externalDefinitions]);\n\n const allBuiltinVariables: BuiltinVariableDefinition[] = useMemo(() => {\n const result: BuiltinVariableDefinition[] = [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__from',\n value: () => absoluteTimeRange.start.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__from',\n description: 'Start time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__to',\n value: () => absoluteTimeRange.end.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__to',\n description: 'End time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range',\n value: () => formatDuration(intervalToPrometheusDuration(absoluteTimeRange)),\n source: 'Dashboard',\n display: {\n name: '__range',\n description: 'The range for the current dashboard in human readable format',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_s',\n value: () => ((absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()) / 1000).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_s',\n description: 'The range for the current dashboard in second',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_ms',\n value: () => (absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_ms',\n description: 'The range for the current dashboard in millisecond',\n hidden: true,\n },\n },\n },\n ];\n builtinVariables?.forEach((def) => result.push(def));\n return result;\n }, [absoluteTimeRange, builtinVariables]);\n\n return (\n <BuiltinVariableContext.Provider value={{ variables: allBuiltinVariables }}>\n <VariableContext.Provider value={{ state: values }}>{children}</VariableContext.Provider>\n </BuiltinVariableContext.Provider>\n );\n}\n\ninterface VariableDefinitionStoreArgs {\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createVariableDefinitionStore({\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n queryParams,\n}: VariableDefinitionStoreArgs): StoreApi<VariableDefinitionStore> {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<VariableDefinitionStore>()(\n devtools(\n immer((set, get) => ({\n variableState: hydrateVariableDefinitionStates(\n initialVariableDefinitions,\n initialParams,\n externalVariableDefinitions\n ),\n variableDefinitions: initialVariableDefinitions,\n externalVariableDefinitions: externalVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]): void {\n set(\n (state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateVariableDefinitionStates(\n definitions,\n initialParams,\n externalVariableDefinitions\n );\n },\n false,\n '[Variables] setVariableDefinitions' // Used for action name in Redux devtools\n );\n },\n setVariableOptions(name, options, source?: string): void {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.options = options;\n },\n false,\n '[Variables] setVariableOptions'\n );\n },\n setVariableLoading(name, loading, source?: string): void {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.loading = loading;\n },\n false,\n '[Variables] setVariableLoading'\n );\n },\n setVariableValue: (name, value, source?: string): void =>\n set(\n (state) => {\n let val = value;\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n },\n false,\n '[Variables] setVariableValue'\n ),\n setVariableDefaultValues: (): VariableDefinition[] => {\n const variableDefinitions = get().variableDefinitions;\n const variableState = get().variableState;\n const updatedVariables = produce(variableDefinitions, (draft) => {\n draft.forEach((variable, index) => {\n const name = variable.spec.name;\n if (variable.kind === 'ListVariable') {\n const currentVariable = variableState.get({ name });\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'ListVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.defaultValue = currentVariable.value;\n }),\n };\n }\n } else if (variable.kind === 'TextVariable') {\n const currentVariable = variableState.get({ name });\n const currentVariableValue = typeof currentVariable?.value === 'string' ? currentVariable.value : '';\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'TextVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.value = currentVariableValue;\n }),\n };\n }\n }\n });\n });\n set(\n (state) => {\n state.variableDefinitions = updatedVariables;\n },\n false,\n '[Variables] setVariableDefaultValues'\n );\n return updatedVariables;\n },\n getSavedVariablesStatus: (): {\n modifiedVariableNames: string[];\n isSavedVariableModified: boolean;\n } => {\n return checkSavedDefaultVariableStatus(get().variableDefinitions, get().variableState);\n },\n }))\n )\n );\n\n return store as StoreApi<VariableDefinitionStore>;\n}\n\n/**\n * The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.\n * 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\n * to modify their runtime value as any other variable.\n * If one of the external variable has the same name as a local one, it will be marked as overridden.\n * You can define one list of variable definition by source and as many source as you want.\n * The order of the sources is important as first one will take precedence on the following ones, in case they have same names.\n */\n\nexport interface VariableProviderProps {\n children: ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n builtinVariableDefinitions?: BuiltinVariableDefinition[];\n}\n\n// TODO: merge the different providers related to Variables under a single one (and keep \"VariableProvider\" as a name)\nexport function VariableProvider({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions = [],\n}: VariableProviderProps): ReactElement {\n const [store] = useState(() =>\n createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions })\n );\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariableDefinitions}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n\nexport function VariableProviderWithQueryParams({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions: builtinVariables = [],\n}: VariableProviderProps): ReactElement {\n const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);\n const queryParams = useVariableQueryParams(allVariableDefs);\n const [store] = useState(() =>\n createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions, queryParams })\n );\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariables}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","useStoreWithEqualityFn","immer","devtools","shallow","produce","VariableContext","BuiltinVariableContext","useTimeRange","intervalToPrometheusDuration","DEFAULT_ALL_VALUE","ALL_VALUE","formatDuration","checkSavedDefaultVariableStatus","findVariableDefinitionByName","mergeVariableDefinitions","hydrateVariableDefinitionStates","getInitalValuesFromQueryParameters","getURLQueryParamName","useVariableQueryParams","VariableDefinitionStoreContext","undefined","useVariableDefinitionStoreCtx","context","Error","useVariableDefinitionStates","variableNames","store","s","varStates","names","variableDefinitions","map","value","spec","name","forEach","varState","variableState","get","overridden","externalVariableDefinitions","d","source","definitions","left","right","JSON","stringify","useVariableDefinitionAndState","state","find","v","definition","useVariableDefinitionActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","setVariableDefaultValues","getSavedVariablesStatus","useVariableDefinitions","useExternalVariableDefinitions","PluginProvider","children","builtinVariables","originalValues","externalDefinitions","absoluteTimeRange","values","contextValues","Object","keys","kind","customAllValue","options","o","allBuiltinVariables","result","start","valueOf","toString","display","description","hidden","end","def","push","Provider","variables","createVariableDefinitionStore","initialVariableDefinitions","queryParams","initialParams","set","loading","val","Array","isArray","includes","at","filter","setQueryParams","updatedVariables","draft","variable","index","currentVariable","specDraft","defaultValue","currentVariableValue","VariableProvider","builtinVariableDefinitions","VariableProviderWithQueryParams","allVariableDefs"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAA2BC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC9F,SAASC,WAAW,EAAYC,QAAQ,QAAQ,UAAU;AAC1D,SAAS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AAG6E;oCACpB;gCACF;4BACF;wBACF;oBACF;gBACF;gBACAhB,IACE,CAAC5C;oBACCA,MAAMnB,mBAAmB,GAAGwE;gBAC9B,GACA,OACA;gBAEF,OAAOA;YACT;YACA3C,yBAAyB;gBAIvB,OAAO/C,gCAAgC0B,MAAMR,mBAAmB,EAAEQ,MAAMD,aAAa;YACvF;QACF,CAAA;IAIJ,OAAOX;AACT;AAkBA,sHAAsH;AACtH,OAAO,SAASoF,iBAAiB,EAC/B/C,QAAQ,EACR2B,6BAA6B,EAAE,EAC/BlD,8BAA8B,EAAE,EAChCuE,6BAA6B,EAAE,EACT;IACtB,MAAM,CAACrF,MAAM,GAAG7B,SAAS,IACvB4F,8BAA8B;YAAEC;YAA4BlD;QAA4B;IAG1F,qBACE,KAACrB,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkB+C;sBAA6BhD;;;AAGrE;AAEA,OAAO,SAASiD,gCAAgC,EAC9CjD,QAAQ,EACR2B,6BAA6B,EAAE,EAC/BlD,8BAA8B,EAAE,EAChCuE,4BAA4B/C,mBAAmB,EAAE,EAC3B;IACtB,MAAMiD,kBAAkBnG,yBAAyB4E,4BAA4BlD;IAC7E,MAAMmD,cAAczE,uBAAuB+F;IAC3C,MAAM,CAACvF,MAAM,GAAG7B,SAAS,IACvB4F,8BAA8B;YAAEC;YAA4BlD;YAA6BmD;QAAY;IAGvG,qBACE,KAACxE,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkBA;sBAAmBD;;;AAG3D"}
1
+ {"version":3,"sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, ReactNode, useContext, useMemo, useState } from 'react';\nimport { createStore, StoreApi, useStore } from 'zustand';\nimport { useStoreWithEqualityFn } from 'zustand/traditional';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\nimport { shallow } from 'zustand/shallow';\nimport { produce } from 'immer';\nimport {\n VariableContext,\n VariableStateMap,\n VariableState,\n VariableStoreStateMap,\n VariableOption,\n BuiltinVariableContext,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport {\n DEFAULT_ALL_VALUE as ALL_VALUE,\n VariableName,\n VariableValue,\n VariableDefinition,\n formatDuration,\n BuiltinVariableDefinition,\n TextVariableDefinition,\n ListVariableDefinition,\n intervalToDuration,\n} from '@perses-dev/spec';\nimport { ExternalVariableDefinition } from '../../model/VariableDefinition';\nimport { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';\nimport { hydrateVariableDefinitionStates as hydrateVariableDefinitionStates } from './hydrationUtils';\nimport { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';\n\n/**\n * This store is used to manipulate and read the definition of the variables and their state.\n * - being local or external variables.\n * - being text or list variables.\n * - being of any state (value, options, loading, error, ...) check {@VariableState}\n * Go and read each property documentation for more details.\n */\ntype VariableDefinitionStore = {\n /**\n * List of local variables definitions.\n * This is typically the variable definition that can be modified through the setVariableDefinition setter.\n *\n * In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify\n * them.\n */\n variableDefinitions: VariableDefinition[];\n /**\n * List of external variable definitions.\n * This is static variable definitions that won´t be modified under this context.\n * You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for\n * more details.\n *\n * In Perses App ecosystem, this is typically the project or global scope variables.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with global scope variables. Which means we\n * won't be able to modify them from this form.\n */\n externalVariableDefinitions: ExternalVariableDefinition[];\n /**\n * Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for.\n * This can be heavily modified under this context, using the different setters available.\n * Note that the state of local AND external variables can be modified.\n */\n variableState: VariableStoreStateMap;\n /**\n * Allow to modify the `value` property of a variable in the state map.\n * @param variableName identify the variable\n * @param value new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;\n /**\n * Allow to modify the `options` property of a variable in the state map.\n * @param variableName identify the variable\n * @param options new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;\n /**\n * Allow to modify the `loading` property of a variable in the state map.\n * @param variableName identify the variable\n * @param laoding new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n setVariableDefaultValues: () => VariableDefinition[];\n getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[] };\n};\n\n/**\n * Context object for {@link VariableDefinitionStore}.\n */\nconst VariableDefinitionStoreContext = createContext<StoreApi<VariableDefinitionStore> | undefined>(undefined);\nexport function useVariableDefinitionStoreCtx(): StoreApi<VariableDefinitionStore> {\n const context = useContext(VariableDefinitionStoreContext);\n if (!context) {\n throw new Error('VariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap {\n const store = useVariableDefinitionStoreCtx();\n return useStoreWithEqualityFn(\n store,\n (s) => {\n const varStates: VariableStateMap = {};\n\n // Collect values of local variables, from the variable state\n const names = variableNames ?? s.variableDefinitions.map((value) => value.spec.name);\n names.forEach((name) => {\n const varState = s.variableState.get({ name });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n\n // Collect values of external variables, from the variable state\n s.externalVariableDefinitions.forEach((d) => {\n const source = d.source;\n d.definitions.forEach((value) => {\n const name = value.spec.name;\n const varState = s.variableState.get({ name, source });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n });\n\n return varStates;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n}\n\n/**\n * Get the state and definition of a variable from the variables context.\n * @param name name of the variable\n * @param source if given, it searches in the external variables\n */\nexport function useVariableDefinitionAndState(\n name: string,\n source?: string\n): {\n definition: TextVariableDefinition | ListVariableDefinition | undefined;\n state: VariableState | undefined;\n} {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => {\n const state = s.variableState.get({ name, source });\n const definitions = source\n ? s.externalVariableDefinitions.find((v) => v.source === source)?.definitions\n : s.variableDefinitions;\n const definition = (definitions || []).find((v) => v.spec.name === name);\n\n return { state, definition };\n });\n}\n\nexport function useVariableDefinitionActions(): {\n setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;\n getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[] };\n setVariableDefaultValues: () => VariableDefinition[];\n setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n} {\n const store = useVariableDefinitionStoreCtx();\n return useStoreWithEqualityFn(\n store,\n (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n setVariableDefaultValues: s.setVariableDefaultValues,\n getSavedVariablesStatus: s.getSavedVariablesStatus,\n };\n },\n shallow\n );\n}\n\nexport function useVariableDefinitions(): VariableDefinition[] {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useExternalVariableDefinitions(): ExternalVariableDefinition[] {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.externalVariableDefinitions);\n}\n\ninterface PluginProviderProps {\n children: ReactNode;\n builtinVariables?: BuiltinVariableDefinition[];\n}\n\nfunction PluginProvider({ children, builtinVariables }: PluginProviderProps): ReactElement {\n const originalValues = useVariableDefinitionStates();\n const definitions = useVariableDefinitions();\n const externalDefinitions = useExternalVariableDefinitions();\n const { absoluteTimeRange } = useTimeRange();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n\n if (v.value === ALL_VALUE) {\n const definition = findVariableDefinitionByName(name, definitions, externalDefinitions);\n // If the variable is a list variable and has a custom all value, then use that value instead\n if (definition?.kind === 'ListVariable' && definition.spec.customAllValue) {\n v.value = definition.spec.customAllValue;\n } else {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues, definitions, externalDefinitions]);\n\n const allBuiltinVariables: BuiltinVariableDefinition[] = useMemo(() => {\n const result: BuiltinVariableDefinition[] = [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__from',\n value: () => absoluteTimeRange.start.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__from',\n description: 'Start time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__to',\n value: () => absoluteTimeRange.end.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__to',\n description: 'End time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range',\n value: () => formatDuration(intervalToDuration(absoluteTimeRange)),\n source: 'Dashboard',\n display: {\n name: '__range',\n description: 'The range for the current dashboard in human readable format',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_s',\n value: () => ((absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()) / 1000).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_s',\n description: 'The range for the current dashboard in second',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_ms',\n value: () => (absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_ms',\n description: 'The range for the current dashboard in millisecond',\n hidden: true,\n },\n },\n },\n ];\n builtinVariables?.forEach((def) => result.push(def));\n return result;\n }, [absoluteTimeRange, builtinVariables]);\n\n return (\n <BuiltinVariableContext.Provider value={{ variables: allBuiltinVariables }}>\n <VariableContext.Provider value={{ state: values }}>{children}</VariableContext.Provider>\n </BuiltinVariableContext.Provider>\n );\n}\n\ninterface VariableDefinitionStoreArgs {\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n initialVariableValues?: Record<string, VariableValue>;\n}\n\nfunction createVariableDefinitionStore({\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n queryParams,\n initialVariableValues,\n}: VariableDefinitionStoreArgs): StoreApi<VariableDefinitionStore> {\n const queryParamValues = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const initialParams = { ...queryParamValues, ...initialVariableValues };\n const store = createStore<VariableDefinitionStore>()(\n devtools(\n immer((set, get) => ({\n variableState: hydrateVariableDefinitionStates(\n initialVariableDefinitions,\n initialParams,\n externalVariableDefinitions\n ),\n variableDefinitions: initialVariableDefinitions,\n externalVariableDefinitions: externalVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]): void {\n set(\n (state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateVariableDefinitionStates(\n definitions,\n initialParams,\n externalVariableDefinitions\n );\n },\n false,\n '[Variables] setVariableDefinitions' // Used for action name in Redux devtools\n );\n },\n setVariableOptions(name, options, source?: string): void {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.options = options;\n },\n false,\n '[Variables] setVariableOptions'\n );\n },\n setVariableLoading(name, loading, source?: string): void {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.loading = loading;\n },\n false,\n '[Variables] setVariableLoading'\n );\n },\n setVariableValue: (name, value, source?: string): void =>\n set(\n (state) => {\n let val = value;\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n },\n false,\n '[Variables] setVariableValue'\n ),\n setVariableDefaultValues: (): VariableDefinition[] => {\n const variableDefinitions = get().variableDefinitions;\n const variableState = get().variableState;\n const updatedVariables = produce(variableDefinitions, (draft) => {\n draft.forEach((variable, index) => {\n const name = variable.spec.name;\n if (variable.kind === 'ListVariable') {\n const currentVariable = variableState.get({ name });\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'ListVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.defaultValue = currentVariable.value;\n }),\n };\n }\n } else if (variable.kind === 'TextVariable') {\n const currentVariable = variableState.get({ name });\n const currentVariableValue = typeof currentVariable?.value === 'string' ? currentVariable.value : '';\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'TextVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.value = currentVariableValue;\n }),\n };\n }\n }\n });\n });\n set(\n (state) => {\n state.variableDefinitions = updatedVariables;\n },\n false,\n '[Variables] setVariableDefaultValues'\n );\n return updatedVariables;\n },\n getSavedVariablesStatus: (): {\n modifiedVariableNames: string[];\n isSavedVariableModified: boolean;\n } => {\n return checkSavedDefaultVariableStatus(get().variableDefinitions, get().variableState);\n },\n }))\n )\n );\n\n return store as StoreApi<VariableDefinitionStore>;\n}\n\n/**\n * The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.\n * 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\n * to modify their runtime value as any other variable.\n * If one of the external variable has the same name as a local one, it will be marked as overridden.\n * You can define one list of variable definition by source and as many source as you want.\n * The order of the sources is important as first one will take precedence on the following ones, in case they have same names.\n */\n\nexport interface VariableProviderProps {\n children: ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n builtinVariableDefinitions?: BuiltinVariableDefinition[];\n initialVariableValues?: Record<string, VariableValue>;\n}\n\n// TODO: merge the different providers related to Variables under a single one (and keep \"VariableProvider\" as a name)\nexport function VariableProvider({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions = [],\n initialVariableValues,\n}: VariableProviderProps): ReactElement {\n const [store] = useState(() =>\n createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions, initialVariableValues })\n );\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariableDefinitions}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n\nexport function VariableProviderWithQueryParams({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions: builtinVariables = [],\n}: VariableProviderProps): ReactElement {\n const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);\n const queryParams = useVariableQueryParams(allVariableDefs);\n const [store] = useState(() =>\n createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions, queryParams })\n );\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariables}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","useStoreWithEqualityFn","immer","devtools","shallow","produce","VariableContext","BuiltinVariableContext","useTimeRange","DEFAULT_ALL_VALUE","ALL_VALUE","formatDuration","intervalToDuration","checkSavedDefaultVariableStatus","findVariableDefinitionByName","mergeVariableDefinitions","hydrateVariableDefinitionStates","getInitalValuesFromQueryParameters","getURLQueryParamName","useVariableQueryParams","VariableDefinitionStoreContext","undefined","useVariableDefinitionStoreCtx","context","Error","useVariableDefinitionStates","variableNames","store","s","varStates","names","variableDefinitions","map","value","spec","name","forEach","varState","variableState","get","overridden","externalVariableDefinitions","d","source","definitions","left","right","JSON","stringify","useVariableDefinitionAndState","state","find","v","definition","useVariableDefinitionActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","setVariableDefaultValues","getSavedVariablesStatus","useVariableDefinitions","useExternalVariableDefinitions","PluginProvider","children","builtinVariables","originalValues","externalDefinitions","absoluteTimeRange","values","contextValues","Object","keys","kind","customAllValue","options","o","allBuiltinVariables","result","start","valueOf","toString","display","description","hidden","end","def","push","Provider","variables","createVariableDefinitionStore","initialVariableDefinitions","queryParams","initialVariableValues","queryParamValues","initialParams","set","loading","val","Array","isArray","includes","at","filter","setQueryParams","updatedVariables","draft","variable","index","currentVariable","specDraft","defaultValue","currentVariableValue","VariableProvider","builtinVariableDefinitions","VariableProviderWithQueryParams","allVariableDefs"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAA2BC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC9F,SAASC,WAAW,EA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ACbnC,MAAM;oCACNvC,MAAM7B,QAAQsG,SAASzE,IAAI,EAAE,CAAC4E;wCAC5BA,UAAU7E,KAAK,GAAG+E;oCACpB;gCACF;4BACF;wBACF;oBACF;gBACF;gBACAhB,IACE,CAAC9C;oBACCA,MAAMnB,mBAAmB,GAAG0E;gBAC9B,GACA,OACA;gBAEF,OAAOA;YACT;YACA7C,yBAAyB;gBAIvB,OAAO/C,gCAAgC0B,MAAMR,mBAAmB,EAAEQ,MAAMD,aAAa;YACvF;QACF,CAAA;IAIJ,OAAOX;AACT;AAmBA,sHAAsH;AACtH,OAAO,SAASsF,iBAAiB,EAC/BjD,QAAQ,EACR2B,6BAA6B,EAAE,EAC/BlD,8BAA8B,EAAE,EAChCyE,6BAA6B,EAAE,EAC/BrB,qBAAqB,EACC;IACtB,MAAM,CAAClE,MAAM,GAAG7B,SAAS,IACvB4F,8BAA8B;YAAEC;YAA4BlD;YAA6BoD;QAAsB;IAGjH,qBACE,KAACzE,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkBiD;sBAA6BlD;;;AAGrE;AAEA,OAAO,SAASmD,gCAAgC,EAC9CnD,QAAQ,EACR2B,6BAA6B,EAAE,EAC/BlD,8BAA8B,EAAE,EAChCyE,4BAA4BjD,mBAAmB,EAAE,EAC3B;IACtB,MAAMmD,kBAAkBrG,yBAAyB4E,4BAA4BlD;IAC7E,MAAMmD,cAAczE,uBAAuBiG;IAC3C,MAAM,CAACzF,MAAM,GAAG7B,SAAS,IACvB4F,8BAA8B;YAAEC;YAA4BlD;YAA6BmD;QAAY;IAGvG,qBACE,KAACxE,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkBA;sBAAmBD;;;AAG3D"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
15
15
  const PanelFocusContext = /*#__PURE__*/ createContext(undefined);
16
16
  function usePanelFocusContext() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/keyboard-shortcuts/PanelFocusProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\ninterface PanelFocusContextValue {\n focusedPanelKey: string | null;\n setFocusedPanel: (panelKey: string) => void;\n clearFocusedPanel: () => void;\n}\n\nconst PanelFocusContext = createContext<PanelFocusContextValue | undefined>(undefined);\n\nfunction usePanelFocusContext(): PanelFocusContextValue {\n const ctx = useContext(PanelFocusContext);\n if (ctx === undefined) {\n throw new Error('Panel focus hooks must be used within a PanelFocusProvider');\n }\n return ctx;\n}\n\n/** Tracks which dashboard panel is currently focused (hovered) for panel-scoped shortcuts. */\nexport function PanelFocusProvider({ children }: { children: ReactNode }): ReactElement {\n const [focusedPanelKey, setFocusedPanelKeyState] = useState<string | null>(null);\n\n // This wrapper narrow the setter type (string-only / null-only) and provide\n // stable references for the useMemo context value below. React guarantees\n // setFocusedPanelKeyState is stable, but useCallback makes the stability\n // explicit and satisfies exhaustive-deps when used in useMemo.\n const setFocusedPanel = useCallback((panelKey: string) => {\n setFocusedPanelKeyState(panelKey);\n }, []);\n\n const clearFocusedPanel = useCallback(() => {\n setFocusedPanelKeyState(null);\n }, []);\n\n const value = useMemo(\n (): PanelFocusContextValue => ({\n focusedPanelKey,\n setFocusedPanel,\n clearFocusedPanel,\n }),\n [focusedPanelKey, setFocusedPanel, clearFocusedPanel]\n );\n\n return <PanelFocusContext.Provider value={value}>{children}</PanelFocusContext.Provider>;\n}\n\nexport function useFocusedPanel(): string | null {\n return usePanelFocusContext().focusedPanelKey;\n}\n\nconst PANEL_FOCUS_DEBOUNCE_MS = 50;\n\n/** Debounced mouse enter/leave handlers for panel focus. Add `tabIndex={-1}` to the panel element. */\nexport function usePanelFocusHandlers(panelKey: string): {\n onMouseEnter: (e: React.MouseEvent<HTMLElement>) => void;\n onMouseLeave: () => void;\n} {\n const { setFocusedPanel, clearFocusedPanel } = usePanelFocusContext();\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const onMouseEnter = useCallback(\n (e: React.MouseEvent<HTMLElement>) => {\n const element = e.currentTarget;\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n timerRef.current = setTimeout(() => {\n setFocusedPanel(panelKey);\n element.focus({ preventScroll: true });\n timerRef.current = null;\n }, PANEL_FOCUS_DEBOUNCE_MS);\n },\n [panelKey, setFocusedPanel]\n );\n\n const onMouseLeave = useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n clearFocusedPanel();\n }, [clearFocusedPanel]);\n\n useEffect(() => {\n return (): void => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n };\n }, []);\n\n return useMemo(() => ({ onMouseEnter, onMouseLeave }), [onMouseEnter, onMouseLeave]);\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","PanelFocusContext","undefined","usePanelFocusContext","ctx","Error","PanelFocusProvider","children","focusedPanelKey","setFocusedPanelKeyState","setFocusedPanel","panelKey","clearFocusedPanel","value","Provider","useFocusedPanel","PANEL_FOCUS_DEBOUNCE_MS","usePanelFocusHandlers","timerRef","onMouseEnter","e","element","currentTarget","current","clearTimeout","setTimeout","focus","preventScroll","onMouseLeave"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SACLC,aAAa,EAGbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAQf,MAAMC,kCAAoBP,cAAkDQ;AAE5E,SAASC;IACP,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,4FAA4F,GAC5F,OAAO,SAASE,mBAAmB,EAAEC,QAAQ,EAA2B;IACtE,MAAM,CAACC,iBAAiBC,wBAAwB,GAAGT,SAAwB;IAE3E,4EAA4E;IAC5E,0EAA0E;IAC1E,yEAAyE;IACzE,+DAA+D;IAC/D,MAAMU,kBAAkBf,YAAY,CAACgB;QACnCF,wBAAwBE;IAC1B,GAAG,EAAE;IAEL,MAAMC,oBAAoBjB,YAAY;QACpCc,wBAAwB;IAC1B,GAAG,EAAE;IAEL,MAAMI,QAAQf,QACZ,IAA+B,CAAA;YAC7BU;YACAE;YACAE;QACF,CAAA,GACA;QAACJ;QAAiBE;QAAiBE;KAAkB;IAGvD,qBAAO,KAACX,kBAAkBa,QAAQ;QAACD,OAAOA;kBAAQN;;AACpD;AAEA,OAAO,SAASQ;IACd,OAAOZ,uBAAuBK,eAAe;AAC/C;AAEA,MAAMQ,0BAA0B;AAEhC,oGAAoG,GACpG,OAAO,SAASC,sBAAsBN,QAAgB;IAIpD,MAAM,EAAED,eAAe,EAAEE,iBAAiB,EAAE,GAAGT;IAC/C,MAAMe,WAAWnB,OAA6C;IAE9D,MAAMoB,eAAexB,YACnB,CAACyB;QACC,MAAMC,UAAUD,EAAEE,aAAa;QAC/B,IAAIJ,SAASK,OAAO,KAAK,MAAM;YAC7BC,aAAaN,SAASK,OAAO;QAC/B;QACAL,SAASK,OAAO,GAAGE,WAAW;YAC5Bf,gBAAgBC;YAChBU,QAAQK,KAAK,CAAC;gBAAEC,eAAe;YAAK;YACpCT,SAASK,OAAO,GAAG;QACrB,GAAGP;IACL,GACA;QAACL;QAAUD;KAAgB;IAG7B,MAAMkB,eAAejC,YAAY;QAC/B,IAAIuB,SAASK,OAAO,KAAK,MAAM;YAC7BC,aAAaN,SAASK,OAAO;YAC7BL,SAASK,OAAO,GAAG;QACrB;QACAX;IACF,GAAG;QAACA;KAAkB;IAEtBf,UAAU;QACR,OAAO;YACL,IAAIqB,SAASK,OAAO,KAAK,MAAM;gBAC7BC,aAAaN,SAASK,OAAO;YAC/B;QACF;IACF,GAAG,EAAE;IAEL,OAAOzB,QAAQ,IAAO,CAAA;YAAEqB;YAAcS;QAAa,CAAA,GAAI;QAACT;QAAcS;KAAa;AACrF"}
1
+ {"version":3,"sources":["../../src/keyboard-shortcuts/PanelFocusProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\ninterface PanelFocusContextValue {\n focusedPanelKey: string | null;\n setFocusedPanel: (panelKey: string) => void;\n clearFocusedPanel: () => void;\n}\n\nconst PanelFocusContext = createContext<PanelFocusContextValue | undefined>(undefined);\n\nfunction usePanelFocusContext(): PanelFocusContextValue {\n const ctx = useContext(PanelFocusContext);\n if (ctx === undefined) {\n throw new Error('Panel focus hooks must be used within a PanelFocusProvider');\n }\n return ctx;\n}\n\n/** Tracks which dashboard panel is currently focused (hovered) for panel-scoped shortcuts. */\nexport function PanelFocusProvider({ children }: { children: ReactNode }): ReactElement {\n const [focusedPanelKey, setFocusedPanelKeyState] = useState<string | null>(null);\n\n // This wrapper narrow the setter type (string-only / null-only) and provide\n // stable references for the useMemo context value below. React guarantees\n // setFocusedPanelKeyState is stable, but useCallback makes the stability\n // explicit and satisfies exhaustive-deps when used in useMemo.\n const setFocusedPanel = useCallback((panelKey: string) => {\n setFocusedPanelKeyState(panelKey);\n }, []);\n\n const clearFocusedPanel = useCallback(() => {\n setFocusedPanelKeyState(null);\n }, []);\n\n const value = useMemo(\n (): PanelFocusContextValue => ({\n focusedPanelKey,\n setFocusedPanel,\n clearFocusedPanel,\n }),\n [focusedPanelKey, setFocusedPanel, clearFocusedPanel]\n );\n\n return <PanelFocusContext.Provider value={value}>{children}</PanelFocusContext.Provider>;\n}\n\nexport function useFocusedPanel(): string | null {\n return usePanelFocusContext().focusedPanelKey;\n}\n\nconst PANEL_FOCUS_DEBOUNCE_MS = 50;\n\n/** Debounced mouse enter/leave handlers for panel focus. Add `tabIndex={-1}` to the panel element. */\nexport function usePanelFocusHandlers(panelKey: string): {\n onMouseEnter: (e: React.MouseEvent<HTMLElement>) => void;\n onMouseLeave: () => void;\n} {\n const { setFocusedPanel, clearFocusedPanel } = usePanelFocusContext();\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const onMouseEnter = useCallback(\n (e: React.MouseEvent<HTMLElement>) => {\n const element = e.currentTarget;\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n timerRef.current = setTimeout(() => {\n setFocusedPanel(panelKey);\n element.focus({ preventScroll: true });\n timerRef.current = null;\n }, PANEL_FOCUS_DEBOUNCE_MS);\n },\n [panelKey, setFocusedPanel]\n );\n\n const onMouseLeave = useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n clearFocusedPanel();\n }, [clearFocusedPanel]);\n\n useEffect(() => {\n return (): void => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n };\n }, []);\n\n return useMemo(() => ({ onMouseEnter, onMouseLeave }), [onMouseEnter, onMouseLeave]);\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","PanelFocusContext","undefined","usePanelFocusContext","ctx","Error","PanelFocusProvider","children","focusedPanelKey","setFocusedPanelKeyState","setFocusedPanel","panelKey","clearFocusedPanel","value","Provider","useFocusedPanel","PANEL_FOCUS_DEBOUNCE_MS","usePanelFocusHandlers","timerRef","onMouseEnter","e","element","currentTarget","current","clearTimeout","setTimeout","focus","preventScroll","onMouseLeave"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,SACLC,aAAa,EAGbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAQf,MAAMC,kCAAoBP,cAAkDQ;AAE5E,SAASC;IACP,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,4FAA4F,GAC5F,OAAO,SAASE,mBAAmB,EAAEC,QAAQ,EAA2B;IACtE,MAAM,CAACC,iBAAiBC,wBAAwB,GAAGT,SAAwB;IAE3E,4EAA4E;IAC5E,0EAA0E;IAC1E,yEAA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,4 +1,4 @@
1
- import { GlobalDatasourceResource } from '@perses-dev/core';
1
+ import { GlobalDatasourceResource } from '@perses-dev/client';
2
2
  import { DatasourceStoreProviderProps } from '../context';
3
3
  export declare const prometheusDemoUrl = "https://prometheus.demo.prometheus.io";
4
4
  export declare const prometheusDemo: GlobalDatasourceResource;
@@ -1 +1 @@
1
- {"version":3,"file":"datasource-provider.d.ts","sourceRoot":"","sources":["../../src/test/datasource-provider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAG1D,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AACzE,eAAO,MAAM,cAAc,EAAE,wBAenB,CAAC;AAKX,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,4BAA4B,EAAE,eAAe,GAAG,mBAAmB,CAqB5G,CAAC"}
1
+ {"version":3,"file":"datasource-provider.d.ts","sourceRoot":"","sources":["../../src/test/datasource-provider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAG1D,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AACzE,eAAO,MAAM,cAAc,EAAE,wBAenB,CAAC;AAKX,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,4BAA4B,EAAE,eAAe,GAAG,mBAAmB,CAqB5G,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/datasource-provider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { GlobalDatasourceResource } from '@perses-dev/core';\nimport { DatasourceStoreProviderProps } from '../context';\nimport { getTestDashboard } from './dashboard-provider';\n\nexport const prometheusDemoUrl = 'https://prometheus.demo.prometheus.io';\nexport const prometheusDemo: GlobalDatasourceResource = {\n kind: 'GlobalDatasource',\n metadata: {\n name: 'PrometheusDemo',\n createdAt: '0001-01-01T00:00:00Z',\n updatedAt: '0001-01-01T00:00:00Z',\n version: 0,\n },\n spec: {\n default: true,\n plugin: {\n kind: 'PrometheusDatasource',\n spec: { directUrl: prometheusDemoUrl },\n },\n },\n} as const;\n\n// This default currently defines the bare minimum to get a story working in\n// the `Dashboard` storybook with the Prometheus demo api. We'll likely want\n// to expand it to do more in the future.\nexport const defaultDatasourceProps: Pick<DatasourceStoreProviderProps, 'datasourceApi' | 'dashboardResource'> = {\n dashboardResource: getTestDashboard(),\n datasourceApi: {\n buildProxyUrl: () => '',\n getDatasource: () => {\n return Promise.resolve(undefined);\n },\n getGlobalDatasource: (selector) => {\n if (selector.kind === 'PrometheusDatasource') {\n return Promise.resolve(prometheusDemo);\n }\n\n return Promise.resolve(undefined);\n },\n listDatasources: () => {\n return Promise.resolve([]);\n },\n listGlobalDatasources: () => {\n return Promise.resolve([]);\n },\n },\n};\n"],"names":["getTestDashboard","prometheusDemoUrl","prometheusDemo","kind","metadata","name","createdAt","updatedAt","version","spec","default","plugin","directUrl","defaultDatasourceProps","dashboardResource","datasourceApi","buildProxyUrl","getDatasource","Promise","resolve","undefined","getGlobalDatasource","selector","listDatasources","listGlobalDatasources"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,gBAAgB,QAAQ,uBAAuB;AAExD,OAAO,MAAMC,oBAAoB,wCAAwC;AACzE,OAAO,MAAMC,iBAA2C;IACtDC,MAAM;IACNC,UAAU;QACRC,MAAM;QACNC,WAAW;QACXC,WAAW;QACXC,SAAS;IACX;IACAC,MAAM;QACJC,SAAS;QACTC,QAAQ;YACNR,MAAM;YACNM,MAAM;gBAAEG,WAAWX;YAAkB;QACvC;IACF;AACF,EAAW;AAEX,4EAA4E;AAC5E,4EAA4E;AAC5E,yCAAyC;AACzC,OAAO,MAAMY,yBAAoG;IAC/GC,mBAAmBd;IACnBe,eAAe;QACbC,eAAe,IAAM;QACrBC,eAAe;YACb,OAAOC,QAAQC,OAAO,CAACC;QACzB;QACAC,qBAAqB,CAACC;YACpB,IAAIA,SAASnB,IAAI,KAAK,wBAAwB;gBAC5C,OAAOe,QAAQC,OAAO,CAACjB;YACzB;YAEA,OAAOgB,QAAQC,OAAO,CAACC;QACzB;QACAG,iBAAiB;YACf,OAAOL,QAAQC,OAAO,CAAC,EAAE;QAC3B;QACAK,uBAAuB;YACrB,OAAON,QAAQC,OAAO,CAAC,EAAE;QAC3B;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/test/datasource-provider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { GlobalDatasourceResource } from '@perses-dev/client';\nimport { DatasourceStoreProviderProps } from '../context';\nimport { getTestDashboard } from './dashboard-provider';\n\nexport const prometheusDemoUrl = 'https://prometheus.demo.prometheus.io';\nexport const prometheusDemo: GlobalDatasourceResource = {\n kind: 'GlobalDatasource',\n metadata: {\n name: 'PrometheusDemo',\n createdAt: '0001-01-01T00:00:00Z',\n updatedAt: '0001-01-01T00:00:00Z',\n version: 0,\n },\n spec: {\n default: true,\n plugin: {\n kind: 'PrometheusDatasource',\n spec: { directUrl: prometheusDemoUrl },\n },\n },\n} as const;\n\n// This default currently defines the bare minimum to get a story working in\n// the `Dashboard` storybook with the Prometheus demo api. We'll likely want\n// to expand it to do more in the future.\nexport const defaultDatasourceProps: Pick<DatasourceStoreProviderProps, 'datasourceApi' | 'dashboardResource'> = {\n dashboardResource: getTestDashboard(),\n datasourceApi: {\n buildProxyUrl: () => '',\n getDatasource: () => {\n return Promise.resolve(undefined);\n },\n getGlobalDatasource: (selector) => {\n if (selector.kind === 'PrometheusDatasource') {\n return Promise.resolve(prometheusDemo);\n }\n\n return Promise.resolve(undefined);\n },\n listDatasources: () => {\n return Promise.resolve([]);\n },\n listGlobalDatasources: () => {\n return Promise.resolve([]);\n },\n },\n};\n"],"names":["getTestDashboard","prometheusDemoUrl","prometheusDemo","kind","metadata","name","createdAt","updatedAt","version","spec","default","plugin","directUrl","defaultDatasourceProps","dashboardResource","datasourceApi","buildProxyUrl","getDatasource","Promise","resolve","undefined","getGlobalDatasource","selector","listDatasources","listGlobalDatasources"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,gBAAgB,QAAQ,uBAAuB;AAExD,OAAO,MAAMC,oBAAoB,wCAAwC;AACzE,OAAO,MAAMC,iBAA2C;IACtDC,MAAM;IACNC,UAAU;QACRC,MAAM;QACNC,WAAW;QACXC,WAAW;QACXC,SAAS;IACX;IACAC,MAAM;QACJC,SAAS;QACTC,QAAQ;YACNR,MAAM;YACNM,MAAM;gBAAEG,WAAWX;YAAkB;QACvC;IACF;AACF,EAAW;AAEX,4EAA4E;AAC5E,4EAA4E;AAC5E,yCAAyC;AACzC,OAAO,MAAMY,yBAAoG;IAC/GC,mBAAmBd;IACnBe,eAAe;QACbC,eAAe,IAAM;QACrBC,eAAe;YACb,OAAOC,QAAQC,OAAO,CAACC;QACzB;QACAC,qBAAqB,CAACC;YACpB,IAAIA,SAASnB,IAAI,KAAK,wBAAwB;gBAC5C,OAAOe,QAAQC,OAAO,CAACjB;YACzB;YAEA,OAAOgB,QAAQC,OAAO,CAACC;QACzB;QACAG,iBAAiB;YACf,OAAOL,QAAQC,OAAO,CAAC,EAAE;QAC3B;QACAK,uBAAuB;YACrB,OAAON,QAAQC,OAAO,CAAC,EAAE;QAC3B;IACF;AACF,EAAE"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { ChartsProvider, SnackbarProvider, testChartsTheme } from '@perses-dev/components';
15
15
  import { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';
16
16
  import { HotkeysProvider } from '@tanstack/react-hotkeys';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChartsProvider, SnackbarProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { HotkeysProvider } from '@tanstack/react-hotkeys';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { render, RenderOptions, RenderResult } from '@testing-library/react';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { ReactElement, useLayoutEffect, useState } from 'react';\nimport { Router } from 'react-router-dom';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { DatasourceStoreProvider } from '../context';\nimport { PanelFocusProvider } from '../keyboard-shortcuts';\nimport { defaultDatasourceProps } from '../test';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\ninterface CustomRouterProps {\n history: MemoryHistory;\n children: React.ReactNode;\n}\n\n/*\n * Workaround for React router upgrade type errors.\n * More details: https://stackoverflow.com/a/69948457/17575201\n */\nconst CustomRouter: React.FC<CustomRouterProps> = ({ history, children }) => {\n const [state, setState] = useState({\n action: history.action,\n location: history.location,\n });\n\n useLayoutEffect(() => history.listen(setState), [history]);\n\n return (\n <Router location={state.location} navigationType={state.action} navigator={history}>\n {children}\n </Router>\n );\n};\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n): RenderResult {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const customHistory = history ?? createMemoryHistory();\n\n const mockRegistry = mockPluginRegistry(...MOCK_PLUGINS);\n\n const BaseRender = (): ReactElement => (\n <CustomRouter history={customHistory}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <SnackbarProvider anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>\n <ChartsProvider chartsTheme={testChartsTheme}>\n <PluginRegistry\n pluginLoader={mockRegistry.pluginLoader}\n defaultPluginKinds={mockRegistry.defaultPluginKinds}\n >\n <HotkeysProvider\n defaultOptions={{\n hotkey: { preventDefault: true, stopPropagation: true },\n hotkeySequence: { timeout: 1000 },\n }}\n >\n <PanelFocusProvider>\n <DatasourceStoreProvider {...defaultDatasourceProps}>{ui}</DatasourceStoreProvider>\n </PanelFocusProvider>\n </HotkeysProvider>\n </PluginRegistry>\n </ChartsProvider>\n </SnackbarProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </CustomRouter>\n );\n\n return render(<BaseRender />, options);\n}\n"],"names":["ChartsProvider","SnackbarProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","HotkeysProvider","QueryClient","QueryClientProvider","render","createMemoryHistory","useLayoutEffect","useState","Router","QueryParamProvider","ReactRouter6Adapter","DatasourceStoreProvider","PanelFocusProvider","defaultDatasourceProps","MOCK_PLUGINS","CustomRouter","history","children","state","setState","action","location","listen","navigationType","navigator","renderWithContext","ui","options","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","customHistory","mockRegistry","BaseRender","client","adapter","anchorOrigin","vertical","horizontal","chartsTheme","pluginLoader","defaultPluginKinds","hotkey","preventDefault","stopPropagation","hotkeySequence","timeout"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,cAAc,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,yBAAyB;AAC3F,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,4BAA4B;AAC/E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,wBAAwB;AACzE,SAASC,MAAM,QAAqC,yBAAyB;AAC7E,SAASC,mBAAmB,QAAuB,UAAU;AAC7D,SAAuBC,eAAe,EAAEC,QAAQ,QAAQ,QAAQ;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AgB;wCACde,QAAQ;4CAAEC,gBAAgB;4CAAMC,iBAAiB;wCAAK;wCACtDC,gBAAgB;4CAAEC,SAAS;wCAAK;oCAClC;8CAEA,cAAA,KAACpC;kDACC,cAAA,KAACD;4CAAyB,GAAGE,sBAAsB;sDAAGa;;;;;;;;;;IAWxE,OAAOtB,qBAAO,KAAC+B,iBAAeR;AAChC"}
1
+ {"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChartsProvider, SnackbarProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { HotkeysProvider } from '@tanstack/react-hotkeys';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { render, RenderOptions, RenderResult } from '@testing-library/react';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { ReactElement, useLayoutEffect, useState } from 'react';\nimport { Router } from 'react-router-dom';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { DatasourceStoreProvider } from '../context';\nimport { PanelFocusProvider } from '../keyboard-shortcuts';\nimport { defaultDatasourceProps } from '../test';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\ninterface CustomRouterProps {\n history: MemoryHistory;\n children: React.ReactNode;\n}\n\n/*\n * Workaround for React router upgrade type errors.\n * More details: https://stackoverflow.com/a/69948457/17575201\n */\nconst CustomRouter: React.FC<CustomRouterProps> = ({ history, children }) => {\n const [state, setState] = useState({\n action: history.action,\n location: history.location,\n });\n\n useLayoutEffect(() => history.listen(setState), [history]);\n\n return (\n <Router location={state.location} navigationType={state.action} navigator={history}>\n {children}\n </Router>\n );\n};\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n): RenderResult {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const customHistory = history ?? createMemoryHistory();\n\n const mockRegistry = mockPluginRegistry(...MOCK_PLUGINS);\n\n const BaseRender = (): ReactElement => (\n <CustomRouter history={customHistory}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <SnackbarProvider anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>\n <ChartsProvider chartsTheme={testChartsTheme}>\n <PluginRegistry\n pluginLoader={mockRegistry.pluginLoader}\n defaultPluginKinds={mockRegistry.defaultPluginKinds}\n >\n <HotkeysProvider\n defaultOptions={{\n hotkey: { preventDefault: true, stopPropagation: true },\n hotkeySequence: { timeout: 1000 },\n }}\n >\n <PanelFocusProvider>\n <DatasourceStoreProvider {...defaultDatasourceProps}>{ui}</DatasourceStoreProvider>\n </PanelFocusProvider>\n </HotkeysProvider>\n </PluginRegistry>\n </ChartsProvider>\n </SnackbarProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </CustomRouter>\n );\n\n return render(<BaseRender />, options);\n}\n"],"names":["ChartsProvider","SnackbarProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","HotkeysProvider","QueryClient","QueryClientProvider","render","createMemoryHistory","useLayoutEffect","useState","Router","QueryParamProvider","ReactRouter6Adapter","DatasourceStoreProvider","PanelFocusProvider","defaultDatasourceProps","MOCK_PLUGINS","CustomRouter","history","children","state","setState","action","location","listen","navigationType","navigator","renderWithContext","ui","options","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","customHistory","mockRegistry","BaseRender","client","adapter","anchorOrigin","vertical","horizontal","chartsTheme","pluginLoader","defaultPluginKinds","hotkey","preventDefault","stopPropagation","hotkeySequence","timeout"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,yBAAyB;AAC3F,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,4BAA4B;AAC/E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,wBAAwB;AACzE,SAASC,MAAM,QAAqC,yBAAyB;AAC7E,SAASC,mBAAmB,QAAuB,UAAU;AAC7D,SAAuBC,eAAe,EAAEC,QAAQ,QAAQ,QAAQ;AAChE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,kBAAkB,QAAQ,mBAAmB;AACtD,SAASC,mBAAmB,QAAQ,2CAA2C;AAC/E,SAASC,uBAAuB,QAAQ,aAAa;AACrD,SAASC,kBAAkB,QAAQ,wBAAwB;AAC3D,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,YAAY,QAAQ,oBAAoB;AAOjD;;;CAGC,GACD,MAAMC,eAA4C,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAE;IACtE,MAAM,CAACC,OAAOC,SAAS,GAAGZ,SAAS;QACjCa,QAAQJ,QAAQI,MAAM;QACtBC,UAAUL,QAAQK,QAAQ;IAC5B;IAEAf,gBAAgB,IAAMU,QAAQM,MAAM,CAACH,WAAW;QAACH;KAAQ;IAEzD,qBACE,KAACR;QAAOa,UAAUH,MAAMG,QAAQ;QAAEE,gBAAgBL,MAAME,MAAM;QAAEI,WAAWR;kBACxEC;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASQ,kBACdC,EAAsB,EACtBC,OAAwC,EACxCX,OAAuB;IAEvB,iEAAiE;IACjE,MAAMY,cAAc,IAAI1B,YAAY;QAAE2B,gBAAgB;YAAEC,SAAS;gBAAEC,sBAAsB;gBAAOC,OAAO;YAAM;QAAE;IAAE;IAEjH,MAAMC,gBAAgBjB,WAAWX;IAEjC,MAAM6B,eAAenC,sBAAsBe;IAE3C,MAAMqB,aAAa,kBACjB,KAACpB;YAAaC,SAASiB;sBACrB,cAAA,KAAC9B;gBAAoBiC,QAAQR;0BAC3B,cAAA,KAACnB;oBAAmB4B,SAAS3B;8BAC3B,cAAA,KAACb;wBAAiByC,cAAc;4BAAEC,UAAU;4BAAUC,YAAY;wBAAQ;kCACxE,cAAA,KAAC5C;4BAAe6C,aAAa3C;sCAC3B,cAAA,KAACE;gCACC0C,cAAcR,aAAaQ,YAAY;gCACvCC,oBAAoBT,aAAaS,kBAAkB;0CAEnD,cAAA,KAAC1C;oCACC4B,gBAAgB;wCACde,QAAQ;4CAAEC,gBAAgB;4CAAMC,iBAAiB;wCAAK;wCACtDC,gBAAgB;4CAAEC,SAAS;wCAAK;oCAClC;8CAEA,cAAA,KAACpC;kDACC,cAAA,KAACD;4CAAyB,GAAGE,sBAAsB;sDAAGa;;;;;;;;;;IAWxE,OAAOtB,qBAAO,KAAC+B,iBAAeR;AAChC"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
15
  import { Box } from '@mui/material';
16
16
  import { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { DashboardSpec } from '@perses-dev/spec';\nimport {\n PanelDrawer,\n Dashboard,\n useDashboardShortcuts,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DashboardDiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n EmptyDashboardProps,\n EditJsonDialog,\n SaveChangesConfirmationDialog,\n LeaveDialog,\n} from '../../components';\nimport { OnSaveDashboard, useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\nimport { PanelFocusProvider } from '../../keyboard-shortcuts';\nimport { DashboardResource } from '../../model';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n emptyDashboardProps?: Partial<EmptyDashboardProps>;\n isReadonly: boolean;\n isVariableEnabled: boolean;\n isDatasourceEnabled: boolean;\n disableShortcuts?: boolean;\n isCreating?: boolean;\n isInitialVariableSticky?: boolean;\n // If true, browser confirmation dialog will be shown when navigating away with unsaved changes (closing tab, ...).\n isLeavingConfirmDialogEnabled?: boolean;\n dashboardTitleComponent?: ReactNode;\n onSave?: OnSaveDashboard;\n onDiscard?: (name: string, spec: DashboardSpec) => void;\n}\n\nexport const DashboardApp = (props: DashboardAppProps): ReactElement => {\n return (\n <PanelFocusProvider>\n <DashboardAppContent {...props} />\n </PanelFocusProvider>\n );\n};\n\nconst DashboardAppContent = (props: DashboardAppProps): ReactElement => {\n const {\n dashboardResource,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n } = props;\n\n const chartsTheme = useChartsTheme();\n\n const { isEditMode, setEditMode } = useEditMode();\n\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { setSavedDatasources } = useDatasourceStore();\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = (): void => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard.metadata.name, dashboard.spec);\n }\n };\n\n const onEditButtonClick = (): void => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n setSavedDatasources(dashboard.spec.datasources ?? {});\n };\n\n const onCancelButtonClick = (): void => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n useDashboardShortcuts({\n onSave,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n disabled: disableShortcuts,\n });\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={isInitialVariableSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ paddingTop: 2, paddingX: 2, height: '100%' }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard\n emptyDashboardProps={{\n onEditButtonClick,\n ...emptyDashboardProps,\n }}\n />\n </ErrorBoundary>\n <ChartsProvider chartsTheme={chartsTheme} enablePinning={false} enableSyncGrouping={false}>\n <PanelDrawer />\n </ChartsProvider>\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DashboardDiscardChangesConfirmationDialog />\n <EditJsonDialog isReadonly={!isEditMode} disableMetadataEdition={!isCreating} />\n <SaveChangesConfirmationDialog />\n {isLeavingConfirmDialogEnabled && isEditMode && (\n <LeaveDialog original={originalDashboard} current={dashboard} />\n )}\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ChartsProvider","ErrorAlert","ErrorBoundary","useChartsTheme","useDatasourceStore","PanelDrawer","Dashboard","useDashboardShortcuts","PanelGroupDialog","DeletePanelGroupDialog","DashboardDiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","EditJsonDialog","SaveChangesConfirmationDialog","LeaveDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","PanelFocusProvider","DashboardApp","props","DashboardAppContent","dashboardResource","emptyDashboardProps","isReadonly","isVariableEnabled","isDatasourceEnabled","disableShortcuts","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","onSave","onDiscard","chartsTheme","isEditMode","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","setSavedDatasources","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","metadata","name","spec","onEditButtonClick","datasources","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","disabled","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","initialVariableIsSticky","paddingTop","paddingX","height","FallbackComponent","enablePinning","enableSyncGrouping","disableMetadataEdition","original","current"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAkCA,QAAQ,QAAQ,QAAQ;AAC1D,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,cAAc,EAAEC,UAAU,EAAEC,aAAa,EAAEC,cAAc,QAAQ,yBAAyB;AACnG,SAASC,kBAAkB,QAAQ,4BAA4B;AAE/D,SACEC,WAAW,EACXC,SAAS,EACTC,qBAAqB,EACrBC,gBAAgB,EAChBC,sBAAsB,EACtBC,yCAAyC,EACzCC,gBAAgB,EAChBC,iBAAiB,EAEjBC,cAAc,EACdC,6BAA6B,EAC7BC,WAAW,QACN,mBAAmB;AAC1B,SAA0BC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,gBAAgB;AAChH,SAASC,kBAAkB,QAAQ,2BAA2B;AAmB9D,OAAO,MAAMC,eAAe,CAACC;IAC3B,qBACE,KAACF;kBACC,cAAA,KAACG;YAAqB,GAAGD,KAAK;;;AAGpC,EAAE;AAEF,MAAMC,sBAAsB,CAACD;IAC3B,MAAM,EACJE,iBAAiB,EACjBC,mBAAmB,EACnBC,UAAU,EACVC,iBAAiB,EACjBC,mBAAmB,EACnBC,gBAAgB,EAChBC,UAAU,EACVC,uBAAuB,EACvBC,6BAA6B,EAC7BC,uBAAuB,EACvBC,MAAM,EACNC,SAAS,EACV,GAAGb;IAEJ,MAAMc,cAAchC;IAEpB,MAAM,EAAEiC,UAAU,EAAEC,WAAW,EAAE,GAAGnB;IAEpC,MAAM,EAAEoB,SAAS,EAAEC,YAAY,EAAE,GAAGvB;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4BACxB;;;kCAGJ,KAACxB;wBAAemC,aAAaA;wBAAamC,eAAe;wBAAOC,oBAAoB;kCAClF,cAAA,KAAClE;;kCAEH,KAACG;kCACD,KAACC;kCACD,KAACG;kCACD,KAACF;kCACD,KAACG;wBAAeY,YAAY,CAACW;wBAAYoC,wBAAwB,CAAC3C;;kCAClE,KAACf;oBACAiB,iCAAiCK,4BAChC,KAACrB;wBAAY0D,UAAUjC;wBAAmBkC,SAASpC;;;;;;AAK7D"}
1
+ {"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { DashboardSpec } from '@perses-dev/spec';\nimport {\n PanelDrawer,\n Dashboard,\n useDashboardShortcuts,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DashboardDiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n EmptyDashboardProps,\n EditJsonDialog,\n SaveChangesConfirmationDialog,\n LeaveDialog,\n} from '../../components';\nimport { OnSaveDashboard, useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\nimport { PanelFocusProvider } from '../../keyboard-shortcuts';\nimport { DashboardResource } from '../../model';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n emptyDashboardProps?: Partial<EmptyDashboardProps>;\n isReadonly: boolean;\n isVariableEnabled: boolean;\n isDatasourceEnabled: boolean;\n disableShortcuts?: boolean;\n isCreating?: boolean;\n isInitialVariableSticky?: boolean;\n // If true, browser confirmation dialog will be shown when navigating away with unsaved changes (closing tab, ...).\n isLeavingConfirmDialogEnabled?: boolean;\n dashboardTitleComponent?: ReactNode;\n onSave?: OnSaveDashboard;\n onDiscard?: (name: string, spec: DashboardSpec) => void;\n}\n\nexport const DashboardApp = (props: DashboardAppProps): ReactElement => {\n return (\n <PanelFocusProvider>\n <DashboardAppContent {...props} />\n </PanelFocusProvider>\n );\n};\n\nconst DashboardAppContent = (props: DashboardAppProps): ReactElement => {\n const {\n dashboardResource,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n } = props;\n\n const chartsTheme = useChartsTheme();\n\n const { isEditMode, setEditMode } = useEditMode();\n\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { setSavedDatasources } = useDatasourceStore();\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = (): void => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard.metadata.name, dashboard.spec);\n }\n };\n\n const onEditButtonClick = (): void => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n setSavedDatasources(dashboard.spec.datasources ?? {});\n };\n\n const onCancelButtonClick = (): void => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n useDashboardShortcuts({\n onSave,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n disabled: disableShortcuts,\n });\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={isInitialVariableSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ paddingTop: 2, paddingX: 2, height: '100%' }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard\n emptyDashboardProps={{\n onEditButtonClick,\n ...emptyDashboardProps,\n }}\n />\n </ErrorBoundary>\n <ChartsProvider chartsTheme={chartsTheme} enablePinning={false} enableSyncGrouping={false}>\n <PanelDrawer />\n </ChartsProvider>\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DashboardDiscardChangesConfirmationDialog />\n <EditJsonDialog isReadonly={!isEditMode} disableMetadataEdition={!isCreating} />\n <SaveChangesConfirmationDialog />\n {isLeavingConfirmDialogEnabled && isEditMode && (\n <LeaveDialog original={originalDashboard} current={dashboard} />\n )}\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ChartsProvider","ErrorAlert","ErrorBoundary","useChartsTheme","useDatasourceStore","PanelDrawer","Dashboard","useDashboardShortcuts","PanelGroupDialog","DeletePanelGroupDialog","DashboardDiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","EditJsonDialog","SaveChangesConfirmationDialog","LeaveDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","PanelFocusProvider","DashboardApp","props","DashboardAppContent","dashboardResource","emptyDashboardProps","isReadonly","isVariableEnabled","isDatasourceEnabled","disableShortcuts","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","onSave","onDiscard","chartsTheme","isEditMode","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","setSavedDatasources","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","metadata","name","spec","onEditButtonClick","datasources","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","disabled","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","initialVariableIsSticky","paddingTop","paddingX","height","FallbackComponent","enablePinning","enableSyncGrouping","disableMetadataEdition","original","current"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAkCA,QAAQ,QAAQ,QAAQ;AAC1D,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,cAAc,EAAEC,UAAU,EAAEC,aAAa,EAAEC,cAAc,QAAQ,yBAAyB;AACnG,SAASC,kBAAkB,QAAQ,4BAA4B;AAE/D,SACEC,WAAW,EACXC,SAAS,EACTC,qBAAqB,EACrBC,gBAAgB,EAChBC,sBAAsB,EACtBC,yCAAyC,EACzCC,gBAAgB,EAChBC,iBAAiB,EAEjBC,cAAc,EACdC,6BAA6B,EAC7BC,WAAW,QACN,mBAAmB;AAC1B,SAA0BC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,gBAAgB;AAChH,SAASC,kBAAkB,QAAQ,2BAA2B;AAmB9D,OAAO,MAAMC,eAAe,CAACC;IAC3B,qBACE,KAACF;kBACC,cAAA,KAACG;YAAqB,GAAGD,KAAK;;;AAGpC,EAAE;AAEF,MAAMC,sBAAsB,CAACD;IAC3B,MAAM,EACJE,iBAAiB,EACjBC,mBAAmB,EACnBC,UAAU,EACVC,i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AAYA;gBACZC,mBAAmBA;gBACnBC,qBAAqBA;gBACrBuB,mBAAmBA;gBACnBE,qBAAqBA;;0BAEvB,MAACrD;gBAAI2D,IAAI;oBAAEQ,YAAY;oBAAGC,UAAU;oBAAGC,QAAQ;gBAAO;;kCACpD,KAAClE;wBAAcmE,mBAAmBpE;kCAChC,cAAA,KAACK;4BACCkB,qBAAqB;gCACnB0B;gCACA,GAAG1B,mBAAmB;4BACxB;;;kCAGJ,KAACxB;wBAAemC,aAAaA;wBAAamC,eAAe;wBAAOC,oBAAoB;kCAClF,cAAA,KAAClE;;kCAEH,KAACG;kCACD,KAACC;kCACD,KAACG;kCACD,KAACF;kCACD,KAACG;wBAAeY,YAAY,CAACW;wBAAYoC,wBAAwB,CAAC3C;;kCAClE,KAACf;oBACAiB,iCAAiCK,4BAChC,KAACrB;wBAAY0D,UAAUjC;wBAAmBkC,SAASpC;;;;;;AAK7D"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Box } from '@mui/material';
15
15
  import { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';
16
16
  import { TimeRangeProviderWithQueryParams, useInitialRefreshInterval, useInitialTimeRange, usePluginBuiltinVariableDefinitions } from '@perses-dev/plugin-system';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, BoxProps } from '@mui/material';\nimport { BuiltinVariableDefinition } from '@perses-dev/spec';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport {\n TimeRangeProviderWithQueryParams,\n useInitialRefreshInterval,\n useInitialTimeRange,\n usePluginBuiltinVariableDefinitions,\n} from '@perses-dev/plugin-system';\nimport { ReactElement, useMemo } from 'react';\nimport { DEFAULT_DASHBOARD_DURATION, DEFAULT_REFRESH_INTERVAL } from '../../constants';\nimport {\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n VariableProviderProps,\n VariableProviderWithQueryParams,\n} from '../../context';\nimport { DashboardProviderWithQueryParams } from '../../context/DashboardProvider/DashboardProviderWithQueryParams';\nimport { DashboardApp, DashboardAppProps } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'>, DashboardAppProps {\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n externalVariableDefinitions?: VariableProviderProps['externalVariableDefinitions'];\n isEditing?: boolean;\n isCreating?: boolean;\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps): ReactElement {\n const {\n dashboardResource,\n datasourceApi,\n externalVariableDefinitions,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isEditing,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n sx,\n ...others\n } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? DEFAULT_DASHBOARD_DURATION;\n const dashboardRefreshInterval = spec.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n const initialRefreshInterval = useInitialRefreshInterval(dashboardRefreshInterval);\n const { data } = usePluginBuiltinVariableDefinitions();\n\n const builtinVariables = useMemo(() => {\n const result = [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__dashboard',\n value: () => dashboardResource.metadata.name,\n source: 'Dashboard',\n display: {\n name: '__dashboard',\n description: 'The name of the current dashboard',\n hidden: true,\n },\n },\n } as BuiltinVariableDefinition,\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__project',\n value: () => dashboardResource.metadata.project,\n source: 'Dashboard',\n display: {\n name: '__project',\n description: 'The name of the current dashboard project',\n hidden: true,\n },\n },\n } as BuiltinVariableDefinition,\n ];\n if (data) {\n data.forEach((def: BuiltinVariableDefinition) => result.push(def));\n }\n return result;\n }, [dashboardResource.metadata.name, dashboardResource.metadata.project, data]);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProviderWithQueryParams\n initialState={{\n isEditMode: !!isEditing,\n dashboardResource,\n }}\n >\n <TimeRangeProviderWithQueryParams\n initialTimeRange={initialTimeRange}\n initialRefreshInterval={initialRefreshInterval}\n >\n <VariableProviderWithQueryParams\n initialVariableDefinitions={spec.variables}\n externalVariableDefinitions={externalVariableDefinitions}\n builtinVariableDefinitions={builtinVariables}\n >\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp\n dashboardResource={dashboardResource}\n emptyDashboardProps={emptyDashboardProps}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n disableShortcuts={disableShortcuts}\n isCreating={isCreating}\n isInitialVariableSticky={isInitialVariableSticky}\n isLeavingConfirmDialogEnabled={isLeavingConfirmDialogEnabled}\n dashboardTitleComponent={dashboardTitleComponent}\n onSave={onSave}\n onDiscard={onDiscard}\n />\n </ErrorBoundary>\n </Box>\n </VariableProviderWithQueryParams>\n </TimeRangeProviderWithQueryParams>\n </DashboardProviderWithQueryParams>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProviderWithQueryParams","useInitialRefreshInterval","useInitialTimeRange","usePluginBuiltinVariableDefinitions","useMemo","DEFAULT_DASHBOARD_DURATION","DEFAULT_REFRESH_INTERVAL","DatasourceStoreProvider","VariableProviderWithQueryParams","DashboardProviderWithQueryParams","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","externalVariableDefinitions","emptyDashboardProps","isReadonly","isVariableEnabled","isDatasourceEnabled","disableShortcuts","isEditing","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","onSave","onDiscard","sx","others","spec","dashboardDuration","duration","dashboardRefreshInterval","refreshInterval","initialTimeRange","initialRefreshInterval","data","builtinVariables","result","kind","name","value","metadata","source","display","description","hidden","project","forEach","def","push","initialState","isEditMode","initialVariableDefinitions","variables","builtinVariableDefinitions","width","height","position","overflow","FallbackComponent"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,QAAkB,gBAAgB;AAE9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAQ,yBAAyB;AAC9E,SACEC,gCAAgC,EAChCC,yBAAyB,EACzBC,mBAAmB,EACnBC,mCAAmC,QAC9B,4BAA4B;AACnC,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAASC,0BAA0B,EAAEC,wBAAwB,QAAQ,kBAAkB;AACvF,SAEEC,uBAAuB,EAEvBC,+BAA+B,QAC1B,gBAAgB;AACvB,SAASC,gCAAgC,QAAQ,mEAAm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ACE,KAAC9B;QAAwBM,mBAAmBA;QAAmBC,eAAeA;kBAC5E,cAAA,KAACL;YACC2C,cAAc;gBACZC,YAAY,CAAC,CAAChC;gBACdR;YACF;sBAEA,cAAA,KAACb;gBACCmC,kBAAkBA;gBAClBC,wBAAwBA;0BAExB,cAAA,KAAC5B;oBACC8C,4BAA4BxB,KAAKyB,SAAS;oBAC1CxC,6BAA6BA;oBAC7ByC,4BAA4BlB;8BAE5B,cAAA,KAAC1C;wBACCgC,IAAI7B,UACF;4BACE8C,SAAS;4BACTY,OAAO;4BACPC,QAAQ;4BACRC,UAAU;4BACVC,UAAU;wBACZ,GACAhC;wBAED,GAAGC,MAAM;kCAEV,cAAA,KAAChC;4BAAcgE,mBAAmB/D;sCAChC,cAAA,KAACY;gCACCG,mBAAmBA;gCACnBG,qBAAqBA;gCACrBC,YAAYA;gCACZC,mBAAmBA;gCACnBC,qBAAqBA;gCACrBC,kBAAkBA;gCAClBE,YAAYA;gCACZC,yBAAyBA;gCACzBC,+BAA+BA;gCAC/BC,yBAAyBA;gCACzBC,QAAQA;gCACRC,WAAWA;;;;;;;;AAS7B"}
1
+ {"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, BoxProps } from '@mui/material';\nimport { BuiltinVariableDefinition } from '@perses-dev/spec';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport {\n TimeRangeProviderWithQueryParams,\n useInitialRefreshInterval,\n useInitialTimeRange,\n usePluginBuiltinVariableDefinitions,\n} from '@perses-dev/plugin-system';\nimport { ReactElement, useMemo } from 'react';\nimport { DEFAULT_DASHBOARD_DURATION, DEFAULT_REFRESH_INTERVAL } from '../../constants';\nimport {\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n VariableProviderProps,\n VariableProviderWithQueryParams,\n} from '../../context';\nimport { DashboardProviderWithQueryParams } from '../../context/DashboardProvider/DashboardProviderWithQueryParams';\nimport { DashboardApp, DashboardAppProps } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'>, DashboardAppProps {\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n externalVariableDefinitions?: VariableProviderProps['externalVariableDefinitions'];\n isEditing?: boolean;\n isCreating?: boolean;\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps): ReactElement {\n const {\n dashboardResource,\n datasourceApi,\n externalVariableDefinitions,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isEditing,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n sx,\n ...others\n } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? DEFAULT_DASHBOARD_DURATION;\n const dashboardRefreshInterval = spec.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n const initialRefreshInterval = useInitialRefreshInterval(dashboardRefreshInterval);\n const { data } = usePluginBuiltinVariableDefinitions();\n\n const builtinVariables = useMemo(() => {\n const result = [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__dashboard',\n value: () => dashboardResource.metadata.name,\n source: 'Dashboard',\n display: {\n name: '__dashboard',\n description: 'The name of the current dashboard',\n hidden: true,\n },\n },\n } as BuiltinVariableDefinition,\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__project',\n value: () => dashboardResource.metadata.project,\n source: 'Dashboard',\n display: {\n name: '__project',\n description: 'The name of the current dashboard project',\n hidden: true,\n },\n },\n } as BuiltinVariableDefinition,\n ];\n if (data) {\n data.forEach((def: BuiltinVariableDefinition) => result.push(def));\n }\n return result;\n }, [dashboardResource.metadata.name, dashboardResource.metadata.project, data]);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProviderWithQueryParams\n initialState={{\n isEditMode: !!isEditing,\n dashboardResource,\n }}\n >\n <TimeRangeProviderWithQueryParams\n initialTimeRange={initialTimeRange}\n initialRefreshInterval={initialRefreshInterval}\n >\n <VariableProviderWithQueryParams\n initialVariableDefinitions={spec.variables}\n externalVariableDefinitions={externalVariableDefinitions}\n builtinVariableDefinitions={builtinVariables}\n >\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp\n dashboardResource={dashboardResource}\n emptyDashboardProps={emptyDashboardProps}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n disableShortcuts={disableShortcuts}\n isCreating={isCreating}\n isInitialVariableSticky={isInitialVariableSticky}\n isLeavingConfirmDialogEnabled={isLeavingConfirmDialogEnabled}\n dashboardTitleComponent={dashboardTitleComponent}\n onSave={onSave}\n onDiscard={onDiscard}\n />\n </ErrorBoundary>\n </Box>\n </VariableProviderWithQueryParams>\n </TimeRangeProviderWithQueryParams>\n </DashboardProviderWithQueryParams>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProviderWithQueryParams","useInitialRefreshInterval","useInitialTimeRange","usePluginBuiltinVariableDefinitions","useMemo","DEFAULT_DASHBOARD_DURATION","DEFAULT_REFRESH_INTERVAL","DatasourceStoreProvider","VariableProviderWithQueryParams","DashboardProviderWithQueryParams","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","externalVariableDefinitions","emptyDashboardProps","isReadonly","isVariableEnabled","isDatasourceEnabled","disableShortcuts","isEditing","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","onSave","onDiscard","sx","others","spec","dashboardDuration","duration","dashboardRefreshInterval","refreshInterval","initialTimeRange","initialRefreshInterval","data","builtinVariables","result","kind","name","value","metadata","source","display","description","hidden","project","forEach","def","push","initialState","isEditMode","initialVariableDefinitions","variables","builtinVariableDefinitions","width","height","position","overflow","FallbackComponent"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,QAAkB,gBAAgB;AAE9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAQ,yBAAyB;AAC9E,SACEC,gCAAgC,EAChCC,yBAAyB,EACzBC,mBAAmB,EACnBC,mCAAmC,QAC9B,4BAA4B;AACnC,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAASC,0BAA0B,EAAEC,wBAAwB,QAAQ,kBAAkB;AACvF,SAEEC,uBAAuB,EAEvBC,+BAA+B,QAC1B,gBAAgB;AACvB,SAASC,gCAAgC,QAAQ,mEAAmE;AACpH,SAASC,YAAY,QAA2B,iBAAiB;AASjE;;CAEC,GACD,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,iBAAiB,EACjBC,aAAa,EACbC,2BAA2B,EAC3BC,mBAAmB,EACnBC,UAAU,EACVC,iBAAiB,EACjBC,mBAAmB,EACnBC,gBAAgB,EAChBC,SAAS,EACTC,UAAU,EACVC,uBAAuB,EACvBC,6BAA6B,EAC7BC,uBAAuB,EACvBC,MAAM,EACNC,SAAS,EACTC,EAAE,EACF,GAAGC,QACJ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OAAO;4BACPC,QAAQ;4BACRC,UAAU;4BACVC,UAAU;wBACZ,GACAhC;wBAED,GAAGC,MAAM;kCAEV,cAAA,KAAChC;4BAAcgE,mBAAmB/D;sCAChC,cAAA,KAACY;gCACCG,mBAAmBA;gCACnBG,qBAAqBA;gCACrBC,YAAYA;gCACZC,mBAAmBA;gCACnBC,qBAAqBA;gCACrBC,kBAAkBA;gCAClBE,YAAYA;gCACZC,yBAAyBA;gCACzBC,+BAA+BA;gCAC/BC,yBAAyBA;gCACzBC,QAAQA;gCACRC,WAAWA;;;;;;;;AAS7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/dashboards",
3
- "version": "0.54.0-beta.1",
3
+ "version": "0.54.0-beta.2",
4
4
  "description": "The dashboards feature in Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -29,18 +29,15 @@
29
29
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
30
30
  },
31
31
  "dependencies": {
32
- "@perses-dev/components": "0.54.0-beta.1",
33
- "@perses-dev/core": "0.53.0",
34
- "@perses-dev/plugin-system": "0.54.0-beta.1",
32
+ "@perses-dev/components": "0.54.0-beta.2",
33
+ "@perses-dev/plugin-system": "0.54.0-beta.2",
35
34
  "@perses-dev/spec": "0.2.0-beta.0",
36
- "@types/react-grid-layout": "^1.3.2",
37
- "date-fns": "^4.1.0",
35
+ "@tanstack/react-hotkeys": "^0.9.1",
38
36
  "immer": "^10.1.1",
39
37
  "mdi-material-ui": "^7.9.2",
40
38
  "react-grid-layout": "^1.3.4",
41
39
  "react-hook-form": "^7.46.1",
42
40
  "react-intersection-observer": "^9.4.0",
43
- "@tanstack/react-hotkeys": "^0.9.1",
44
41
  "use-immer": "^0.11.0",
45
42
  "use-query-params": "^2.2.1",
46
43
  "use-resize-observer": "^9.0.0",
@@ -48,8 +45,8 @@
48
45
  "zustand": "^4.3.3"
49
46
  },
50
47
  "devDependencies": {
51
- "history": "^5.3.0",
52
- "intersection-observer": "^0.12.2"
48
+ "@types/react-grid-layout": "^1.3.6",
49
+ "history": "^5.3.0"
53
50
  },
54
51
  "peerDependencies": {
55
52
  "@mui/material": "^6.1.10",