@perses-dev/dashboards 0.24.0 → 0.26.0

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 (161) hide show
  1. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +9 -2
  2. package/dist/cjs/components/Dashboard/Dashboard.js +23 -6
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -17
  4. package/dist/cjs/components/EditButton/EditButton.js +41 -0
  5. package/dist/cjs/components/EditButton/index.js +28 -0
  6. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +42 -0
  7. package/dist/cjs/components/EditJsonButton/index.js +28 -0
  8. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +86 -0
  9. package/dist/cjs/components/EditJsonDialog/index.js +28 -0
  10. package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +128 -0
  11. package/dist/cjs/components/EmptyDashboard/index.js +28 -0
  12. package/dist/cjs/components/Panel/Panel.js +0 -4
  13. package/dist/cjs/components/Panel/PanelHeader.js +2 -2
  14. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +185 -0
  15. package/dist/cjs/components/QuerySummaryTable/index.js +28 -0
  16. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  17. package/dist/cjs/components/Variables/EditVariablesButton.js +9 -2
  18. package/dist/cjs/components/index.js +4 -0
  19. package/dist/cjs/constants/user-interface-text.js +1 -0
  20. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +12 -6
  21. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +10 -1
  22. package/dist/cjs/context/DashboardProvider/edit-json-dialog-slice.js +36 -0
  23. package/dist/cjs/context/DatasourceStoreProvider.js +9 -3
  24. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +3 -41
  25. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +68 -0
  26. package/dist/cjs/stories/decorators/WithDashboard.js +39 -0
  27. package/dist/cjs/stories/decorators/WithDatasourceStore.js +82 -0
  28. package/dist/cjs/stories/decorators/WithPluginRegistry.js +91 -0
  29. package/dist/cjs/stories/decorators/WithQueryClient.js +29 -0
  30. package/dist/cjs/stories/decorators/WithQueryParams.js +29 -0
  31. package/dist/cjs/stories/decorators/WithTemplateVariables.js +35 -0
  32. package/dist/cjs/stories/decorators/WithTimeRange.js +38 -0
  33. package/dist/cjs/stories/decorators/constants.js +36 -0
  34. package/dist/cjs/stories/decorators/index.js +35 -0
  35. package/dist/cjs/views/ViewDashboard/DashboardApp.js +11 -4
  36. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -1
  37. package/dist/components/AddPanelButton/AddPanelButton.d.ts +16 -1
  38. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  39. package/dist/components/AddPanelButton/AddPanelButton.js +9 -2
  40. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  41. package/dist/components/Dashboard/Dashboard.d.ts +10 -2
  42. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  43. package/dist/components/Dashboard/Dashboard.js +24 -7
  44. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  45. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  46. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  47. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  48. package/dist/components/EditButton/EditButton.d.ts +13 -0
  49. package/dist/components/EditButton/EditButton.d.ts.map +1 -0
  50. package/dist/components/EditButton/EditButton.js +30 -0
  51. package/dist/components/EditButton/EditButton.js.map +1 -0
  52. package/dist/components/EditButton/index.d.ts +2 -0
  53. package/dist/components/EditButton/index.d.ts.map +1 -0
  54. package/dist/components/EditButton/index.js +15 -0
  55. package/dist/components/EditButton/index.js.map +1 -0
  56. package/dist/components/EditJsonButton/EditJsonButton.d.ts +3 -0
  57. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -0
  58. package/dist/components/EditJsonButton/EditJsonButton.js +31 -0
  59. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -0
  60. package/dist/components/EditJsonButton/index.d.ts +2 -0
  61. package/dist/components/EditJsonButton/index.d.ts.map +1 -0
  62. package/dist/components/EditJsonButton/index.js +15 -0
  63. package/dist/components/EditJsonButton/index.js.map +1 -0
  64. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +3 -0
  65. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -0
  66. package/dist/components/EditJsonDialog/EditJsonDialog.js +80 -0
  67. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -0
  68. package/dist/components/EditJsonDialog/index.d.ts +2 -0
  69. package/dist/components/EditJsonDialog/index.d.ts.map +1 -0
  70. package/dist/components/EditJsonDialog/index.js +15 -0
  71. package/dist/components/EditJsonDialog/index.js.map +1 -0
  72. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +37 -0
  73. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -0
  74. package/dist/components/EmptyDashboard/EmptyDashboard.js +124 -0
  75. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -0
  76. package/dist/components/EmptyDashboard/index.d.ts +2 -0
  77. package/dist/components/EmptyDashboard/index.d.ts.map +1 -0
  78. package/dist/components/EmptyDashboard/index.js +15 -0
  79. package/dist/components/EmptyDashboard/index.js.map +1 -0
  80. package/dist/components/Panel/Panel.d.ts.map +1 -1
  81. package/dist/components/Panel/Panel.js +0 -4
  82. package/dist/components/Panel/Panel.js.map +1 -1
  83. package/dist/components/Panel/PanelHeader.d.ts +1 -2
  84. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  85. package/dist/components/Panel/PanelHeader.js +2 -2
  86. package/dist/components/Panel/PanelHeader.js.map +1 -1
  87. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +11 -0
  88. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -0
  89. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +179 -0
  90. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -0
  91. package/dist/components/QuerySummaryTable/index.d.ts +2 -0
  92. package/dist/components/QuerySummaryTable/index.d.ts.map +1 -0
  93. package/dist/components/QuerySummaryTable/index.js +15 -0
  94. package/dist/components/QuerySummaryTable/index.js.map +1 -0
  95. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +1 -1
  96. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +1 -1
  97. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  98. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  99. package/dist/components/Variables/EditVariablesButton.d.ts +16 -1
  100. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  101. package/dist/components/Variables/EditVariablesButton.js +9 -2
  102. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  103. package/dist/components/index.d.ts +4 -0
  104. package/dist/components/index.d.ts.map +1 -1
  105. package/dist/components/index.js +4 -0
  106. package/dist/components/index.js.map +1 -1
  107. package/dist/constants/user-interface-text.d.ts +1 -0
  108. package/dist/constants/user-interface-text.d.ts.map +1 -1
  109. package/dist/constants/user-interface-text.js +1 -0
  110. package/dist/constants/user-interface-text.js.map +1 -1
  111. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  112. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  113. package/dist/context/DashboardProvider/DashboardProvider.js +12 -6
  114. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  115. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +8 -0
  116. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  117. package/dist/context/DashboardProvider/dashboard-provider-api.js +10 -0
  118. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  119. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts +12 -0
  120. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts.map +1 -0
  121. package/dist/context/DashboardProvider/edit-json-dialog-slice.js +30 -0
  122. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -0
  123. package/dist/context/DatasourceStoreProvider.d.ts +2 -0
  124. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  125. package/dist/context/DatasourceStoreProvider.js +9 -3
  126. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  127. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +3 -2
  128. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  129. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +1 -39
  130. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  131. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts +4 -0
  132. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -0
  133. package/dist/context/TemplateVariableProvider/hydrationUtils.js +62 -0
  134. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -0
  135. package/dist/stories/decorators/WithDashboard.js +33 -0
  136. package/dist/stories/decorators/WithDashboard.js.map +1 -0
  137. package/dist/stories/decorators/WithDatasourceStore.js +76 -0
  138. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -0
  139. package/dist/stories/decorators/WithPluginRegistry.js +46 -0
  140. package/dist/stories/decorators/WithPluginRegistry.js.map +1 -0
  141. package/dist/stories/decorators/WithQueryClient.js +23 -0
  142. package/dist/stories/decorators/WithQueryClient.js.map +1 -0
  143. package/dist/stories/decorators/WithQueryParams.js +23 -0
  144. package/dist/stories/decorators/WithQueryParams.js.map +1 -0
  145. package/dist/stories/decorators/WithTemplateVariables.js +29 -0
  146. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -0
  147. package/dist/stories/decorators/WithTimeRange.js +32 -0
  148. package/dist/stories/decorators/WithTimeRange.js.map +1 -0
  149. package/dist/stories/decorators/constants.js +30 -0
  150. package/dist/stories/decorators/constants.js.map +1 -0
  151. package/dist/stories/decorators/index.js +22 -0
  152. package/dist/stories/decorators/index.js.map +1 -0
  153. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -0
  154. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  155. package/dist/views/ViewDashboard/DashboardApp.js +12 -5
  156. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  157. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -8
  158. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  159. package/dist/views/ViewDashboard/ViewDashboard.js +2 -1
  160. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  161. package/package.json +4 -4
@@ -16,6 +16,7 @@ import { createStore, useStore } from 'zustand';
16
16
  import { immer } from 'zustand/middleware/immer';
17
17
  import { devtools } from 'zustand/middleware';
18
18
  import { TemplateVariableContext, DEFAULT_ALL_VALUE as ALL_VALUE } from '@perses-dev/plugin-system';
19
+ import { hydrateTemplateVariableStates } from './hydrationUtils';
19
20
  import { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';
20
21
  const TemplateVariableStoreContext = /*#__PURE__*/ createContext(undefined);
21
22
  function useTemplateVariableStoreCtx() {
@@ -169,44 +170,5 @@ export function TemplateVariableProvider({ children , initialVariableDefinitions
169
170
  })
170
171
  });
171
172
  }
172
- /** Helpers */ function hydrateTemplateVariableState(variable, initialValue) {
173
- const varState = {
174
- value: null,
175
- loading: false
176
- };
177
- switch(variable.kind){
178
- case 'TextVariable':
179
- varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.value;
180
- break;
181
- case 'ListVariable':
182
- varState.options = [];
183
- var ref;
184
- varState.value = (ref = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.default_value) !== null && ref !== void 0 ? ref : null;
185
- if (varState.options.length > 0 && !varState.value) {
186
- var ref1;
187
- var ref2;
188
- const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
189
- if (firstOptionValue !== null) {
190
- varState.value = variable.spec.allow_multiple ? [
191
- firstOptionValue
192
- ] : firstOptionValue;
193
- }
194
- }
195
- break;
196
- default:
197
- break;
198
- }
199
- return varState;
200
- }
201
- function hydrateTemplateVariableStates(definitions, initialValues) {
202
- const state = {};
203
- definitions.forEach((v)=>{
204
- const name = v.spec.name;
205
- const param = initialValues[name];
206
- const initialValue = param ? param : null;
207
- state[name] = hydrateTemplateVariableState(v, initialValue);
208
- });
209
- return state;
210
- }
211
173
 
212
174
  //# sourceMappingURL=TemplateVariableProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"sourcesContent":["// Copyright 2023 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, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\n\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\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 if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [], queryParams }: TemplateVariableSrvArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions, initialParams);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\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 }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const queryParams = useVariableQueryParams(initialVariableDefinitions);\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions, queryParams }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(variable: VariableDefinition, initialValue?: VariableValue) {\n const varState: VariableState = {\n value: null,\n loading: false,\n };\n switch (variable.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? variable.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n varState.value = initialValue ?? variable.spec.default_value ?? null;\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = variable.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(\n definitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>\n): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state[name] = hydrateTemplateVariableState(v, initialValue);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","useVariableQueryParams","getInitalValuesFromQueryParameters","getURLQueryParamName","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","queryParams","initialParams","set","hydrateTemplateVariableStates","definitions","loading","val","Array","isArray","includes","at","filter","setQueryParams","TemplateVariableProvider","hydrateTemplateVariableState","variable","initialValue","kind","default_value","length","firstOptionValue","allow_multiple","initialValues","param"],"mappings":"AAAA,oCAAo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vB,IAA0B,cAA1BA,IAA0B,GAAI,IAAI,AAAC;gBAC5D,IAAIkD,gBAAgB,KAAK,IAAI,EAAE;oBAC7BlD,QAAQ,CAACuB,KAAK,GAAGsB,QAAQ,CAACnC,IAAI,CAACyC,cAAc,GAAG;wBAACD,gBAAgB;qBAAC,GAAGA,gBAAgB,CAAC;gBACxF,CAAC;YACH,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAOlD,QAAQ,CAAC;AAClB,CAAC;AAED,SAASiC,6BAA6B,CACpCC,WAAiC,EACjCkB,aAA4C,EAC1B;IAClB,MAAM7D,KAAK,GAAqB,EAAE,AAAC;IACnC2C,WAAW,CAACpC,OAAO,CAAC,CAACW,CAAC,GAAK;QACzB,MAAMV,IAAI,GAAGU,CAAC,CAACC,IAAI,CAACX,IAAI,AAAC;QACzB,MAAMsD,KAAK,GAAGD,aAAa,CAACrD,IAAI,CAAC,AAAC;QAClC,MAAM+C,YAAY,GAAGO,KAAK,GAAGA,KAAK,GAAG,IAAI,AAAC;QAC1C9D,KAAK,CAACQ,IAAI,CAAC,GAAG6C,4BAA4B,CAACnC,CAAC,EAAEqC,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IACH,OAAOvD,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"sourcesContent":["// Copyright 2023 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, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\n\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { hydrateTemplateVariableStates } from './hydrationUtils';\nimport { useVariableQueryParams, getInitalValuesFromQueryParameters, getURLQueryParamName } from './query-params';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\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 if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [], queryParams }: TemplateVariableSrvArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions, initialParams);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\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 }))\n )\n );\n\n return store;\n}\n\nexport interface TemplateVariableProviderProps {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}\n\nexport function TemplateVariableProvider({ children, initialVariableDefinitions = [] }: TemplateVariableProviderProps) {\n const queryParams = useVariableQueryParams(initialVariableDefinitions);\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions, queryParams }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","hydrateTemplateVariableStates","useVariableQueryParams","getInitalValuesFromQueryParameters","getURLQueryParamName","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","queryParams","initialParams","set","definitions","loading","val","Array","isArray","includes","at","filter","setQueryParams","TemplateVariableProvider"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,aAAa,EAAEC,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AE,CAAC,CAAC,AAAC;IAEtG,qBACE,KAAC/C,4BAA4B,CAAC4C,QAAQ;QAACJ,KAAK,EAAEjC,KAAK;kBACjD,cAAA,KAAC4B,cAAc;sBAAEC,QAAQ;UAAkB;MACL,CACxC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { VariableValue, VariableDefinition } from '@perses-dev/core';
2
+ import { VariableStateMap } from '@perses-dev/plugin-system';
3
+ export declare function hydrateTemplateVariableStates(definitions: VariableDefinition[], initialValues: Record<string, VariableValue>): VariableStateMap;
4
+ //# sourceMappingURL=hydrationUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrationUtils.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/hydrationUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAoC,MAAM,2BAA2B,CAAC;AAqC/F,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,kBAAkB,EAAE,EACjC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAC3C,gBAAgB,CAUlB"}
@@ -0,0 +1,62 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { DEFAULT_ALL_VALUE } from '@perses-dev/plugin-system';
14
+ function hydrateTemplateVariableState(variable, initialValue) {
15
+ const varState = {
16
+ value: null,
17
+ loading: false
18
+ };
19
+ switch(variable.kind){
20
+ case 'TextVariable':
21
+ varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.value;
22
+ break;
23
+ case 'ListVariable':
24
+ varState.options = [];
25
+ var ref;
26
+ varState.value = (ref = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.default_value) !== null && ref !== void 0 ? ref : null;
27
+ if (varState.options.length > 0 && !varState.value) {
28
+ var ref1;
29
+ var ref2;
30
+ const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
31
+ if (firstOptionValue !== null) {
32
+ varState.value = variable.spec.allow_multiple ? [
33
+ firstOptionValue
34
+ ] : firstOptionValue;
35
+ }
36
+ }
37
+ // "all" variable handling assumes the value is not in an array. This is
38
+ // handled properly during internal variable interactions, but it is possible
39
+ // to end up in a buggy state if the variables are initialized with an "all"
40
+ // value inside an array. When hydrating variables, normalize this to minimize
41
+ // bugs.
42
+ if (Array.isArray(varState.value) && varState.value.length === 1 && varState.value[0] === DEFAULT_ALL_VALUE) {
43
+ varState.value = DEFAULT_ALL_VALUE;
44
+ }
45
+ break;
46
+ default:
47
+ break;
48
+ }
49
+ return varState;
50
+ }
51
+ export function hydrateTemplateVariableStates(definitions, initialValues) {
52
+ const state = {};
53
+ definitions.forEach((v)=>{
54
+ const name = v.spec.name;
55
+ const param = initialValues[name];
56
+ const initialValue = param ? param : null;
57
+ state[name] = hydrateTemplateVariableState(v, initialValue);
58
+ });
59
+ return state;
60
+ }
61
+
62
+ //# sourceMappingURL=hydrationUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/TemplateVariableProvider/hydrationUtils.ts"],"sourcesContent":["// Copyright 2023 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 { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { VariableStateMap, VariableState, DEFAULT_ALL_VALUE } from '@perses-dev/plugin-system';\n\nfunction hydrateTemplateVariableState(variable: VariableDefinition, initialValue?: VariableValue) {\n const varState: VariableState = {\n value: null,\n loading: false,\n };\n switch (variable.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? variable.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n varState.value = initialValue ?? variable.spec.default_value ?? null;\n\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = variable.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n // \"all\" variable handling assumes the value is not in an array. This is\n // handled properly during internal variable interactions, but it is possible\n // to end up in a buggy state if the variables are initialized with an \"all\"\n // value inside an array. When hydrating variables, normalize this to minimize\n // bugs.\n if (Array.isArray(varState.value) && varState.value.length === 1 && varState.value[0] === DEFAULT_ALL_VALUE) {\n varState.value = DEFAULT_ALL_VALUE;\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nexport function hydrateTemplateVariableStates(\n definitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>\n): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state[name] = hydrateTemplateVariableState(v, initialValue);\n });\n\n return state;\n}\n"],"names":["DEFAULT_ALL_VALUE","hydrateTemplateVariableState","variable","initialValue","varState","value","loading","kind","spec","options","default_value","length","firstOptionValue","allow_multiple","Array","isArray","hydrateTemplateVariableStates","definitions","initialValues","state","forEach","v","name","param"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AAC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C;YAED,wEAAwE;YACxE,6EAA6E;YAC7E,4EAA4E;YAC5E,8EAA8E;YAC9E,QAAQ;YACR,IAAIE,KAAK,CAACC,OAAO,CAACX,QAAQ,CAACC,KAAK,CAAC,IAAID,QAAQ,CAACC,KAAK,CAACM,MAAM,KAAK,CAAC,IAAIP,QAAQ,CAACC,KAAK,CAAC,CAAC,CAAC,KAAKL,iBAAiB,EAAE;gBAC3GI,QAAQ,CAACC,KAAK,GAAGL,iBAAiB,CAAC;YACrC,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAOI,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,SAASY,6BAA6B,CAC3CC,WAAiC,EACjCC,aAA4C,EAC1B;IAClB,MAAMC,KAAK,GAAqB,EAAE,AAAC;IACnCF,WAAW,CAACG,OAAO,CAAC,CAACC,CAAC,GAAK;QACzB,MAAMC,IAAI,GAAGD,CAAC,CAACb,IAAI,CAACc,IAAI,AAAC;QACzB,MAAMC,KAAK,GAAGL,aAAa,CAACI,IAAI,CAAC,AAAC;QAClC,MAAMnB,YAAY,GAAGoB,KAAK,GAAGA,KAAK,GAAG,IAAI,AAAC;QAC1CJ,KAAK,CAACG,IAAI,CAAC,GAAGrB,4BAA4B,CAACoB,CAAC,EAAElB,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,OAAOgB,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,33 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { DashboardProvider } from '@perses-dev/dashboards';
15
+ import { EMPTY_DASHBOARD_RESOURCE } from './constants';
16
+ // Type guard because storybook types parameters as `any`
17
+ function isWithDashboardParameter(parameter) {
18
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
19
+ }
20
+ export const WithDashboard = (Story, context)=>{
21
+ const initParameter = context.parameters.withDashboard;
22
+ const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;
23
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
24
+ return /*#__PURE__*/ _jsx(DashboardProvider, {
25
+ initialState: {
26
+ dashboardResource: EMPTY_DASHBOARD_RESOURCE
27
+ },
28
+ ...props,
29
+ children: /*#__PURE__*/ _jsx(Story, {})
30
+ });
31
+ };
32
+
33
+ //# sourceMappingURL=WithDashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithDashboard.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { DashboardProvider, DashboardProviderProps } from '@perses-dev/dashboards';\nimport { EMPTY_DASHBOARD_RESOURCE } from './constants';\n\nexport type WithDashboardParameter = {\n props: Partial<DashboardProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDashboardParameter(parameter: unknown | WithDashboardParameter): parameter is WithDashboardParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithDashboard = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withDashboard;\n const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <DashboardProvider initialState={{ dashboardResource: EMPTY_DASHBOARD_RESOURCE }} {...props}>\n <Story />\n </DashboardProvider>\n );\n};\n"],"names":["DashboardProvider","EMPTY_DASHBOARD_RESOURCE","isWithDashboardParameter","parameter","WithDashboard","Story","context","initParameter","parameters","withDashboard","undefined","props","initialState","dashboardResource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,SAASA,iBAAiB,QAAgC,wBAAwB,CAAC;AACnF,SAASC,wBAAwB,QAAQ,aAAa,CAAC;AAMvD,yDAAyD;AACzD,SAASC,wBAAwB,CAACC,SAA2C,EAAuC;IAClH,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IAC/E,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,aAAa,AAAC;IACvD,MAAMN,SAAS,GAAGD,wBAAwB,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IACtF,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACX,iBAAiB;QAACY,YAAY,EAAE;YAAEC,iBAAiB,EAAEZ,wBAAwB;SAAE;QAAG,GAAGU,KAAK;kBACzF,cAAA,KAACN,KAAK,KAAG;MACS,CACpB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,76 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { DatasourceStoreProvider } from '@perses-dev/dashboards';
15
+ import { EMPTY_DASHBOARD_RESOURCE } from './constants';
16
+ // Type guard because storybook types parameters as `any`
17
+ function isWithDatasourceStoreParameter(parameter) {
18
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
19
+ }
20
+ const prometheusDemoUrl = 'https://prometheus.demo.do.prometheus.io';
21
+ const prometheusDemo = {
22
+ kind: 'GlobalDatasource',
23
+ metadata: {
24
+ name: 'PrometheusDemo',
25
+ created_at: '0001-01-01T00:00:00Z',
26
+ updated_at: '0001-01-01T00:00:00Z',
27
+ version: 0
28
+ },
29
+ spec: {
30
+ default: true,
31
+ plugin: {
32
+ kind: 'PrometheusDatasource',
33
+ spec: {
34
+ direct_url: prometheusDemoUrl
35
+ }
36
+ }
37
+ }
38
+ };
39
+ export const WithDatasourceStore = (Story, context)=>{
40
+ const initParameter = context.parameters.withDatasourceStore;
41
+ const parameter = isWithDatasourceStoreParameter(initParameter) ? initParameter : undefined;
42
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
43
+ // This default currently defines the bare minimum to get a story working in
44
+ // the `Dashboard` storybook with the Prometheus demo api. We'll likely want
45
+ // to expand it to do more in the future.
46
+ const defaultDatasourceProps = {
47
+ dashboardResource: EMPTY_DASHBOARD_RESOURCE,
48
+ datasourceApi: {
49
+ getDatasource: ()=>{
50
+ return Promise.resolve(undefined);
51
+ },
52
+ getGlobalDatasource: (selector)=>{
53
+ if (selector.kind === 'PrometheusDatasource') {
54
+ return Promise.resolve({
55
+ resource: prometheusDemo,
56
+ proxyUrl: prometheusDemoUrl
57
+ });
58
+ }
59
+ return Promise.resolve(undefined);
60
+ },
61
+ listDatasources: ()=>{
62
+ return Promise.resolve([]);
63
+ },
64
+ listGlobalDatasources: ()=>{
65
+ return Promise.resolve([]);
66
+ }
67
+ }
68
+ };
69
+ return /*#__PURE__*/ _jsx(DatasourceStoreProvider, {
70
+ ...defaultDatasourceProps,
71
+ ...props,
72
+ children: /*#__PURE__*/ _jsx(Story, {})
73
+ });
74
+ };
75
+
76
+ //# sourceMappingURL=WithDatasourceStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithDatasourceStore.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { DatasourceStoreProvider, DatasourceStoreProviderProps } from '@perses-dev/dashboards';\nimport { GlobalDatasource } from '@perses-dev/core';\nimport { EMPTY_DASHBOARD_RESOURCE } from './constants';\n\nexport type WithDatasourceStoreParameter = {\n props: Partial<DatasourceStoreProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDatasourceStoreParameter(\n parameter: unknown | WithDatasourceStoreParameter\n): parameter is WithDatasourceStoreParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nconst prometheusDemoUrl = 'https://prometheus.demo.do.prometheus.io';\nconst prometheusDemo: GlobalDatasource = {\n kind: 'GlobalDatasource',\n metadata: {\n name: 'PrometheusDemo',\n created_at: '0001-01-01T00:00:00Z',\n updated_at: '0001-01-01T00:00:00Z',\n version: 0,\n },\n spec: {\n default: true,\n plugin: {\n kind: 'PrometheusDatasource',\n spec: { direct_url: prometheusDemoUrl },\n },\n },\n} as const;\n\nexport const WithDatasourceStore = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withDatasourceStore;\n const parameter = isWithDatasourceStoreParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\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.\n const defaultDatasourceProps: Pick<DatasourceStoreProviderProps, 'datasourceApi' | 'dashboardResource'> = {\n dashboardResource: EMPTY_DASHBOARD_RESOURCE,\n datasourceApi: {\n getDatasource: () => {\n return Promise.resolve(undefined);\n },\n getGlobalDatasource: (selector) => {\n if (selector.kind === 'PrometheusDatasource') {\n return Promise.resolve({ resource: prometheusDemo, proxyUrl: prometheusDemoUrl });\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\n return (\n <DatasourceStoreProvider {...defaultDatasourceProps} {...props}>\n <Story />\n </DatasourceStoreProvider>\n );\n};\n"],"names":["DatasourceStoreProvider","EMPTY_DASHBOARD_RESOURCE","isWithDatasourceStoreParameter","parameter","prometheusDemoUrl","prometheusDemo","kind","metadata","name","created_at","updated_at","version","spec","default","plugin","direct_url","WithDatasourceStore","Story","context","initParameter","parameters","withDatasourceStore","undefined","props","defaultDatasourceProps","dashboardResource","datasourceApi","getDatasource","Promise","resolve","getGlobalDatasource","selector","resource","proxyUrl","listDatasources","listGlobalDatasources"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA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;gBACjC,IAAIA,QAAQ,CAACzB,IAAI,KAAK,sBAAsB,EAAE;oBAC5C,OAAOsB,OAAO,CAACC,OAAO,CAAC;wBAAEG,QAAQ,EAAE3B,cAAc;wBAAE4B,QAAQ,EAAE7B,iBAAiB;qBAAE,CAAC,CAAC;gBACpF,CAAC;gBAED,OAAOwB,OAAO,CAACC,OAAO,CAACP,SAAS,CAAC,CAAC;YACpC,CAAC;YACDY,eAAe,EAAE,IAAM;gBACrB,OAAON,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC7B,CAAC;YACDM,qBAAqB,EAAE,IAAM;gBAC3B,OAAOP,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC7B,CAAC;SACF;KACF,AAAC;IAEF,qBACE,KAAC7B,uBAAuB;QAAE,GAAGwB,sBAAsB;QAAG,GAAGD,KAAK;kBAC5D,cAAA,KAACN,KAAK,KAAG;MACe,CAC1B;AACJ,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { PluginRegistry, dynamicImportPluginLoader } from '@perses-dev/plugin-system';
15
+ // NOTE: the aliases we use for components break these top level imports, so we
16
+ // import relatively.
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
18
+ const prometheusResource = require('../../../../prometheus-plugin/plugin.json');
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ const panelsResource = require('../../../../panels-plugin/plugin.json');
21
+ const bundledPluginLoader = dynamicImportPluginLoader([
22
+ {
23
+ resource: prometheusResource,
24
+ // This throws an error in CI (but not locally for some reason), likely because
25
+ // this package isn't a dependency for dashboards. We probably do not want to
26
+ // make it one solely for type-checking in storybook.
27
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
+ // @ts-ignore
29
+ importPlugin: ()=>import('@perses-dev/prometheus-plugin')
30
+ },
31
+ {
32
+ resource: panelsResource,
33
+ // Same comment as above.
34
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
+ // @ts-ignore
36
+ importPlugin: ()=>import('@perses-dev/panels-plugin')
37
+ }
38
+ ]);
39
+ export const WithPluginRegistry = (Story)=>{
40
+ return /*#__PURE__*/ _jsx(PluginRegistry, {
41
+ pluginLoader: bundledPluginLoader,
42
+ children: /*#__PURE__*/ _jsx(Story, {})
43
+ });
44
+ };
45
+
46
+ //# sourceMappingURL=WithPluginRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithPluginRegistry.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn } from '@storybook/react';\nimport {\n PluginRegistry,\n PluginLoader,\n PluginModuleResource,\n dynamicImportPluginLoader,\n} from '@perses-dev/plugin-system';\n\n// NOTE: the aliases we use for components break these top level imports, so we\n// import relatively.\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst prometheusResource = require('../../../../prometheus-plugin/plugin.json');\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst panelsResource = require('../../../../panels-plugin/plugin.json');\n\nconst bundledPluginLoader: PluginLoader = dynamicImportPluginLoader([\n {\n resource: prometheusResource as PluginModuleResource,\n // This throws an error in CI (but not locally for some reason), likely because\n // this package isn't a dependency for dashboards. We probably do not want to\n // make it one solely for type-checking in storybook.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/prometheus-plugin'),\n },\n {\n resource: panelsResource as PluginModuleResource,\n // Same comment as above.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n importPlugin: () => import('@perses-dev/panels-plugin'),\n },\n]);\n\nexport const WithPluginRegistry = (Story: StoryFn) => {\n return (\n <PluginRegistry pluginLoader={bundledPluginLoader}>\n <Story />\n </PluginRegistry>\n );\n};\n"],"names":["PluginRegistry","dynamicImportPluginLoader","prometheusResource","require","panelsResource","bundledPluginLoader","resource","importPlugin","WithPluginRegistry","Story","pluginLoader"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,SACEA,cAAc,EAGdC,yBAAyB,QACpB,2BAA2B,CAAC;AAEnC,+EAA+E;AAC/E,qBAAqB;AACrB,8DAA8D;AAC9D,MAAMC,kBAAkB,GAAGC,OAAO,CAAC,2CAA2C,CAAC,AAAC;AAChF,8DAA8D;AAC9D,MAAMC,cAAc,GAAGD,OAAO,CAAC,uCAAuC,CAAC,AAAC;AAExE,MAAME,mBAAmB,GAAiBJ,yBAAyB,CAAC;IAClE;QACEK,QAAQ,EAAEJ,kBAAkB;QAC5B,+EAA+E;QAC/E,6EAA6E;QAC7E,qDAAqD;QACrD,6DAA6D;QAC7D,aAAa;QACbK,YAAY,EAAE,IAAM,MAAM,CAAC,+BAA+B,CAAC;KAC5D;IACD;QACED,QAAQ,EAAEF,cAAc;QACxB,yBAAyB;QACzB,6DAA6D;QAC7D,aAAa;QACbG,YAAY,EAAE,IAAM,MAAM,CAAC,2BAA2B,CAAC;KACxD;CACF,CAAC,AAAC;AAEH,OAAO,MAAMC,kBAAkB,GAAG,CAACC,KAAc,GAAK;IACpD,qBACE,KAACT,cAAc;QAACU,YAAY,EAAEL,mBAAmB;kBAC/C,cAAA,KAACI,KAAK,KAAG;MACM,CACjB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
15
+ export const WithQueryClient = (Story)=>{
16
+ const queryClient = new QueryClient({});
17
+ return /*#__PURE__*/ _jsx(QueryClientProvider, {
18
+ client: queryClient,
19
+ children: /*#__PURE__*/ _jsx(Story, {})
20
+ });
21
+ };
22
+
23
+ //# sourceMappingURL=WithQueryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithQueryClient.tsx"],"sourcesContent":["// Copyright 2023 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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { StoryFn } from '@storybook/react';\n\nexport const WithQueryClient = (Story: StoryFn) => {\n const queryClient = new QueryClient({});\n\n return (\n <QueryClientProvider client={queryClient}>\n <Story />\n </QueryClientProvider>\n );\n};\n"],"names":["QueryClient","QueryClientProvider","WithQueryClient","Story","queryClient","client"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB,CAAC;AAGzE,OAAO,MAAMC,eAAe,GAAG,CAACC,KAAc,GAAK;IACjD,MAAMC,WAAW,GAAG,IAAIJ,WAAW,CAAC,EAAE,CAAC,AAAC;IAExC,qBACE,KAACC,mBAAmB;QAACI,MAAM,EAAED,WAAW;kBACtC,cAAA,KAACD,KAAK,KAAG;MACW,CACtB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { WindowHistoryAdapter } from 'use-query-params/adapters/window';
15
+ import { QueryParamProvider } from 'use-query-params';
16
+ export const WithQueryParams = (Story)=>{
17
+ return /*#__PURE__*/ _jsx(QueryParamProvider, {
18
+ adapter: WindowHistoryAdapter,
19
+ children: /*#__PURE__*/ _jsx(Story, {})
20
+ });
21
+ };
22
+
23
+ //# sourceMappingURL=WithQueryParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithQueryParams.tsx"],"sourcesContent":["// Copyright 2023 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 { WindowHistoryAdapter } from 'use-query-params/adapters/window';\nimport { QueryParamProvider } from 'use-query-params';\nimport { StoryFn } from '@storybook/react';\n\nexport const WithQueryParams = (Story: StoryFn) => {\n return (\n <QueryParamProvider adapter={WindowHistoryAdapter}>\n <Story />\n </QueryParamProvider>\n );\n};\n"],"names":["WindowHistoryAdapter","QueryParamProvider","WithQueryParams","Story","adapter"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,oBAAoB,QAAQ,kCAAkC,CAAC;AACxE,SAASC,kBAAkB,QAAQ,kBAAkB,CAAC;AAGtD,OAAO,MAAMC,eAAe,GAAG,CAACC,KAAc,GAAK;IACjD,qBACE,KAACF,kBAAkB;QAACG,OAAO,EAAEJ,oBAAoB;kBAC/C,cAAA,KAACG,KAAK,KAAG;MACU,CACrB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { TemplateVariableProvider } from '@perses-dev/dashboards';
15
+ // Type guard because storybook types parameters as `any`
16
+ function isWithTemplateVariableParameter(parameter) {
17
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
18
+ }
19
+ export const WithTemplateVariables = (Story, context)=>{
20
+ const initParameter = context.parameters.withTemplateVariables;
21
+ const parameter = isWithTemplateVariableParameter(initParameter) ? initParameter : undefined;
22
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
23
+ return /*#__PURE__*/ _jsx(TemplateVariableProvider, {
24
+ ...props,
25
+ children: /*#__PURE__*/ _jsx(Story, {})
26
+ });
27
+ };
28
+
29
+ //# sourceMappingURL=WithTemplateVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithTemplateVariables.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { TemplateVariableProvider, TemplateVariableProviderProps } from '@perses-dev/dashboards';\n\nexport type WithTemplateVariableParameter = {\n props: Partial<TemplateVariableProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithTemplateVariableParameter(\n parameter: unknown | WithTemplateVariableParameter\n): parameter is WithTemplateVariableParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithTemplateVariables = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withTemplateVariables;\n const parameter = isWithTemplateVariableParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <TemplateVariableProvider {...props}>\n <Story />\n </TemplateVariableProvider>\n );\n};\n"],"names":["TemplateVariableProvider","isWithTemplateVariableParameter","parameter","WithTemplateVariables","Story","context","initParameter","parameters","withTemplateVariables","undefined","props"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,SAASA,wBAAwB,QAAuC,wBAAwB,CAAC;AAMjG,yDAAyD;AACzD,SAASC,+BAA+B,CACtCC,SAAkD,EACN;IAC5C,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IACvF,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,qBAAqB,AAAC;IAC/D,MAAMN,SAAS,GAAGD,+BAA+B,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IAC7F,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACV,wBAAwB;QAAE,GAAGU,KAAK;kBACjC,cAAA,KAACN,KAAK,KAAG;MACgB,CAC3B;AACJ,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { TimeRangeProvider } from '@perses-dev/plugin-system';
15
+ // Type guard because storybook types parameters as `any`
16
+ function isWithTimeRangeParameter(parameter) {
17
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
18
+ }
19
+ export const WithTimeRange = (Story, context)=>{
20
+ const initParameter = context.parameters.withTimeRange;
21
+ const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;
22
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
23
+ return /*#__PURE__*/ _jsx(TimeRangeProvider, {
24
+ initialTimeRange: {
25
+ pastDuration: '1h'
26
+ },
27
+ ...props,
28
+ children: /*#__PURE__*/ _jsx(Story, {})
29
+ });
30
+ };
31
+
32
+ //# sourceMappingURL=WithTimeRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/WithTimeRange.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { TimeRangeProvider, TimeRangeProviderProps } from '@perses-dev/plugin-system';\n\nexport type WithTimeRangeParameter = {\n props: Partial<TimeRangeProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithTimeRangeParameter(parameter: unknown | WithTimeRangeParameter): parameter is WithTimeRangeParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithTimeRange = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withTimeRange;\n const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <TimeRangeProvider initialTimeRange={{ pastDuration: '1h' }} {...props}>\n <Story />\n </TimeRangeProvider>\n );\n};\n"],"names":["TimeRangeProvider","isWithTimeRangeParameter","parameter","WithTimeRange","Story","context","initParameter","parameters","withTimeRange","undefined","props","initialTimeRange","pastDuration"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,SAASA,iBAAiB,QAAgC,2BAA2B,CAAC;AAMtF,yDAAyD;AACzD,SAASC,wBAAwB,CAACC,SAA2C,EAAuC;IAClH,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IAC/E,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,aAAa,AAAC;IACvD,MAAMN,SAAS,GAAGD,wBAAwB,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IACtF,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACV,iBAAiB;QAACW,gBAAgB,EAAE;YAAEC,YAAY,EAAE,IAAI;SAAE;QAAG,GAAGF,KAAK;kBACpE,cAAA,KAACN,KAAK,KAAG;MACS,CACpB;AACJ,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export const EMPTY_DASHBOARD_RESOURCE = {
14
+ kind: 'Dashboard',
15
+ metadata: {
16
+ name: 'My Dashboard',
17
+ project: 'Storybook',
18
+ created_at: '2021-11-09T00:00:00Z',
19
+ updated_at: '2021-11-09T00:00:00Z',
20
+ version: 0
21
+ },
22
+ spec: {
23
+ duration: '1h',
24
+ variables: [],
25
+ layouts: [],
26
+ panels: {}
27
+ }
28
+ };
29
+
30
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/stories/decorators/constants.ts"],"sourcesContent":["// Copyright 2023 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 { DashboardResource } from '@perses-dev/core';\n\nexport const EMPTY_DASHBOARD_RESOURCE: DashboardResource = {\n kind: 'Dashboard',\n metadata: {\n name: 'My Dashboard',\n project: 'Storybook',\n created_at: '2021-11-09T00:00:00Z',\n updated_at: '2021-11-09T00:00:00Z',\n version: 0,\n },\n spec: {\n duration: '1h',\n variables: [],\n layouts: [],\n panels: {},\n },\n};\n"],"names":["EMPTY_DASHBOARD_RESOURCE","kind","metadata","name","project","created_at","updated_at","version","spec","duration","variables","layouts","panels"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,wBAAwB,GAAsB;IACzDC,IAAI,EAAE,WAAW;IACjBC,QAAQ,EAAE;QACRC,IAAI,EAAE,cAAc;QACpBC,OAAO,EAAE,WAAW;QACpBC,UAAU,EAAE,sBAAsB;QAClCC,UAAU,EAAE,sBAAsB;QAClCC,OAAO,EAAE,CAAC;KACX;IACDC,IAAI,EAAE;QACJC,QAAQ,EAAE,IAAI;QACdC,SAAS,EAAE,EAAE;QACbC,OAAO,EAAE,EAAE;QACXC,MAAM,EAAE,EAAE;KACX;CACF,CAAC"}
@@ -0,0 +1,22 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './constants';
14
+ export * from './WithDashboard';
15
+ export * from './WithDatasourceStore';
16
+ export * from './WithPluginRegistry';
17
+ export * from './WithQueryClient';
18
+ export * from './WithQueryParams';
19
+ export * from './WithTemplateVariables';
20
+ export * from './WithTimeRange';
21
+
22
+ //# sourceMappingURL=index.js.map