@perses-dev/dashboards 0.37.2 → 0.39.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.
- package/dist/cjs/components/Dashboard/Dashboard.js +3 -2
- package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +12 -52
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -1
- package/dist/cjs/components/GridLayout/GridLayout.js +1 -0
- package/dist/cjs/components/Panel/Panel.js +8 -3
- package/dist/cjs/components/Panel/PanelHeader.js +7 -3
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +3 -1
- package/dist/cjs/components/Variables/EditVariablesButton.js +2 -0
- package/dist/cjs/components/Variables/TemplateVariable.js +22 -18
- package/dist/cjs/components/Variables/VariableEditor.js +271 -99
- package/dist/cjs/components/Variables/VariableList.js +38 -18
- package/dist/cjs/components/Variables/index.js +0 -2
- package/dist/cjs/context/DatasourceStoreProvider.js +22 -18
- package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +71 -24
- package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +55 -5
- package/dist/cjs/context/TemplateVariableProvider/utils.js +39 -7
- package/dist/cjs/test/render.js +1 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +7 -2
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +4 -3
- package/dist/components/Dashboard/Dashboard.d.ts +3 -1
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard/Dashboard.js +3 -2
- package/dist/components/Dashboard/Dashboard.js.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +11 -46
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +3 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -0
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -0
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +20 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +8 -3
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +2 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +7 -3
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +3 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js +3 -1
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/TemplateVariable.d.ts +2 -1
- package/dist/components/Variables/TemplateVariable.d.ts.map +1 -1
- package/dist/components/Variables/TemplateVariable.js +21 -17
- package/dist/components/Variables/TemplateVariable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +7 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +261 -95
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts +5 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +31 -17
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +0 -2
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +0 -2
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +4 -3
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +22 -18
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +39 -10
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +76 -27
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts +9 -2
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.js +60 -5
- package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
- package/dist/context/TemplateVariableProvider/utils.d.ts +27 -2
- package/dist/context/TemplateVariableProvider/utils.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider/utils.js +46 -4
- package/dist/context/TemplateVariableProvider/utils.js.map +1 -1
- package/dist/test/render.js +2 -2
- package/dist/test/render.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +9 -4
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +4 -3
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +6 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -399
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +0 -178
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +0 -29
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -91
- package/dist/cjs/components/Variables/variable-model.js +0 -117
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +0 -10
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -354
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +0 -16
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +0 -122
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/index.d.ts +0 -3
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/index.js +0 -16
- package/dist/components/Variables/VariableEditorForm/index.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +0 -23
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -79
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +0 -1
- package/dist/components/Variables/variable-model.d.ts +0 -16
- package/dist/components/Variables/variable-model.d.ts.map +0 -1
- package/dist/components/Variables/variable-model.js +0 -105
- package/dist/components/Variables/variable-model.js.map +0 -1
|
@@ -10,30 +10,44 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { Box } from '@mui/material';
|
|
15
|
-
import { useTemplateVariableDefinitions } from '../../context';
|
|
15
|
+
import { useTemplateExternalVariableDefinitions, useTemplateVariable, useTemplateVariableDefinitions } from '../../context';
|
|
16
16
|
import { TemplateVariable } from './TemplateVariable';
|
|
17
17
|
const VARIABLE_INPUT_MIN_WIDTH = '120px';
|
|
18
18
|
const VARIABLE_INPUT_MAX_WIDTH = '240px';
|
|
19
19
|
export function TemplateVariableList() {
|
|
20
20
|
const variableDefinitions = useTemplateVariableDefinitions();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, v.spec.name)
|
|
34
|
-
}, v.spec.name);
|
|
35
|
-
})
|
|
21
|
+
const externalVariableDefinitions = useTemplateExternalVariableDefinitions();
|
|
22
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
23
|
+
children: [
|
|
24
|
+
externalVariableDefinitions.slice().reverse() // We reverse to have the most prioritized on top
|
|
25
|
+
.map((def)=>def.definitions.map((v)=>/*#__PURE__*/ _jsx(TemplateVariableListItem, {
|
|
26
|
+
spec: v.spec,
|
|
27
|
+
source: def.source
|
|
28
|
+
}, v.spec.name + def.source))),
|
|
29
|
+
variableDefinitions.map((v)=>/*#__PURE__*/ _jsx(TemplateVariableListItem, {
|
|
30
|
+
spec: v.spec
|
|
31
|
+
}, v.spec.name))
|
|
32
|
+
]
|
|
36
33
|
});
|
|
37
34
|
}
|
|
35
|
+
export function TemplateVariableListItem({ spec , source }) {
|
|
36
|
+
var ref, ref1;
|
|
37
|
+
const ctx = useTemplateVariable(spec.name, source);
|
|
38
|
+
var ref2, ref3;
|
|
39
|
+
return /*#__PURE__*/ _jsx(Box, {
|
|
40
|
+
display: ((ref = ctx.state) === null || ref === void 0 ? void 0 : ref.overridden) || ((ref1 = spec.display) === null || ref1 === void 0 ? void 0 : ref1.hidden) ? 'none' : undefined,
|
|
41
|
+
minWidth: VARIABLE_INPUT_MIN_WIDTH,
|
|
42
|
+
maxWidth: VARIABLE_INPUT_MAX_WIDTH,
|
|
43
|
+
marginBottom: 1,
|
|
44
|
+
marginRight: 1,
|
|
45
|
+
"data-testid": "template-variable",
|
|
46
|
+
children: /*#__PURE__*/ _jsx(TemplateVariable, {
|
|
47
|
+
name: spec.name,
|
|
48
|
+
source: source
|
|
49
|
+
}, (ref2 = spec.name + source) !== null && ref2 !== void 0 ? ref2 : '')
|
|
50
|
+
}, (ref3 = spec.name + source) !== null && ref3 !== void 0 ? ref3 : '');
|
|
51
|
+
}
|
|
38
52
|
|
|
39
53
|
//# sourceMappingURL=VariableList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/VariableList.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 { Box } from '@mui/material';\nimport { VariableDefinition } from '@perses-dev/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/VariableList.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 { Box } from '@mui/material';\nimport { VariableDefinition, VariableSpec } from '@perses-dev/core';\nimport {\n ExternalVariableDefinition,\n useTemplateExternalVariableDefinitions,\n useTemplateVariable,\n useTemplateVariableDefinitions,\n} from '../../context';\nimport { TemplateVariable } from './TemplateVariable';\n\nconst VARIABLE_INPUT_MIN_WIDTH = '120px';\nconst VARIABLE_INPUT_MAX_WIDTH = '240px';\n\nexport function TemplateVariableList() {\n const variableDefinitions: VariableDefinition[] = useTemplateVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useTemplateExternalVariableDefinitions();\n\n return (\n <>\n {externalVariableDefinitions\n .slice()\n .reverse() // We reverse to have the most prioritized on top\n .map((def) =>\n def.definitions.map((v) => (\n <TemplateVariableListItem key={v.spec.name + def.source} spec={v.spec} source={def.source} />\n ))\n )}\n {variableDefinitions.map((v) => (\n <TemplateVariableListItem key={v.spec.name} spec={v.spec} />\n ))}\n </>\n );\n}\n\nexport function TemplateVariableListItem({ spec, source }: { spec: VariableSpec; source?: string }) {\n const ctx = useTemplateVariable(spec.name, source);\n return (\n <Box\n key={spec.name + source ?? ''}\n display={ctx.state?.overridden || spec.display?.hidden ? 'none' : undefined}\n minWidth={VARIABLE_INPUT_MIN_WIDTH}\n maxWidth={VARIABLE_INPUT_MAX_WIDTH}\n marginBottom={1}\n marginRight={1}\n data-testid=\"template-variable\"\n >\n <TemplateVariable key={spec.name + source ?? ''} name={spec.name} source={source} />\n </Box>\n );\n}\n"],"names":["Box","useTemplateExternalVariableDefinitions","useTemplateVariable","useTemplateVariableDefinitions","TemplateVariable","VARIABLE_INPUT_MIN_WIDTH","VARIABLE_INPUT_MAX_WIDTH","TemplateVariableList","variableDefinitions","externalVariableDefinitions","slice","reverse","map","def","definitions","v","TemplateVariableListItem","spec","source","name","ctx","display","state","overridden","hidden","undefined","minWidth","maxWidth","marginBottom","marginRight","data-testid"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;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,IAAI,EAAED,MAAM,CAAC,AAAC;QAWxBD,IAAkB,EARpCA,IAAkB;IAF3B,qBACE,KAACjB,GAAG;QAEFqB,OAAO,EAAED,CAAAA,CAAAA,GAAS,GAATA,GAAG,CAACE,KAAK,cAATF,GAAS,WAAY,GAArBA,KAAAA,CAAqB,GAArBA,GAAS,CAAEG,UAAU,CAAA,IAAIN,CAAAA,CAAAA,IAAY,GAAZA,IAAI,CAACI,OAAO,cAAZJ,IAAY,WAAQ,GAApBA,KAAAA,CAAoB,GAApBA,IAAY,CAAEO,MAAM,CAAA,GAAG,MAAM,GAAGC,SAAS;QAC3EC,QAAQ,EAAErB,wBAAwB;QAClCsB,QAAQ,EAAErB,wBAAwB;QAClCsB,YAAY,EAAE,CAAC;QACfC,WAAW,EAAE,CAAC;QACdC,aAAW,EAAC,mBAAmB;kBAE/B,cAAA,KAAC1B,gBAAgB;YAAgCe,IAAI,EAAEF,IAAI,CAACE,IAAI;YAAED,MAAM,EAAEA,MAAM;WAAzDD,CAAAA,IAAkB,GAAlBA,IAAI,CAACE,IAAI,GAAGD,MAAM,cAAlBD,IAAkB,cAAlBA,IAAkB,GAAI,EAAE,CAAqC;OAR/EA,CAAAA,IAAkB,GAAlBA,IAAI,CAACE,IAAI,GAAGD,MAAM,cAAlBD,IAAkB,cAAlBA,IAAkB,GAAI,EAAE,CASzB,CACN;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/index.tsx"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/index.tsx"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
export * from './EditVariablesButton';
|
|
14
14
|
export * from './TemplateVariable';
|
|
15
15
|
export * from './VariableEditor';
|
|
16
|
-
export * from './VariableEditorForm';
|
|
17
16
|
export * from './VariableList';
|
|
18
|
-
export * from './variable-model';
|
|
19
17
|
|
|
20
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/index.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\nexport * from './EditVariablesButton';\nexport * from './TemplateVariable';\nexport * from './VariableEditor';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/index.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\nexport * from './EditVariablesButton';\nexport * from './TemplateVariable';\nexport * from './VariableEditor';\nexport * from './VariableList';\n"],"names":[],"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,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { DashboardResource, Datasource, DatasourceSelector, GlobalDatasource } from '@perses-dev/core';
|
|
3
3
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
4
4
|
export interface DatasourceStoreProviderProps {
|
|
5
|
-
dashboardResource
|
|
5
|
+
dashboardResource?: DashboardResource;
|
|
6
|
+
projectName?: string;
|
|
6
7
|
datasourceApi: DatasourceApi;
|
|
7
|
-
children?:
|
|
8
|
+
children?: ReactNode;
|
|
8
9
|
onCreate?: (client: DatasourceClient) => DatasourceClient;
|
|
9
10
|
}
|
|
10
11
|
export interface DatasourceApi {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAwB,MAAM,OAAO,CAAC;AACxD,OAAO,EACL,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAElB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CAC3D;AAGD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAErE,mBAAmB,EAAE,CACnB,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAE3E,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEjF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,eA4G1E"}
|
|
@@ -17,26 +17,30 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
17
17
|
/**
|
|
18
18
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
19
19
|
*/ export function DatasourceStoreProvider(props) {
|
|
20
|
-
const { dashboardResource , datasourceApi , onCreate , children } = props;
|
|
21
|
-
const
|
|
20
|
+
const { dashboardResource , projectName , datasourceApi , onCreate , children } = props;
|
|
21
|
+
const project = projectName !== null && projectName !== void 0 ? projectName : dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.metadata.project;
|
|
22
22
|
const { getPlugin , listPluginMetadata } = usePluginRegistry();
|
|
23
23
|
const findDatasource = useEvent(async (selector)=>{
|
|
24
24
|
// Try to find it in dashboard spec
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
if (dashboardResource) {
|
|
26
|
+
const { datasources } = dashboardResource.spec;
|
|
27
|
+
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
28
|
+
if (dashboardDatasource !== undefined) {
|
|
29
|
+
return {
|
|
30
|
+
spec: dashboardDatasource,
|
|
31
|
+
proxyUrl: undefined
|
|
32
|
+
};
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
if (project) {
|
|
36
|
+
// Try to find it at the project level as a Datasource resource
|
|
37
|
+
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
38
|
+
if (datasource !== undefined) {
|
|
39
|
+
return {
|
|
40
|
+
spec: datasource.resource.spec,
|
|
41
|
+
proxyUrl: datasource.proxyUrl
|
|
42
|
+
};
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
42
46
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
@@ -78,7 +82,7 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
78
82
|
const listDatasourceMetadata = useEvent(async (datasourcePluginKind)=>{
|
|
79
83
|
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
80
84
|
listPluginMetadata('Datasource'),
|
|
81
|
-
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
85
|
+
project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],
|
|
82
86
|
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
83
87
|
]);
|
|
84
88
|
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
@@ -89,7 +93,7 @@ import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-sy
|
|
|
89
93
|
// Get helper for de-duping results properly
|
|
90
94
|
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
91
95
|
// Start with dashboard datasources that have highest precedence
|
|
92
|
-
if (dashboardResource.spec.datasources
|
|
96
|
+
if (dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) {
|
|
93
97
|
for(const selectorName in dashboardResource.spec.datasources){
|
|
94
98
|
const spec = dashboardResource.spec.datasources[selectorName];
|
|
95
99
|
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
@@ -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 { useCallback, useMemo } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n Datasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n usePluginRegistry,\n DatasourceMetadata,\n DatasourceClient,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (\n project: string,\n selector: DatasourceSelector\n ) => Promise<{ resource: Datasource; proxyUrl: string } | undefined>;\n\n getGlobalDatasource: (\n selector: DatasourceSelector\n ) => Promise<{ resource: GlobalDatasource; proxyUrl: string } | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;\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 { dashboardResource, datasourceApi, onCreate, children } = props;\n const { project } = dashboardResource.metadata;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return { spec: dashboardDatasource, proxyUrl: undefined };\n }\n\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 { spec: datasource.resource.spec, proxyUrl: datasource.proxyUrl };\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 { spec: globalDatasource.resource.spec, proxyUrl: globalDatasource.proxyUrl };\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 listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n 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 de-duping results properly\n const { results, addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources that have highest precedence\n if (dashboardResource.spec.datasources !== undefined) {\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 addResult(spec, selectorName);\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addResult(datasource.spec, selectorName);\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addResult(globalDatasource.spec, selectorName);\n }\n\n return results;\n });\n\n const ctxValue: DatasourceStore = useMemo(\n () => ({\n getDatasource,\n getDatasourceClient,\n listDatasourceMetadata,\n }),\n [getDatasource, getDatasourceClient, listDatasourceMetadata]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(dashboardDatasources: DashboardSpec['datasources'], selector: DatasourceSelector) {\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 ? named : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n return Object.values(dashboardDatasources).find((ds) => ds.plugin.kind === selector.kind && ds.default === true);\n}\n\n// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors\nfunction buildListDatasourceMetadataResults(pluginDisplayName: string) {\n const results: DatasourceMetadata[] = [];\n const usedNames = new Set<string>();\n let defaultAdded = false;\n const addResult = (spec: DatasourceSpec, selectorName: string) => {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n if (spec.default && defaultAdded === false) {\n results.unshift({\n name: `Default ${pluginDisplayName}`,\n selector: {\n kind: spec.plugin.kind,\n },\n });\n defaultAdded = true;\n }\n\n // If we already have a datasource with this selector name, ignore it, otherwise add to end of list\n if (usedNames.has(selectorName)) return;\n\n results.push({\n name: spec.display?.name ?? selectorName,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n },\n });\n usedNames.add(selectorName);\n };\n\n return { results, addResult };\n}\n"],"names":["useCallback","useMemo","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","dashboardResource","datasourceApi","onCreate","children","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","datasource","getDatasource","resource","globalDatasource","getGlobalDatasource","Error","kind","name","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceMetadata","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addResult","buildListDatasourceMetadataResults","display","selectorName","ctxValue","Provider","value","dashboardDatasources","named","Object","values","ds","default","pluginDisplayName","usedNames","Set","defaultAdded","unshift","has","push","add"],"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,OAAO,QAAQ,OAAO,CAAC;AAC7C,SAOEC,QAAQ,QACH,kBAAkB,CAAC;AAC1B,SACEC,sBAAs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O;QAAEJ,OAAO;QAAEC,SAAS;KAAE,CAAC;AAChC,CAAC"}
|
|
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 } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n Datasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n usePluginRegistry,\n DatasourceMetadata,\n DatasourceClient,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (\n project: string,\n selector: DatasourceSelector\n ) => Promise<{ resource: Datasource; proxyUrl: string } | undefined>;\n\n getGlobalDatasource: (\n selector: DatasourceSelector\n ) => Promise<{ resource: GlobalDatasource; proxyUrl: string } | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;\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 { dashboardResource, projectName, datasourceApi, onCreate, children } = props;\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 { spec: dashboardDatasource, proxyUrl: undefined };\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 { spec: datasource.resource.spec, proxyUrl: datasource.proxyUrl };\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 { spec: globalDatasource.resource.spec, proxyUrl: globalDatasource.proxyUrl };\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 listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\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 de-duping results properly\n const { results, addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources that have 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 addResult(spec, selectorName);\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addResult(datasource.spec, selectorName);\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addResult(globalDatasource.spec, selectorName);\n }\n\n return results;\n });\n\n const ctxValue: DatasourceStore = useMemo(\n () => ({\n getDatasource,\n getDatasourceClient,\n listDatasourceMetadata,\n }),\n [getDatasource, getDatasourceClient, listDatasourceMetadata]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(dashboardDatasources: DashboardSpec['datasources'], selector: DatasourceSelector) {\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 ? named : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n return Object.values(dashboardDatasources).find((ds) => ds.plugin.kind === selector.kind && ds.default === true);\n}\n\n// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors\nfunction buildListDatasourceMetadataResults(pluginDisplayName: string) {\n const results: DatasourceMetadata[] = [];\n const usedNames = new Set<string>();\n let defaultAdded = false;\n const addResult = (spec: DatasourceSpec, selectorName: string) => {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n if (spec.default && defaultAdded === false) {\n results.unshift({\n name: `Default ${pluginDisplayName}`,\n selector: {\n kind: spec.plugin.kind,\n },\n });\n defaultAdded = true;\n }\n\n // If we already have a datasource with this selector name, ignore it, otherwise add to end of list\n if (usedNames.has(selectorName)) return;\n\n results.push({\n name: spec.display?.name ?? selectorName,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n },\n });\n usedNames.add(selectorName);\n };\n\n return { results, addResult };\n}\n"],"names":["useCallback","useMemo","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","dashboardResource","projectName","datasourceApi","onCreate","children","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","datasource","getDatasource","resource","globalDatasource","getGlobalDatasource","Error","kind","name","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceMetadata","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addResult","buildListDatasourceMetadataResults","display","selectorName","ctxValue","Provider","value","dashboardDatasources","named","Object","values","ds","default","pluginDisplayName","usedNames","Set","defaultAdded","unshift","has","push","add"],"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,SAAoBA,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AACxD,SAOEC,QAAQ,QACH,kBAAkB,CAAC;AAC1B,SACEC,sBAAsB,EAEtBC,iBAAiB,QAGZ,2BAA2B,CAAC;AA0BnC;;CAEC,GACD,OAAO,SAASC,uBAAuB,CAACC,KAAmC,EAAE;IAC3E,MAAM,EAAEC,iBAAiB,CAAA,EAAEC,WAAW,CAAA,EAAEC,aAAa,CAAA,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B;SACF,CAAC,CAAC;QACHW,SAAS,CAACM,GAAG,CAACjB,YAAY,CAAC,CAAC;IAC9B,CAAC,AAAC;IAEF,OAAO;QAAEJ,OAAO;QAAEC,SAAS;KAAE,CAAC;AAChC,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { VariableStateMap, VariableState, VariableOption } from '@perses-dev/plugin-system';
|
|
2
|
+
import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system';
|
|
3
3
|
import { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';
|
|
4
4
|
declare type TemplateVariableStore = {
|
|
5
5
|
variableDefinitions: VariableDefinition[];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
externalVariableDefinitions: ExternalVariableDefinition[];
|
|
7
|
+
variableState: VariableStoreStateMap;
|
|
8
|
+
setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;
|
|
9
|
+
setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;
|
|
10
|
+
setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;
|
|
10
11
|
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
11
12
|
setVariableDefaultValues: () => VariableDefinition[];
|
|
12
13
|
getSavedVariablesStatus: () => {
|
|
@@ -14,15 +15,29 @@ declare type TemplateVariableStore = {
|
|
|
14
15
|
modifiedVariableNames: string[];
|
|
15
16
|
};
|
|
16
17
|
};
|
|
18
|
+
export declare function useTemplateVariableStoreCtx(): Omit<Omit<import("zustand").StoreApi<TemplateVariableStore>, "setState"> & {
|
|
19
|
+
setState<A extends string | {
|
|
20
|
+
type: unknown;
|
|
21
|
+
}>(partial: TemplateVariableStore | Partial<TemplateVariableStore> | ((state: TemplateVariableStore) => TemplateVariableStore | Partial<TemplateVariableStore>), replace?: boolean | undefined, action?: A | undefined): void;
|
|
22
|
+
}, "setState"> & {
|
|
23
|
+
setState(nextStateOrUpdater: TemplateVariableStore | Partial<TemplateVariableStore> | ((state: import("immer/dist/internal").WritableDraft<TemplateVariableStore>) => void), shouldReplace?: boolean | undefined, action?: string | {
|
|
24
|
+
type: unknown;
|
|
25
|
+
} | undefined): void;
|
|
26
|
+
};
|
|
17
27
|
export declare function useTemplateVariableValues(variableNames?: string[]): VariableStateMap;
|
|
18
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Get the state and definition of a variable from the Template variables context.
|
|
30
|
+
* @param name name of the variable
|
|
31
|
+
* @param source if given, it searches in the external variables
|
|
32
|
+
*/
|
|
33
|
+
export declare function useTemplateVariable(name: string, source?: string): {
|
|
19
34
|
state: VariableState | undefined;
|
|
20
35
|
definition: VariableDefinition | undefined;
|
|
21
36
|
};
|
|
22
37
|
export declare function useTemplateVariableActions(): {
|
|
23
|
-
setVariableValue: (variableName: string, value: VariableValue) => void;
|
|
24
|
-
setVariableLoading: (name: string, loading: boolean) => void;
|
|
25
|
-
setVariableOptions: (name: string, options: VariableOption[]) => void;
|
|
38
|
+
setVariableValue: (variableName: string, value: VariableValue, source?: string | undefined) => void;
|
|
39
|
+
setVariableLoading: (name: string, loading: boolean, source?: string | undefined) => void;
|
|
40
|
+
setVariableOptions: (name: string, options: VariableOption[], source?: string | undefined) => void;
|
|
26
41
|
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
27
42
|
setVariableDefaultValues: () => VariableDefinition[];
|
|
28
43
|
getSavedVariablesStatus: () => {
|
|
@@ -31,11 +46,25 @@ export declare function useTemplateVariableActions(): {
|
|
|
31
46
|
};
|
|
32
47
|
};
|
|
33
48
|
export declare function useTemplateVariableDefinitions(): VariableDefinition[];
|
|
49
|
+
export declare function useTemplateExternalVariableDefinitions(): ExternalVariableDefinition[];
|
|
34
50
|
export declare function useTemplateVariableStore(): TemplateVariableStore;
|
|
51
|
+
export declare type ExternalVariableDefinition = {
|
|
52
|
+
source: string;
|
|
53
|
+
definitions: VariableDefinition[];
|
|
54
|
+
};
|
|
35
55
|
export interface TemplateVariableProviderProps {
|
|
36
56
|
children: React.ReactNode;
|
|
37
57
|
initialVariableDefinitions?: VariableDefinition[];
|
|
58
|
+
/**
|
|
59
|
+
* The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.
|
|
60
|
+
* 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
|
|
61
|
+
* to modify their runtime value as any other variable.
|
|
62
|
+
* If one of the external variable has the same name as a local one, it will be marked as overridden.
|
|
63
|
+
* You can define one list of variable definition by source and as many source as you want.
|
|
64
|
+
* The order of the sources is important as first one will take precedence on the following ones, in case they have same names.
|
|
65
|
+
*/
|
|
66
|
+
externalVariableDefinitions?: ExternalVariableDefinition[];
|
|
38
67
|
}
|
|
39
|
-
export declare function TemplateVariableProvider({ children, initialVariableDefinitions }: TemplateVariableProviderProps): JSX.Element;
|
|
68
|
+
export declare function TemplateVariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, }: TemplateVariableProviderProps): JSX.Element;
|
|
40
69
|
export {};
|
|
41
70
|
//# sourceMappingURL=TemplateVariableProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAkBA,OAAO,
|
|
1
|
+
{"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAkC,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAKnH,aAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;I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EAAE,0BAA0B,EAAE,CAAC;CAC5D;AAED,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,GACjC,EAAE,6BAA6B,eAY/B"}
|
|
@@ -18,11 +18,11 @@ import { devtools } from 'zustand/middleware';
|
|
|
18
18
|
import produce from 'immer';
|
|
19
19
|
import { TemplateVariableContext } from '@perses-dev/plugin-system';
|
|
20
20
|
import { DEFAULT_ALL_VALUE as ALL_VALUE } from '@perses-dev/core';
|
|
21
|
-
import { checkSavedDefaultVariableStatus } from './utils';
|
|
21
|
+
import { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';
|
|
22
22
|
import { hydrateTemplateVariableStates } from './hydrationUtils';
|
|
23
|
-
import {
|
|
23
|
+
import { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';
|
|
24
24
|
const TemplateVariableStoreContext = /*#__PURE__*/ createContext(undefined);
|
|
25
|
-
function useTemplateVariableStoreCtx() {
|
|
25
|
+
export function useTemplateVariableStoreCtx() {
|
|
26
26
|
const context = useContext(TemplateVariableStoreContext);
|
|
27
27
|
if (!context) {
|
|
28
28
|
throw new Error('TemplateVariableStoreContext not initialized');
|
|
@@ -31,29 +31,55 @@ function useTemplateVariableStoreCtx() {
|
|
|
31
31
|
}
|
|
32
32
|
export function useTemplateVariableValues(variableNames) {
|
|
33
33
|
const store = useTemplateVariableStoreCtx();
|
|
34
|
-
|
|
35
|
-
const names = variableNames !== null && variableNames !== void 0 ? variableNames : Object.keys(s.variableState);
|
|
34
|
+
return useStore(store, (s)=>{
|
|
36
35
|
const vars = {};
|
|
36
|
+
// Collect values of local variables, from the variable state
|
|
37
|
+
const names = variableNames !== null && variableNames !== void 0 ? variableNames : s.variableDefinitions.map((value)=>value.spec.name);
|
|
37
38
|
names.forEach((name)=>{
|
|
38
|
-
const varState = s.variableState
|
|
39
|
-
|
|
39
|
+
const varState = s.variableState.get({
|
|
40
|
+
name
|
|
41
|
+
});
|
|
42
|
+
if (!varState || varState.overridden) {
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
vars[name] = varState;
|
|
43
46
|
});
|
|
47
|
+
// Collect values of external variables, from the variable state
|
|
48
|
+
s.externalVariableDefinitions.forEach((d)=>{
|
|
49
|
+
const source = d.source;
|
|
50
|
+
d.definitions.forEach((value)=>{
|
|
51
|
+
const name = value.spec.name;
|
|
52
|
+
const varState = s.variableState.get({
|
|
53
|
+
name,
|
|
54
|
+
source
|
|
55
|
+
});
|
|
56
|
+
if (!varState || varState.overridden) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
vars[name] = varState;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
44
62
|
return vars;
|
|
45
63
|
}, (left, right)=>{
|
|
46
64
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
47
65
|
});
|
|
48
|
-
return state;
|
|
49
66
|
}
|
|
50
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Get the state and definition of a variable from the Template variables context.
|
|
69
|
+
* @param name name of the variable
|
|
70
|
+
* @param source if given, it searches in the external variables
|
|
71
|
+
*/ export function useTemplateVariable(name, source) {
|
|
51
72
|
const store = useTemplateVariableStoreCtx();
|
|
52
73
|
return useStore(store, (s)=>{
|
|
53
|
-
|
|
54
|
-
const
|
|
74
|
+
var ref;
|
|
75
|
+
const state = s.variableState.get({
|
|
76
|
+
name,
|
|
77
|
+
source
|
|
78
|
+
});
|
|
79
|
+
const definitions = source ? (ref = s.externalVariableDefinitions.find((v)=>v.source === source)) === null || ref === void 0 ? void 0 : ref.definitions : s.variableDefinitions;
|
|
80
|
+
const definition = (definitions || []).find((v)=>v.spec.name === name);
|
|
55
81
|
return {
|
|
56
|
-
state
|
|
82
|
+
state,
|
|
57
83
|
definition
|
|
58
84
|
};
|
|
59
85
|
});
|
|
@@ -75,6 +101,10 @@ export function useTemplateVariableDefinitions() {
|
|
|
75
101
|
const store = useTemplateVariableStoreCtx();
|
|
76
102
|
return useStore(store, (s)=>s.variableDefinitions);
|
|
77
103
|
}
|
|
104
|
+
export function useTemplateExternalVariableDefinitions() {
|
|
105
|
+
const store = useTemplateVariableStoreCtx();
|
|
106
|
+
return useStore(store, (s)=>s.externalVariableDefinitions);
|
|
107
|
+
}
|
|
78
108
|
export function useTemplateVariableStore() {
|
|
79
109
|
const store = useTemplateVariableStoreCtx();
|
|
80
110
|
return useStore(store);
|
|
@@ -82,6 +112,7 @@ export function useTemplateVariableStore() {
|
|
|
82
112
|
function PluginProvider({ children }) {
|
|
83
113
|
const originalValues = useTemplateVariableValues();
|
|
84
114
|
const definitions = useTemplateVariableDefinitions();
|
|
115
|
+
const externalDefinitions = useTemplateExternalVariableDefinitions();
|
|
85
116
|
const values = useMemo(()=>{
|
|
86
117
|
const contextValues = {};
|
|
87
118
|
// This will loop through all the current variables values
|
|
@@ -92,7 +123,7 @@ function PluginProvider({ children }) {
|
|
|
92
123
|
...originalValues[name]
|
|
93
124
|
};
|
|
94
125
|
if (v.value === ALL_VALUE) {
|
|
95
|
-
const definition =
|
|
126
|
+
const definition = findVariableDefinitionByName(name, definitions, externalDefinitions);
|
|
96
127
|
// If the variable is a list variable and has a custom all value, then use that value instead
|
|
97
128
|
if ((definition === null || definition === void 0 ? void 0 : definition.kind) === 'ListVariable' && definition.spec.custom_all_value) {
|
|
98
129
|
v.value = definition.spec.custom_all_value;
|
|
@@ -107,7 +138,8 @@ function PluginProvider({ children }) {
|
|
|
107
138
|
return contextValues;
|
|
108
139
|
}, [
|
|
109
140
|
originalValues,
|
|
110
|
-
definitions
|
|
141
|
+
definitions,
|
|
142
|
+
externalDefinitions
|
|
111
143
|
]);
|
|
112
144
|
return /*#__PURE__*/ _jsx(TemplateVariableContext.Provider, {
|
|
113
145
|
value: {
|
|
@@ -116,40 +148,50 @@ function PluginProvider({ children }) {
|
|
|
116
148
|
children: children
|
|
117
149
|
});
|
|
118
150
|
}
|
|
119
|
-
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , queryParams }) {
|
|
151
|
+
function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , externalVariableDefinitions =[] , queryParams }) {
|
|
120
152
|
const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});
|
|
121
153
|
const store = createStore()(devtools(immer((set, get)=>{
|
|
122
154
|
return {
|
|
123
|
-
variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),
|
|
155
|
+
variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams, externalVariableDefinitions),
|
|
124
156
|
variableDefinitions: initialVariableDefinitions,
|
|
157
|
+
externalVariableDefinitions: externalVariableDefinitions,
|
|
125
158
|
setVariableDefinitions (definitions) {
|
|
126
159
|
set((state)=>{
|
|
127
160
|
state.variableDefinitions = definitions;
|
|
128
|
-
state.variableState = hydrateTemplateVariableStates(definitions, initialParams);
|
|
161
|
+
state.variableState = hydrateTemplateVariableStates(definitions, initialParams, externalVariableDefinitions);
|
|
129
162
|
}, false, '[Variables] setVariableDefinitions' // Used for action name in Redux devtools
|
|
130
163
|
);
|
|
131
164
|
},
|
|
132
|
-
setVariableOptions (name, options) {
|
|
165
|
+
setVariableOptions (name, options, source) {
|
|
133
166
|
set((state)=>{
|
|
134
|
-
const varState = state.variableState
|
|
167
|
+
const varState = state.variableState.get({
|
|
168
|
+
name,
|
|
169
|
+
source
|
|
170
|
+
});
|
|
135
171
|
if (!varState) {
|
|
136
172
|
return;
|
|
137
173
|
}
|
|
138
174
|
varState.options = options;
|
|
139
175
|
}, false, '[Variables] setVariableOptions');
|
|
140
176
|
},
|
|
141
|
-
setVariableLoading (name, loading) {
|
|
177
|
+
setVariableLoading (name, loading, source) {
|
|
142
178
|
set((state)=>{
|
|
143
|
-
const varState = state.variableState
|
|
179
|
+
const varState = state.variableState.get({
|
|
180
|
+
name,
|
|
181
|
+
source
|
|
182
|
+
});
|
|
144
183
|
if (!varState) {
|
|
145
184
|
return;
|
|
146
185
|
}
|
|
147
186
|
varState.loading = loading;
|
|
148
187
|
}, false, '[Variables] setVariableLoading');
|
|
149
188
|
},
|
|
150
|
-
setVariableValue: (name, value)=>set((state)=>{
|
|
189
|
+
setVariableValue: (name, value, source)=>set((state)=>{
|
|
151
190
|
let val = value;
|
|
152
|
-
const varState = state.variableState
|
|
191
|
+
const varState = state.variableState.get({
|
|
192
|
+
name,
|
|
193
|
+
source
|
|
194
|
+
});
|
|
153
195
|
if (!varState) {
|
|
154
196
|
return;
|
|
155
197
|
}
|
|
@@ -174,8 +216,11 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , query
|
|
|
174
216
|
const variableState = get().variableState;
|
|
175
217
|
const updatedVariables = produce(variableDefinitions, (draft)=>{
|
|
176
218
|
draft.forEach((variable, index)=>{
|
|
219
|
+
const name = variable.spec.name;
|
|
177
220
|
if (variable.kind === 'ListVariable') {
|
|
178
|
-
const currentVariable = variableState
|
|
221
|
+
const currentVariable = variableState.get({
|
|
222
|
+
name
|
|
223
|
+
});
|
|
179
224
|
if ((currentVariable === null || currentVariable === void 0 ? void 0 : currentVariable.value) !== undefined) {
|
|
180
225
|
draft[index] = {
|
|
181
226
|
kind: 'ListVariable',
|
|
@@ -185,7 +230,9 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , query
|
|
|
185
230
|
};
|
|
186
231
|
}
|
|
187
232
|
} else if (variable.kind === 'TextVariable') {
|
|
188
|
-
const currentVariable1 = variableState
|
|
233
|
+
const currentVariable1 = variableState.get({
|
|
234
|
+
name
|
|
235
|
+
});
|
|
189
236
|
const currentVariableValue = typeof (currentVariable1 === null || currentVariable1 === void 0 ? void 0 : currentVariable1.value) === 'string' ? currentVariable1.value : '';
|
|
190
237
|
if ((currentVariable1 === null || currentVariable1 === void 0 ? void 0 : currentVariable1.value) !== undefined) {
|
|
191
238
|
draft[index] = {
|
|
@@ -210,10 +257,12 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , query
|
|
|
210
257
|
})));
|
|
211
258
|
return store;
|
|
212
259
|
}
|
|
213
|
-
export function TemplateVariableProvider({ children , initialVariableDefinitions =[] }) {
|
|
214
|
-
const
|
|
260
|
+
export function TemplateVariableProvider({ children , initialVariableDefinitions =[] , externalVariableDefinitions =[] }) {
|
|
261
|
+
const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);
|
|
262
|
+
const queryParams = useVariableQueryParams(allVariableDefs);
|
|
215
263
|
const [store] = useState(createTemplateVariableSrvStore({
|
|
216
264
|
initialVariableDefinitions,
|
|
265
|
+
externalVariableDefinitions,
|
|
217
266
|
queryParams
|
|
218
267
|
}));
|
|
219
268
|
return /*#__PURE__*/ _jsx(TemplateVariableStoreContext.Provider, {
|