@perses-dev/dashboards 0.0.0-snapshot-scatterplot-fix-imports-95e1b59 → 0.0.0-snapshot-explorer-plugin-c4a7621
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.
- package/dist/cjs/components/Dashboard/Dashboard.js +8 -1
- package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
- package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +1 -1
- package/dist/cjs/components/Datasources/DatasourceEditor.js +18 -18
- package/dist/cjs/components/Datasources/EditDatasourcesButton.js +2 -5
- package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +3 -4
- package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +10 -13
- package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +2 -2
- package/dist/cjs/components/GridLayout/GridContainer.js +15 -10
- package/dist/cjs/components/GridLayout/GridItemContent.js +19 -4
- package/dist/cjs/components/GridLayout/GridLayout.js +61 -12
- package/dist/cjs/components/GridLayout/GridTitle.js +3 -3
- package/dist/cjs/{validation/panel.js → components/Panel/HeaderIconButton.js} +8 -10
- package/dist/cjs/components/Panel/Panel.js +14 -10
- package/dist/cjs/components/Panel/PanelActions.js +216 -0
- package/dist/cjs/components/Panel/PanelContent.js +4 -4
- package/dist/cjs/components/Panel/PanelHeader.js +36 -103
- package/dist/cjs/components/Panel/PanelLinks.js +136 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +9 -6
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +67 -65
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +7 -3
- package/dist/cjs/components/PanelDrawer/usePanelEditor.js +9 -6
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
- package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +3 -5
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +4 -6
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +2 -2
- package/dist/cjs/components/Variables/BuiltinVariableAccordions.js +7 -14
- package/dist/cjs/components/Variables/EditVariablesButton.js +4 -4
- package/dist/cjs/components/Variables/{TemplateVariable.js → Variable.js} +43 -60
- package/dist/cjs/components/Variables/VariableEditor.js +34 -40
- package/dist/cjs/components/Variables/VariableList.js +23 -22
- package/dist/cjs/components/Variables/index.js +2 -2
- package/dist/cjs/constants/styles.js +15 -7
- package/dist/cjs/constants/user-interface-text.js +3 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +10 -8
- package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +36 -0
- package/dist/cjs/context/DashboardProvider/common.js +2 -2
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +14 -6
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +1 -2
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +7 -10
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +1 -2
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +8 -3
- package/dist/cjs/context/DashboardProvider/view-panel-slice.js +79 -0
- package/dist/cjs/context/DatasourceStoreProvider.js +18 -23
- package/dist/cjs/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +62 -69
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +11 -14
- package/dist/cjs/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/utils.js +3 -3
- package/dist/cjs/context/index.js +2 -2
- package/dist/cjs/context/useDashboard.js +4 -4
- package/dist/cjs/stories/decorators/WithDashboard.js +1 -1
- package/dist/cjs/stories/decorators/WithDatasourceStore.js +1 -1
- package/dist/cjs/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +9 -9
- package/dist/cjs/stories/decorators/index.js +2 -2
- package/dist/cjs/test/plugin-registry.js +4 -2
- package/dist/cjs/test/render.js +13 -11
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +3 -3
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +7 -8
- package/dist/components/AddGroupButton/AddGroupButton.d.ts +2 -1
- package/dist/components/AddGroupButton/AddGroupButton.d.ts.map +1 -1
- package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
- package/dist/components/AddPanelButton/AddPanelButton.d.ts +2 -1
- package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
- package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
- package/dist/components/Dashboard/Dashboard.d.ts +2 -1
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard/Dashboard.js +8 -1
- package/dist/components/Dashboard/Dashboard.js.map +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts +2 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +3 -3
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts +2 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.js +19 -19
- package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
- package/dist/components/Datasources/EditDatasourcesButton.d.ts +2 -1
- package/dist/components/Datasources/EditDatasourcesButton.d.ts.map +1 -1
- package/dist/components/Datasources/EditDatasourcesButton.js +2 -5
- package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +2 -1
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts +2 -1
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +3 -4
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +2 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/components/DownloadButton/DownloadButton.d.ts +2 -1
- package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -1
- package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
- package/dist/components/EditButton/EditButton.d.ts +2 -1
- package/dist/components/EditButton/EditButton.d.ts.map +1 -1
- package/dist/components/EditButton/EditButton.js.map +1 -1
- package/dist/components/EditJsonButton/EditJsonButton.d.ts +2 -1
- package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -1
- package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +2 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
- package/dist/components/EditJsonDialog/EditJsonDialog.js +7 -10
- package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +3 -3
- package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js +2 -2
- package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
- package/dist/components/GridLayout/GridContainer.d.ts +5 -3
- package/dist/components/GridLayout/GridContainer.d.ts.map +1 -1
- package/dist/components/GridLayout/GridContainer.js +15 -10
- package/dist/components/GridLayout/GridContainer.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -1
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +21 -6
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +4 -2
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +63 -14
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +3 -2
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +3 -3
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/HeaderIconButton.d.ts +5 -0
- package/dist/components/Panel/HeaderIconButton.d.ts.map +1 -0
- package/dist/{context/TemplateVariableProvider/index.js → components/Panel/HeaderIconButton.js} +7 -3
- package/dist/components/Panel/HeaderIconButton.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts +11 -5
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +15 -11
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelActions.d.ts +16 -0
- package/dist/components/Panel/PanelActions.d.ts.map +1 -0
- package/dist/components/Panel/PanelActions.js +203 -0
- package/dist/components/Panel/PanelActions.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +2 -1
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +4 -4
- package/dist/components/Panel/PanelContent.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +8 -8
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +39 -106
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/Panel/PanelLinks.d.ts +6 -0
- package/dist/components/Panel/PanelLinks.d.ts.map +1 -0
- package/dist/components/Panel/PanelLinks.js +123 -0
- package/dist/components/Panel/PanelLinks.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +2 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +10 -7
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +70 -68
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +3 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +8 -4
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelDrawer/usePanelEditor.d.ts +12 -10
- package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -1
- package/dist/components/PanelDrawer/usePanelEditor.js +9 -6
- package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +2 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +2 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
- package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +2 -1
- package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -1
- package/dist/components/QuerySummaryTable/QuerySummaryTable.js +3 -5
- package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +2 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +5 -7
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +2 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +3 -3
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/BuiltinVariableAccordions.d.ts +2 -1
- package/dist/components/Variables/BuiltinVariableAccordions.d.ts.map +1 -1
- package/dist/components/Variables/BuiltinVariableAccordions.js +7 -14
- package/dist/components/Variables/BuiltinVariableAccordions.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.d.ts +2 -1
- package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js +5 -5
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/{TemplateVariable.d.ts → Variable.d.ts} +6 -5
- package/dist/components/Variables/Variable.d.ts.map +1 -0
- package/dist/components/Variables/{TemplateVariable.js → Variable.js} +44 -61
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableEditor.d.ts +3 -2
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +35 -41
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts +4 -3
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +21 -20
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -1
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +2 -2
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/constants/styles.d.ts +4 -2
- package/dist/constants/styles.d.ts.map +1 -1
- package/dist/constants/styles.js +5 -3
- package/dist/constants/styles.js.map +1 -1
- package/dist/constants/user-interface-text.d.ts +3 -0
- package/dist/constants/user-interface-text.d.ts.map +1 -1
- package/dist/constants/user-interface-text.js +3 -0
- package/dist/constants/user-interface-text.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +6 -3
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +11 -9
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts +4 -0
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts.map +1 -0
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +28 -0
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +2 -2
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +36 -23
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +13 -6
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js +1 -2
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/discard-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -2
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -9
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +4 -7
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +1 -2
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +2 -2
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +7 -3
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts +21 -0
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/view-panel-slice.js +73 -0
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +7 -7
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +18 -23
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.d.ts +119 -0
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +51 -54
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.d.ts +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +9 -12
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -0
- package/dist/context/VariableProvider/index.d.ts +2 -0
- package/dist/context/VariableProvider/index.d.ts.map +1 -0
- package/dist/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/context/VariableProvider/index.js.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.d.ts +2 -6
- package/dist/context/VariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/context/VariableProvider/query-params.js.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.d.ts +1 -1
- package/dist/context/VariableProvider/utils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.js +3 -3
- package/dist/context/VariableProvider/utils.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +4 -4
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/stories/decorators/WithDashboard.js +1 -1
- package/dist/stories/decorators/WithDashboard.js.map +1 -1
- package/dist/stories/decorators/WithDatasourceStore.js +1 -1
- package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
- package/dist/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +9 -9
- package/dist/stories/decorators/WithVariables.js.map +1 -0
- package/dist/stories/decorators/index.js +2 -2
- package/dist/stories/decorators/index.js.map +1 -1
- package/dist/test/dashboard-provider.d.ts +1 -1
- package/dist/test/dashboard-provider.d.ts.map +1 -1
- package/dist/test/dashboard-provider.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +2 -2
- package/dist/test/datasource-provider.d.ts.map +1 -1
- package/dist/test/datasource-provider.js.map +1 -1
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +4 -2
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/render.d.ts +2 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +9 -7
- package/dist/test/render.js.map +1 -1
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -2
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +3 -3
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +4 -3
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +8 -9
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +9 -9
- package/dist/cjs/context/TemplateVariableProvider/index.js +0 -30
- package/dist/components/Variables/TemplateVariable.d.ts.map +0 -1
- package/dist/components/Variables/TemplateVariable.js.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +0 -77
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +0 -1
- package/dist/context/TemplateVariableProvider/index.d.ts +0 -2
- package/dist/context/TemplateVariableProvider/index.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/index.js.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.js.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.js.map +0 -1
- package/dist/stories/decorators/WithTemplateVariables.js.map +0 -1
- package/dist/validation/index.d.ts +0 -2
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/panel.d.ts +0 -19
- package/dist/validation/panel.d.ts.map +0 -1
- package/dist/validation/panel.js +0 -21
- package/dist/validation/panel.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { DashboardResource,
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { DashboardResource, DatasourceResource, DatasourceSelector, DatasourceSpec, GlobalDatasourceResource, EphemeralDashboardResource } from '@perses-dev/core';
|
|
3
3
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
4
4
|
export interface DatasourceStoreProviderProps {
|
|
5
5
|
dashboardResource?: DashboardResource | EphemeralDashboardResource;
|
|
@@ -20,13 +20,13 @@ export type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) =>
|
|
|
20
20
|
*/
|
|
21
21
|
export interface DatasourceApi {
|
|
22
22
|
buildProxyUrl?: BuildDatasourceProxyUrlFunc;
|
|
23
|
-
getDatasource: (project: string, selector: DatasourceSelector) => Promise<
|
|
24
|
-
getGlobalDatasource: (selector: DatasourceSelector) => Promise<
|
|
25
|
-
listDatasources: (project: string, pluginKind?: string) => Promise<
|
|
26
|
-
listGlobalDatasources: (pluginKind?: string) => Promise<
|
|
23
|
+
getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;
|
|
24
|
+
getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;
|
|
25
|
+
listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;
|
|
26
|
+
listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
30
30
|
*/
|
|
31
|
-
export declare function DatasourceStoreProvider(props: DatasourceStoreProviderProps):
|
|
31
|
+
export declare function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement;
|
|
32
32
|
//# sourceMappingURL=DatasourceStoreProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAChF,OAAO,EACL,iBAAiB,EAEjB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,wBAAwB,EAExB,0BAA0B,EAE3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,0BAA0B,CAAC;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CAC3D;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,EAAE,6BAA6B,KAAK,MAAM,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,2BAA2B,CAAC;IAC5C,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;IAC1G,mBAAmB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAC;IACrG,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACzF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACrF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,GAAG,YAAY,CAyLzF"}
|
|
@@ -19,9 +19,8 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
19
19
|
*/ export function DatasourceStoreProvider(props) {
|
|
20
20
|
const { projectName, datasourceApi, onCreate, children } = props;
|
|
21
21
|
const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const project = projectName !== null && projectName !== void 0 ? projectName : dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.metadata.project;
|
|
22
|
+
const [savedDatasources, setSavedDatasources] = useState(props.savedDatasources ?? {});
|
|
23
|
+
const project = projectName ?? dashboardResource?.metadata.project;
|
|
25
24
|
const { getPlugin, listPluginMetadata } = usePluginRegistry();
|
|
26
25
|
const findDatasource = useEvent(async (selector)=>{
|
|
27
26
|
// Try to find it in dashboard spec
|
|
@@ -91,24 +90,26 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
91
90
|
getPlugin,
|
|
92
91
|
onCreate
|
|
93
92
|
]);
|
|
94
|
-
const listDatasourceSelectItems = useEvent(async (
|
|
93
|
+
const listDatasourceSelectItems = useEvent(async (datasourcePluginName)=>{
|
|
95
94
|
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
96
|
-
listPluginMetadata(
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
listPluginMetadata([
|
|
96
|
+
'Datasource'
|
|
97
|
+
]),
|
|
98
|
+
project ? datasourceApi.listDatasources(project, datasourcePluginName) : [],
|
|
99
|
+
datasourceApi.listGlobalDatasources(datasourcePluginName)
|
|
99
100
|
]);
|
|
100
101
|
// Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource
|
|
101
|
-
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.
|
|
102
|
+
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.spec.name === datasourcePluginName);
|
|
102
103
|
if (datasourcePluginMetadata === undefined) {
|
|
103
|
-
throw new Error(`Could not find a Datasource plugin with kind '${
|
|
104
|
+
throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);
|
|
104
105
|
}
|
|
105
106
|
// Get helper for computing results properly
|
|
106
|
-
const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);
|
|
107
|
+
const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);
|
|
107
108
|
// Start with dashboard datasources with the highest precedence
|
|
108
|
-
if (dashboardResource
|
|
109
|
+
if (dashboardResource?.spec.datasources) {
|
|
109
110
|
for(const selectorName in dashboardResource.spec.datasources){
|
|
110
111
|
const spec = dashboardResource.spec.datasources[selectorName];
|
|
111
|
-
if (spec === undefined || spec.plugin.kind !==
|
|
112
|
+
if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;
|
|
112
113
|
const saved = selectorName in savedDatasources;
|
|
113
114
|
addItem({
|
|
114
115
|
spec,
|
|
@@ -141,8 +142,7 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
141
142
|
return results;
|
|
142
143
|
});
|
|
143
144
|
const getLocalDatasources = useCallback(()=>{
|
|
144
|
-
|
|
145
|
-
return (_dashboardResource_spec_datasources = dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) !== null && _dashboardResource_spec_datasources !== void 0 ? _dashboardResource_spec_datasources : {};
|
|
145
|
+
return dashboardResource?.spec.datasources ?? {};
|
|
146
146
|
}, [
|
|
147
147
|
dashboardResource
|
|
148
148
|
]);
|
|
@@ -228,8 +228,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
228
228
|
const groupIndices = {};
|
|
229
229
|
let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.
|
|
230
230
|
const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved })=>{
|
|
231
|
-
|
|
232
|
-
group = group !== null && group !== void 0 ? group : '';
|
|
231
|
+
group = group ?? '';
|
|
233
232
|
// Ensure the default group is always present as soon as an item is added.
|
|
234
233
|
if (isFirst) {
|
|
235
234
|
results.push({
|
|
@@ -237,9 +236,8 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
237
236
|
items: []
|
|
238
237
|
});
|
|
239
238
|
}
|
|
240
|
-
var _groupIndices_group;
|
|
241
239
|
// Create the group if necessary
|
|
242
|
-
let selectItemGroup = results[
|
|
240
|
+
let selectItemGroup = results[groupIndices[group] ?? -1];
|
|
243
241
|
if (!selectItemGroup) {
|
|
244
242
|
groupIndices[group] = currentGroupIndex;
|
|
245
243
|
selectItemGroup = {
|
|
@@ -252,9 +250,8 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
252
250
|
}
|
|
253
251
|
// Add item to the group
|
|
254
252
|
const isOverridden = usedNames.has(selectorName);
|
|
255
|
-
var _spec_display_name;
|
|
256
253
|
selectItemGroup.items.push({
|
|
257
|
-
name:
|
|
254
|
+
name: spec.display?.name ?? selectorName,
|
|
258
255
|
overridden: isOverridden,
|
|
259
256
|
saved,
|
|
260
257
|
selector: {
|
|
@@ -283,9 +280,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
283
280
|
// At the end, we make sure the overriding item(s) is well flagged so
|
|
284
281
|
if (isOverridden) {
|
|
285
282
|
for(let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++){
|
|
286
|
-
|
|
287
|
-
var _results_i_items;
|
|
288
|
-
((_results_i_items = (_results_i = results[i]) === null || _results_i === void 0 ? void 0 : _results_i.items) !== null && _results_i_items !== void 0 ? _results_i_items : []).filter((item)=>item.selector.name === selectorName).forEach((item)=>{
|
|
283
|
+
(results[i]?.items ?? []).filter((item)=>item.selector.name === selectorName).forEach((item)=>{
|
|
289
284
|
item.overriding = true;
|
|
290
285
|
});
|
|
291
286
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n ProjectDatasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"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,SAAoBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClE,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AAkCnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGJ;IAC3D,MAAM,CAACK,mBAAmBC,qBAAqB,GAAGX,SAASK,MAAMK,iBAAiB;QAEhFL;IADF,MAAM,CAACO,kBAAkBC,oBAAoB,GAAGb,SAC9CK,CAAAA,0BAAAA,MAAMO,gBAAgB,cAAtBP,qCAAAA,0BAA0B,CAAC;IAE7B,MAAMS,UAAUR,wBAAAA,yBAAAA,cAAeI,8BAAAA,wCAAAA,kBAAmBK,QAAQ,CAACD,OAAO;IAElE,MAAM,EAAEE,SAAS,EAAEC,kBAAkB,EAAE,GAAGd;IAE1C,MAAMe,iBAAiBjB,SAAS,OAAOkB;QACrC,mCAAmC;QACnC,IAAIT,mBAAmB;YACrB,MAAM,EAAEU,WAAW,EAAE,GAAGV,kBAAkBW,IAAI;YAC9C,MAAMC,sBAAsBC,wBAAwBH,aAAaD;YACjE,IAAIG,wBAAwBE,WAAW;gBACrC,OAAO;oBACLH,MAAMC,oBAAoBD,IAAI;oBAC9BI,UAAUC,wBAAwBnB,eAAe;wBAC/CO,SAASJ,kBAAk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CAAAA,WAAYiC,KAAK,cAAjBjC,8BAAAA,mBAAqB,EAAE,AAAD,EACpByC,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
|
|
1
|
+
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactElement, ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n DatasourceResource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasourceResource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;\n listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginName) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginName),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.spec.name === datasourcePluginName);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({\n spec,\n selectorName,\n selectorGroup: group,\n editLink,\n saved,\n }: AddDatasouceSelectItemParams): void => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginName","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF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gBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;gBACtBN,MAAM0B;gBACN2B;YACF;QACF;QACAN,UAAUa,GAAG,CAAClC;QAEd,MAAMmC,oBAAoB,CAACJ,gBAAgBhE,KAAKoD,OAAO,IAAI,CAACK;QAC5D,IAAI5B,OAAO,CAAC,EAAE,IAAK2B,CAAAA,WAAWY,iBAAgB,GAAI;YAChD,8GAA8G;YAC9GvC,OAAO,CAAC,EAAE,CAACiC,KAAK,GAAG;gBACjB;oBACEvD,MAAM,CAAC,SAAS,EAAE0B,aAAa,MAAM,EAAE2B,MAAM,CAAC,CAAC;oBAC/C9D,UAAU;wBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD4C,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;gBACpExC,CAAAA,OAAO,CAACwC,EAAE,EAAEP,SAAS,EAAE,AAAD,EACpBQ,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { StoreApi } from 'zustand';
|
|
3
|
+
import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system';
|
|
4
|
+
import { VariableName, VariableValue, VariableDefinition, BuiltinVariableDefinition, TextVariableDefinition, ListVariableDefinition } from '@perses-dev/core';
|
|
5
|
+
/**
|
|
6
|
+
* This store is used to manipulate and read the definition of the variables and their state.
|
|
7
|
+
* - being local or external variables.
|
|
8
|
+
* - being text or list variables.
|
|
9
|
+
* - being of any state (value, options, loading, error, ...) check {@VariableState}
|
|
10
|
+
* Go and read each property documentation for more details.
|
|
11
|
+
*/
|
|
12
|
+
type VariableDefinitionStore = {
|
|
13
|
+
/**
|
|
14
|
+
* List of local variables definitions.
|
|
15
|
+
* This is typically the variable definition that can be modified through the setVariableDefinition setter.
|
|
16
|
+
*
|
|
17
|
+
* In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local.
|
|
18
|
+
* Note that depending on the form, we can reuse this store to modify higher scope variables. For example,
|
|
19
|
+
* when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify
|
|
20
|
+
* them.
|
|
21
|
+
*/
|
|
22
|
+
variableDefinitions: VariableDefinition[];
|
|
23
|
+
/**
|
|
24
|
+
* List of external variable definitions.
|
|
25
|
+
* This is static variable definitions that won´t be modified under this context.
|
|
26
|
+
* You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for
|
|
27
|
+
* more details.
|
|
28
|
+
*
|
|
29
|
+
* In Perses App ecosystem, this is typically the project or global scope variables.
|
|
30
|
+
* Note that depending on the form, we can reuse this store to modify higher scope variables. For example,
|
|
31
|
+
* when we modify the variable of a project, we'll set this field with global scope variables. Which means we
|
|
32
|
+
* won't be able to modify them from this form.
|
|
33
|
+
*/
|
|
34
|
+
externalVariableDefinitions: ExternalVariableDefinition[];
|
|
35
|
+
/**
|
|
36
|
+
* Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for.
|
|
37
|
+
* This can be heavily modified under this context, using the different setters available.
|
|
38
|
+
* Note that the state of local AND external variables can be modified.
|
|
39
|
+
*/
|
|
40
|
+
variableState: VariableStoreStateMap;
|
|
41
|
+
/**
|
|
42
|
+
* Allow to modify the `value` property of a variable in the state map.
|
|
43
|
+
* @param variableName identify the variable
|
|
44
|
+
* @param value new value
|
|
45
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
46
|
+
*/
|
|
47
|
+
setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Allow to modify the `options` property of a variable in the state map.
|
|
50
|
+
* @param variableName identify the variable
|
|
51
|
+
* @param options new value
|
|
52
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
53
|
+
*/
|
|
54
|
+
setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Allow to modify the `loading` property of a variable in the state map.
|
|
57
|
+
* @param variableName identify the variable
|
|
58
|
+
* @param laoding new value
|
|
59
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
60
|
+
*/
|
|
61
|
+
setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;
|
|
62
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
63
|
+
setVariableDefaultValues: () => VariableDefinition[];
|
|
64
|
+
getSavedVariablesStatus: () => {
|
|
65
|
+
isSavedVariableModified: boolean;
|
|
66
|
+
modifiedVariableNames: string[];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export declare function useVariableDefinitionStoreCtx(): StoreApi<VariableDefinitionStore>;
|
|
70
|
+
export declare function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap;
|
|
71
|
+
/**
|
|
72
|
+
* Get the state and definition of a variable from the variables context.
|
|
73
|
+
* @param name name of the variable
|
|
74
|
+
* @param source if given, it searches in the external variables
|
|
75
|
+
*/
|
|
76
|
+
export declare function useVariableDefinitionAndState(name: string, source?: string): {
|
|
77
|
+
definition: TextVariableDefinition | ListVariableDefinition | undefined;
|
|
78
|
+
state: VariableState | undefined;
|
|
79
|
+
};
|
|
80
|
+
export declare function useVariableDefinitionActions(): {
|
|
81
|
+
setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;
|
|
82
|
+
getSavedVariablesStatus: () => {
|
|
83
|
+
isSavedVariableModified: boolean;
|
|
84
|
+
modifiedVariableNames: string[];
|
|
85
|
+
};
|
|
86
|
+
setVariableDefaultValues: () => VariableDefinition[];
|
|
87
|
+
setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;
|
|
88
|
+
setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;
|
|
89
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
90
|
+
};
|
|
91
|
+
export declare function useVariableDefinitions(): VariableDefinition[];
|
|
92
|
+
export declare function useExternalVariableDefinitions(): ExternalVariableDefinition[];
|
|
93
|
+
/**
|
|
94
|
+
* The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.
|
|
95
|
+
* 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
|
|
96
|
+
* to modify their runtime value as any other variable.
|
|
97
|
+
* If one of the external variable has the same name as a local one, it will be marked as overridden.
|
|
98
|
+
* You can define one list of variable definition by source and as many source as you want.
|
|
99
|
+
* The order of the sources is important as first one will take precedence on the following ones, in case they have same names.
|
|
100
|
+
*/
|
|
101
|
+
export type ExternalVariableDefinition = {
|
|
102
|
+
source: string;
|
|
103
|
+
tooltip?: {
|
|
104
|
+
title?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
};
|
|
107
|
+
editLink?: string;
|
|
108
|
+
definitions: VariableDefinition[];
|
|
109
|
+
};
|
|
110
|
+
export interface VariableProviderProps {
|
|
111
|
+
children: ReactNode;
|
|
112
|
+
initialVariableDefinitions?: VariableDefinition[];
|
|
113
|
+
externalVariableDefinitions?: ExternalVariableDefinition[];
|
|
114
|
+
builtinVariableDefinitions?: BuiltinVariableDefinition[];
|
|
115
|
+
}
|
|
116
|
+
export declare function VariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, }: VariableProviderProps): ReactElement;
|
|
117
|
+
export declare function VariableProviderWithQueryParams({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions: builtinVariables, }: VariableProviderProps): ReactElement;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=VariableProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAC;AAC9F,OAAO,EAAe,QAAQ,EAAY,MAAM,SAAS,CAAC;AAK1D,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EAGf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAGlB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAK1B;;;;;;GAMG;AACH,KAAK,uBAAuB,GAAG;IAC7B;;;;;;;;OAQG;IACH,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C;;;;;;;;;;OAUG;IACH,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D;;;;OAIG;IACH,aAAa,EAAE,qBAAqB,CAAC;IACrC;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9F;;;;;OAKG;IACH,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7F;;;;;OAKG;IACH,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpF,sBAAsB,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IACpE,wBAAwB,EAAE,MAAM,kBAAkB,EAAE,CAAC;IACrD,uBAAu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,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAClD,2BAA2B,CAAC,EAAE,0BAA0B,EAAE,CAAC;IAC3D,0BAA0B,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC1D;AAGD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA+B,GAChC,EAAE,qBAAqB,GAAG,YAAY,CAQtC;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA0B,EAAE,gBAAqB,GAClD,EAAE,qBAAqB,GAAG,YAAY,CAYtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -13,28 +13,31 @@
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createContext, useContext, useMemo, useState } from 'react';
|
|
15
15
|
import { createStore, useStore } from 'zustand';
|
|
16
|
+
import { useStoreWithEqualityFn } from 'zustand/traditional';
|
|
16
17
|
import { immer } from 'zustand/middleware/immer';
|
|
17
18
|
import { devtools } from 'zustand/middleware';
|
|
18
19
|
import produce from 'immer';
|
|
19
|
-
import {
|
|
20
|
+
import { VariableContext, BuiltinVariableContext, useTimeRange } from '@perses-dev/plugin-system';
|
|
20
21
|
import { DEFAULT_ALL_VALUE as ALL_VALUE, formatDuration, intervalToPrometheusDuration } from '@perses-dev/core';
|
|
21
22
|
import { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';
|
|
22
|
-
import {
|
|
23
|
+
import { hydrateVariableDefinitionStates as hydrateVariableDefinitionStates } from './hydrationUtils';
|
|
23
24
|
import { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Context object for {@link VariableDefinitionStore}.
|
|
27
|
+
*/ const VariableDefinitionStoreContext = /*#__PURE__*/ createContext(undefined);
|
|
28
|
+
export function useVariableDefinitionStoreCtx() {
|
|
29
|
+
const context = useContext(VariableDefinitionStoreContext);
|
|
27
30
|
if (!context) {
|
|
28
|
-
throw new Error('
|
|
31
|
+
throw new Error('VariableStoreContext not initialized');
|
|
29
32
|
}
|
|
30
33
|
return context;
|
|
31
34
|
}
|
|
32
|
-
export function
|
|
33
|
-
const store =
|
|
34
|
-
return
|
|
35
|
-
const
|
|
35
|
+
export function useVariableDefinitionStates(variableNames) {
|
|
36
|
+
const store = useVariableDefinitionStoreCtx();
|
|
37
|
+
return useStoreWithEqualityFn(store, (s)=>{
|
|
38
|
+
const varStates = {};
|
|
36
39
|
// Collect values of local variables, from the variable state
|
|
37
|
-
const names = variableNames
|
|
40
|
+
const names = variableNames ?? s.variableDefinitions.map((value)=>value.spec.name);
|
|
38
41
|
names.forEach((name)=>{
|
|
39
42
|
const varState = s.variableState.get({
|
|
40
43
|
name
|
|
@@ -42,7 +45,7 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
42
45
|
if (!varState || varState.overridden) {
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
varStates[name] = varState;
|
|
46
49
|
});
|
|
47
50
|
// Collect values of external variables, from the variable state
|
|
48
51
|
s.externalVariableDefinitions.forEach((d)=>{
|
|
@@ -56,27 +59,26 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
56
59
|
if (!varState || varState.overridden) {
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
|
-
|
|
62
|
+
varStates[name] = varState;
|
|
60
63
|
});
|
|
61
64
|
});
|
|
62
|
-
return
|
|
65
|
+
return varStates;
|
|
63
66
|
}, (left, right)=>{
|
|
64
67
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
|
-
* Get the state and definition of a variable from the
|
|
71
|
+
* Get the state and definition of a variable from the variables context.
|
|
69
72
|
* @param name name of the variable
|
|
70
73
|
* @param source if given, it searches in the external variables
|
|
71
|
-
*/ export function
|
|
72
|
-
const store =
|
|
74
|
+
*/ export function useVariableDefinitionAndState(name, source) {
|
|
75
|
+
const store = useVariableDefinitionStoreCtx();
|
|
73
76
|
return useStore(store, (s)=>{
|
|
74
|
-
var _s_externalVariableDefinitions_find;
|
|
75
77
|
const state = s.variableState.get({
|
|
76
78
|
name,
|
|
77
79
|
source
|
|
78
80
|
});
|
|
79
|
-
const definitions = source ?
|
|
81
|
+
const definitions = source ? s.externalVariableDefinitions.find((v)=>v.source === source)?.definitions : s.variableDefinitions;
|
|
80
82
|
const definition = (definitions || []).find((v)=>v.spec.name === name);
|
|
81
83
|
return {
|
|
82
84
|
state,
|
|
@@ -84,8 +86,8 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
84
86
|
};
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
|
-
export function
|
|
88
|
-
const store =
|
|
89
|
+
export function useVariableDefinitionActions() {
|
|
90
|
+
const store = useVariableDefinitionStoreCtx();
|
|
89
91
|
return useStore(store, (s)=>{
|
|
90
92
|
return {
|
|
91
93
|
setVariableValue: s.setVariableValue,
|
|
@@ -97,22 +99,18 @@ export function useTemplateVariableActions() {
|
|
|
97
99
|
};
|
|
98
100
|
});
|
|
99
101
|
}
|
|
100
|
-
export function
|
|
101
|
-
const store =
|
|
102
|
+
export function useVariableDefinitions() {
|
|
103
|
+
const store = useVariableDefinitionStoreCtx();
|
|
102
104
|
return useStore(store, (s)=>s.variableDefinitions);
|
|
103
105
|
}
|
|
104
|
-
export function
|
|
105
|
-
const store =
|
|
106
|
+
export function useExternalVariableDefinitions() {
|
|
107
|
+
const store = useVariableDefinitionStoreCtx();
|
|
106
108
|
return useStore(store, (s)=>s.externalVariableDefinitions);
|
|
107
109
|
}
|
|
108
|
-
export function useTemplateVariableStore() {
|
|
109
|
-
const store = useTemplateVariableStoreCtx();
|
|
110
|
-
return useStore(store);
|
|
111
|
-
}
|
|
112
110
|
function PluginProvider({ children, builtinVariables }) {
|
|
113
|
-
const originalValues =
|
|
114
|
-
const definitions =
|
|
115
|
-
const externalDefinitions =
|
|
111
|
+
const originalValues = useVariableDefinitionStates();
|
|
112
|
+
const definitions = useVariableDefinitions();
|
|
113
|
+
const externalDefinitions = useExternalVariableDefinitions();
|
|
116
114
|
const { absoluteTimeRange } = useTimeRange();
|
|
117
115
|
const values = useMemo(()=>{
|
|
118
116
|
const contextValues = {};
|
|
@@ -126,12 +124,10 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
126
124
|
if (v.value === ALL_VALUE) {
|
|
127
125
|
const definition = findVariableDefinitionByName(name, definitions, externalDefinitions);
|
|
128
126
|
// If the variable is a list variable and has a custom all value, then use that value instead
|
|
129
|
-
if (
|
|
127
|
+
if (definition?.kind === 'ListVariable' && definition.spec.customAllValue) {
|
|
130
128
|
v.value = definition.spec.customAllValue;
|
|
131
129
|
} else {
|
|
132
|
-
|
|
133
|
-
var _v_options_map;
|
|
134
|
-
v.value = (_v_options_map = (_v_options = v.options) === null || _v_options === void 0 ? void 0 : _v_options.map((o)=>o.value)) !== null && _v_options_map !== void 0 ? _v_options_map : null;
|
|
130
|
+
v.value = v.options?.map((o)=>o.value) ?? null;
|
|
135
131
|
}
|
|
136
132
|
}
|
|
137
133
|
contextValues[name] = v;
|
|
@@ -210,7 +206,7 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
208
|
];
|
|
213
|
-
builtinVariables
|
|
209
|
+
builtinVariables?.forEach((def)=>result.push(def));
|
|
214
210
|
return result;
|
|
215
211
|
}, [
|
|
216
212
|
absoluteTimeRange,
|
|
@@ -220,7 +216,7 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
220
216
|
value: {
|
|
221
217
|
variables: allBuiltinVariables
|
|
222
218
|
},
|
|
223
|
-
children: /*#__PURE__*/ _jsx(
|
|
219
|
+
children: /*#__PURE__*/ _jsx(VariableContext.Provider, {
|
|
224
220
|
value: {
|
|
225
221
|
state: values
|
|
226
222
|
},
|
|
@@ -228,16 +224,16 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
228
224
|
})
|
|
229
225
|
});
|
|
230
226
|
}
|
|
231
|
-
function
|
|
227
|
+
function createVariableDefinitionStore({ initialVariableDefinitions = [], externalVariableDefinitions = [], queryParams }) {
|
|
232
228
|
const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});
|
|
233
229
|
const store = createStore()(devtools(immer((set, get)=>({
|
|
234
|
-
variableState:
|
|
230
|
+
variableState: hydrateVariableDefinitionStates(initialVariableDefinitions, initialParams, externalVariableDefinitions),
|
|
235
231
|
variableDefinitions: initialVariableDefinitions,
|
|
236
232
|
externalVariableDefinitions: externalVariableDefinitions,
|
|
237
233
|
setVariableDefinitions (definitions) {
|
|
238
234
|
set((state)=>{
|
|
239
235
|
state.variableDefinitions = definitions;
|
|
240
|
-
state.variableState =
|
|
236
|
+
state.variableState = hydrateVariableDefinitionStates(definitions, initialParams, externalVariableDefinitions);
|
|
241
237
|
}, false, '[Variables] setVariableDefinitions' // Used for action name in Redux devtools
|
|
242
238
|
);
|
|
243
239
|
},
|
|
@@ -300,7 +296,7 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions = [], exter
|
|
|
300
296
|
const currentVariable = variableState.get({
|
|
301
297
|
name
|
|
302
298
|
});
|
|
303
|
-
if (
|
|
299
|
+
if (currentVariable?.value !== undefined) {
|
|
304
300
|
draft[index] = {
|
|
305
301
|
kind: 'ListVariable',
|
|
306
302
|
spec: produce(variable.spec, (specDraft)=>{
|
|
@@ -312,8 +308,8 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions = [], exter
|
|
|
312
308
|
const currentVariable = variableState.get({
|
|
313
309
|
name
|
|
314
310
|
});
|
|
315
|
-
const currentVariableValue = typeof
|
|
316
|
-
if (
|
|
311
|
+
const currentVariableValue = typeof currentVariable?.value === 'string' ? currentVariable.value : '';
|
|
312
|
+
if (currentVariable?.value !== undefined) {
|
|
317
313
|
draft[index] = {
|
|
318
314
|
kind: 'TextVariable',
|
|
319
315
|
spec: produce(variable.spec, (specDraft)=>{
|
|
@@ -333,30 +329,31 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions = [], exter
|
|
|
333
329
|
return checkSavedDefaultVariableStatus(get().variableDefinitions, get().variableState);
|
|
334
330
|
}
|
|
335
331
|
}))));
|
|
336
|
-
return store;
|
|
332
|
+
return store; // TODO: @Gladorme check if we can avoid this cast
|
|
337
333
|
}
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
// TODO: merge the different providers related to Variables under a single one (and keep "VariableProvider" as a name)
|
|
335
|
+
export function VariableProvider({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions = [] }) {
|
|
336
|
+
const [store] = useState(createVariableDefinitionStore({
|
|
340
337
|
initialVariableDefinitions,
|
|
341
338
|
externalVariableDefinitions
|
|
342
339
|
}));
|
|
343
|
-
return /*#__PURE__*/ _jsx(
|
|
340
|
+
return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
|
|
344
341
|
value: store,
|
|
345
342
|
children: /*#__PURE__*/ _jsx(PluginProvider, {
|
|
346
|
-
builtinVariables:
|
|
343
|
+
builtinVariables: builtinVariableDefinitions,
|
|
347
344
|
children: children
|
|
348
345
|
})
|
|
349
346
|
});
|
|
350
347
|
}
|
|
351
|
-
export function
|
|
348
|
+
export function VariableProviderWithQueryParams({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions: builtinVariables = [] }) {
|
|
352
349
|
const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);
|
|
353
350
|
const queryParams = useVariableQueryParams(allVariableDefs);
|
|
354
|
-
const [store] = useState(
|
|
351
|
+
const [store] = useState(createVariableDefinitionStore({
|
|
355
352
|
initialVariableDefinitions,
|
|
356
353
|
externalVariableDefinitions,
|
|
357
354
|
queryParams
|
|
358
355
|
}));
|
|
359
|
-
return /*#__PURE__*/ _jsx(
|
|
356
|
+
return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
|
|
360
357
|
value: store,
|
|
361
358
|
children: /*#__PURE__*/ _jsx(PluginProvider, {
|
|
362
359
|
builtinVariables: builtinVariables,
|
|
@@ -365,4 +362,4 @@ export function TemplateVariableProviderWithQueryParams({ children, initialVaria
|
|
|
365
362
|
});
|
|
366
363
|
}
|
|
367
364
|
|
|
368
|
-
//# sourceMappingURL=
|
|
365
|
+
//# sourceMappingURL=VariableProvider.js.map
|