@perses-dev/plugin-system 0.23.1 → 0.24.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/model/calculations.js +6 -1
- package/dist/cjs/model/index.js +2 -2
- package/dist/model/calculations.d.ts +1 -1
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +7 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/index.d.ts +2 -2
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +2 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +3 -4
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/components/CalculationSelector/CalculationSelector.test.js +0 -65
- package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -107
- package/dist/cjs/components/PluginEditor/PluginEditor.test.js +0 -150
- package/dist/cjs/components/PluginKindSelect.test.js +0 -86
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +0 -144
- package/dist/cjs/components/PluginSpecEditor.test.js +0 -92
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts +0 -2
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts.map +0 -1
- package/dist/components/CalculationSelector/CalculationSelector.test.js +0 -58
- package/dist/components/CalculationSelector/CalculationSelector.test.js.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts +0 -2
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -100
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.d.ts +0 -2
- package/dist/components/PluginEditor/PluginEditor.test.d.ts.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.js +0 -143
- package/dist/components/PluginEditor/PluginEditor.test.js.map +0 -1
- package/dist/components/PluginKindSelect.test.d.ts +0 -2
- package/dist/components/PluginKindSelect.test.d.ts.map +0 -1
- package/dist/components/PluginKindSelect.test.js +0 -79
- package/dist/components/PluginKindSelect.test.js.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +0 -2
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.js +0 -137
- package/dist/components/PluginRegistry/PluginRegistry.test.js.map +0 -1
- package/dist/components/PluginSpecEditor.test.d.ts +0 -2
- package/dist/components/PluginSpecEditor.test.d.ts.map +0 -1
- package/dist/components/PluginSpecEditor.test.js +0 -85
- package/dist/components/PluginSpecEditor.test.js.map +0 -1
|
@@ -73,5 +73,10 @@ function sum(values) {
|
|
|
73
73
|
return (0, _lodashEs.sumBy)(values, getValue);
|
|
74
74
|
}
|
|
75
75
|
function getValue(valueTuple) {
|
|
76
|
-
|
|
76
|
+
const value = valueTuple[1];
|
|
77
|
+
if (value !== null) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
// TODO: refactor utils so null can be returned and LastNotNull supported
|
|
81
|
+
return NaN;
|
|
77
82
|
}
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -18,10 +18,10 @@ _exportStar(require("./calculations"), exports);
|
|
|
18
18
|
_exportStar(require("./datasource"), exports);
|
|
19
19
|
_exportStar(require("./panels"), exports);
|
|
20
20
|
_exportStar(require("./plugins"), exports);
|
|
21
|
-
_exportStar(require("./time-series-queries"), exports);
|
|
22
|
-
_exportStar(require("./variables"), exports);
|
|
23
21
|
_exportStar(require("./plugin-base"), exports);
|
|
24
22
|
_exportStar(require("./plugin-loading"), exports);
|
|
23
|
+
_exportStar(require("./time-series-queries"), exports);
|
|
24
|
+
_exportStar(require("./variables"), exports);
|
|
25
25
|
function _exportStar(from, to) {
|
|
26
26
|
Object.keys(from).forEach(function(k) {
|
|
27
27
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,eAAO,MAAM,eAAe;;;;;;CAM3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAgB3E,CAAC;AAEX,eAAO,MAAM,mBAAmB,EAAE,eAAuB,CAAC;AAE1D,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGjE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAKhE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGtE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGhE;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAG/D"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { findLast, meanBy, sumBy } from 'lodash-es';
|
|
14
|
+
// TODO: move this file and calculations.test.ts to @perses-dev/core
|
|
14
15
|
export const CalculationsMap = {
|
|
15
16
|
First: first,
|
|
16
17
|
Last: last,
|
|
@@ -58,7 +59,12 @@ function sum(values) {
|
|
|
58
59
|
return sumBy(values, getValue);
|
|
59
60
|
}
|
|
60
61
|
function getValue(valueTuple) {
|
|
61
|
-
|
|
62
|
+
const value = valueTuple[1];
|
|
63
|
+
if (value !== null) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
// TODO: refactor utils so null can be returned and LastNotNull supported
|
|
67
|
+
return NaN;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
//# sourceMappingURL=calculations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { findLast, meanBy, sumBy } from 'lodash-es';\nimport { TimeSeriesValueTuple } from '
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { findLast, meanBy, sumBy } from 'lodash-es';\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\n// TODO: move this file and calculations.test.ts to @perses-dev/core\nexport const CalculationsMap = {\n First: first,\n Last: last,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n};\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n },\n Last: {\n label: 'Last',\n },\n LastNumber: {\n label: 'Last number',\n },\n Mean: {\n label: 'Mean',\n },\n Sum: {\n label: 'Sum',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\nfunction first(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = values[0];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction last(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n\n const tuple = values[values.length - 1];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = findLast(values, (tuple) => isNaN(getValue(tuple)) === false);\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return meanBy(values, getValue);\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return sumBy(values, getValue);\n}\n\nfunction getValue(valueTuple: TimeSeriesValueTuple) {\n const value = valueTuple[1];\n if (value !== null) {\n return value;\n }\n // TODO: refactor utils so null can be returned and LastNotNull supported\n return NaN;\n}\n"],"names":["findLast","meanBy","sumBy","CalculationsMap","First","first","Last","last","LastNumber","lastNumber","Mean","mean","Sum","sum","CALCULATIONS_CONFIG","label","DEFAULT_CALCULATION","values","tuple","undefined","getValue","length","isNaN","valueTuple","value","NaN"],"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,SAASA,QAAQ,EAAEC,MAAM,EAAEC,KAAK,QAAQ,WAAW,CAAC;AAGpD,oEAAoE;AACpE,OAAO,MAAMC,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;CACT,CAAC;AAOF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFV,KAAK,EAAE;QACLW,KAAK,EAAE,OAAO;KACf;IACDT,IAAI,EAAE;QACJS,KAAK,EAAE,MAAM;KACd;IACDP,UAAU,EAAE;QACVO,KAAK,EAAE,aAAa;KACrB;IACDL,IAAI,EAAE;QACJK,KAAK,EAAE,MAAM;KACd;IACDH,GAAG,EAAE;QACHG,KAAK,EAAE,KAAK;KACb;CACF,AAAS,CAAC;AAEX,OAAO,MAAMC,mBAAmB,GAAoB,KAAK,CAAC;AAE1D,SAASX,KAAK,CAACY,MAA8B,EAAsB;IACjE,MAAMC,KAAK,GAAGD,MAAM,CAAC,CAAC,CAAC,AAAC;IACxB,OAAOC,KAAK,KAAKC,SAAS,GAAGA,SAAS,GAAGC,QAAQ,CAACF,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,SAASX,IAAI,CAACU,MAA8B,EAAsB;IAChE,IAAIA,MAAM,CAACI,MAAM,IAAI,CAAC,EAAE,OAAOF,SAAS,CAAC;IAEzC,MAAMD,KAAK,GAAGD,MAAM,CAACA,MAAM,CAACI,MAAM,GAAG,CAAC,CAAC,AAAC;IACxC,OAAOH,KAAK,KAAKC,SAAS,GAAGA,SAAS,GAAGC,QAAQ,CAACF,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,SAAST,UAAU,CAACQ,MAA8B,EAAsB;IACtE,MAAMC,KAAK,GAAGlB,QAAQ,CAACiB,MAAM,EAAE,CAACC,KAAK,GAAKI,KAAK,CAACF,QAAQ,CAACF,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,AAAC;IAC5E,OAAOA,KAAK,KAAKC,SAAS,GAAGA,SAAS,GAAGC,QAAQ,CAACF,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,SAASP,IAAI,CAACM,MAA8B,EAAsB;IAChE,IAAIA,MAAM,CAACI,MAAM,IAAI,CAAC,EAAE,OAAOF,SAAS,CAAC;IACzC,OAAOlB,MAAM,CAACgB,MAAM,EAAEG,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,SAASP,GAAG,CAACI,MAA8B,EAAsB;IAC/D,IAAIA,MAAM,CAACI,MAAM,IAAI,CAAC,EAAE,OAAOF,SAAS,CAAC;IACzC,OAAOjB,KAAK,CAACe,MAAM,EAAEG,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,SAASA,QAAQ,CAACG,UAAgC,EAAE;IAClD,MAAMC,KAAK,GAAGD,UAAU,CAAC,CAAC,CAAC,AAAC;IAC5B,IAAIC,KAAK,KAAK,IAAI,EAAE;QAClB,OAAOA,KAAK,CAAC;IACf,CAAC;IACD,yEAAyE;IACzE,OAAOC,GAAG,CAAC;AACb,CAAC"}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from './calculations';
|
|
|
2
2
|
export * from './datasource';
|
|
3
3
|
export * from './panels';
|
|
4
4
|
export * from './plugins';
|
|
5
|
-
export * from './time-series-queries';
|
|
6
|
-
export * from './variables';
|
|
7
5
|
export * from './plugin-base';
|
|
8
6
|
export * from './plugin-loading';
|
|
7
|
+
export * from './time-series-queries';
|
|
8
|
+
export * from './variables';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
|
@@ -14,9 +14,9 @@ export * from './calculations';
|
|
|
14
14
|
export * from './datasource';
|
|
15
15
|
export * from './panels';
|
|
16
16
|
export * from './plugins';
|
|
17
|
-
export * from './time-series-queries';
|
|
18
|
-
export * from './variables';
|
|
19
17
|
export * from './plugin-base';
|
|
20
18
|
export * from './plugin-loading';
|
|
19
|
+
export * from './time-series-queries';
|
|
20
|
+
export * from './variables';
|
|
21
21
|
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './datasource';\nexport * from './panels';\nexport * from './plugins';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './datasource';\nexport * from './panels';\nexport * from './plugins';\nexport * from './plugin-base';\nexport * from './plugin-loading';\nexport * from './time-series-queries';\nexport * from './variables';\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,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbsoluteTimeRange,
|
|
1
|
+
import { AbsoluteTimeRange, TimeSeriesValueTuple, UnknownSpec } from '@perses-dev/core';
|
|
2
2
|
import { DatasourceStore, VariableStateMap } from '../runtime';
|
|
3
3
|
import { Plugin } from './plugin-base';
|
|
4
4
|
/**
|
|
@@ -30,13 +30,12 @@ export interface TimeSeriesQueryContext {
|
|
|
30
30
|
export interface TimeSeriesData {
|
|
31
31
|
timeRange?: AbsoluteTimeRange;
|
|
32
32
|
stepMs?: number;
|
|
33
|
-
series:
|
|
33
|
+
series: TimeSeries[];
|
|
34
34
|
}
|
|
35
35
|
export interface TimeSeries {
|
|
36
36
|
name: string;
|
|
37
|
-
values:
|
|
37
|
+
values: TimeSeriesValueTuple[];
|
|
38
38
|
formattedName?: string;
|
|
39
39
|
}
|
|
40
|
-
export declare type TimeSeriesValueTuple = [timestamp: UnixTimeMs, value: number];
|
|
41
40
|
export {};
|
|
42
41
|
//# sourceMappingURL=time-series-queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,aAAK,iCAAiC,GAAG;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC7E,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAExF,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,iCAAiC,CAAC;CAC5F;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange,
|
|
1
|
+
{"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeSeriesValueTuple, UnknownSpec } from '@perses-dev/core';\nimport { DatasourceStore, VariableStateMap } from '../runtime';\nimport { Plugin } from './plugin-base';\n\n/**\n * An object containing all the dependencies of a TimeSeriesQuery.\n */\ntype TimeSeriesQueryPluginDependencies = {\n /**\n * Returns a list of variables name this time series query depends on.\n */\n variables?: string[];\n};\n\n/**\n * A plugin for running time series queries.\n */\nexport interface TimeSeriesQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getTimeSeriesData: (spec: Spec, ctx: TimeSeriesQueryContext) => Promise<TimeSeriesData>;\n\n dependsOn?: (spec: Spec, ctx: TimeSeriesQueryContext) => TimeSeriesQueryPluginDependencies;\n}\n\n/**\n * Context available to TimeSeriesQuery plugins at runtime.\n */\nexport interface TimeSeriesQueryContext {\n suggestedStepMs?: number;\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n}\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,WA4CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "The plugin feature in Pereses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"build": "concurrently \"npm:build:*\"",
|
|
21
21
|
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
22
22
|
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
23
|
-
"build:types": "tsc --
|
|
23
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
24
25
|
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
25
26
|
"test": "TZ=UTC jest",
|
|
26
27
|
"lint": "eslint src --ext .ts,.tsx",
|
|
27
28
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@perses-dev/components": "0.
|
|
31
|
-
"@perses-dev/core": "0.
|
|
31
|
+
"@perses-dev/components": "0.24.0",
|
|
32
|
+
"@perses-dev/core": "0.24.0",
|
|
32
33
|
"immer": "^9.0.15",
|
|
33
34
|
"use-immer": "^0.7.0",
|
|
34
35
|
"use-query-params": "^2.1.2"
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _calculationSelector = require("./CalculationSelector");
|
|
21
|
-
function _interopRequireDefault(obj) {
|
|
22
|
-
return obj && obj.__esModule ? obj : {
|
|
23
|
-
default: obj
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('CalculationSelector', ()=>{
|
|
27
|
-
const renderCalculationSelector = (value, onChange = jest.fn())=>{
|
|
28
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_calculationSelector.CalculationSelector, {
|
|
30
|
-
value: value,
|
|
31
|
-
onChange: onChange
|
|
32
|
-
})
|
|
33
|
-
}));
|
|
34
|
-
};
|
|
35
|
-
const getCalculationSelector = ()=>{
|
|
36
|
-
return _react.screen.getByRole('combobox', {
|
|
37
|
-
name: 'Calculation'
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
it('can change the calculation by clicking', ()=>{
|
|
41
|
-
const onChange = jest.fn();
|
|
42
|
-
renderCalculationSelector('Last', onChange);
|
|
43
|
-
const calcSelector = getCalculationSelector();
|
|
44
|
-
_userEvent.default.click(calcSelector);
|
|
45
|
-
const sumOption = _react.screen.getByRole('option', {
|
|
46
|
-
name: 'Sum'
|
|
47
|
-
});
|
|
48
|
-
_userEvent.default.click(sumOption);
|
|
49
|
-
expect(onChange).toHaveBeenCalledWith('Sum');
|
|
50
|
-
});
|
|
51
|
-
it('can change the calculation using a keyboard', ()=>{
|
|
52
|
-
const onChange = jest.fn();
|
|
53
|
-
renderCalculationSelector('First', onChange);
|
|
54
|
-
const calcSelector = getCalculationSelector();
|
|
55
|
-
_userEvent.default.tab();
|
|
56
|
-
expect(calcSelector).toHaveFocus();
|
|
57
|
-
_userEvent.default.clear(calcSelector);
|
|
58
|
-
_userEvent.default.keyboard('first');
|
|
59
|
-
_react.screen.getByRole('option', {
|
|
60
|
-
name: 'First'
|
|
61
|
-
});
|
|
62
|
-
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
63
|
-
expect(onChange).toHaveBeenCalledWith('First');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _optionsEditorTabs = require("./OptionsEditorTabs");
|
|
21
|
-
function _interopRequireDefault(obj) {
|
|
22
|
-
return obj && obj.__esModule ? obj : {
|
|
23
|
-
default: obj
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('OptionsEditorTabs', ()=>{
|
|
27
|
-
const mockTabs = [
|
|
28
|
-
{
|
|
29
|
-
label: 'Query',
|
|
30
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
31
|
-
children: "Edit query configuration"
|
|
32
|
-
})
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
label: 'Settings',
|
|
36
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
37
|
-
children: "Edit settings configuration"
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
label: 'JSON',
|
|
42
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
43
|
-
children: "JSON editor"
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
const renderTabs = (otherTabs)=>{
|
|
48
|
-
const tabs = otherTabs !== null && otherTabs !== void 0 ? otherTabs : mockTabs;
|
|
49
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorTabs.OptionsEditorTabs, {
|
|
50
|
-
tabs: tabs
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
|
-
it('renders all specified tabs in a tab list', ()=>{
|
|
54
|
-
renderTabs();
|
|
55
|
-
const tabList = _react.screen.getByRole('tablist');
|
|
56
|
-
const tabs = (0, _react.getAllByRole)(tabList, 'tab');
|
|
57
|
-
expect(tabs).toHaveLength(3);
|
|
58
|
-
expect(tabs[0]).toHaveTextContent('Query');
|
|
59
|
-
expect(tabs[1]).toHaveTextContent('Settings');
|
|
60
|
-
expect(tabs[2]).toHaveTextContent('JSON');
|
|
61
|
-
});
|
|
62
|
-
it('defaults to selecting the first tab', ()=>{
|
|
63
|
-
renderTabs();
|
|
64
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
65
|
-
selected: true
|
|
66
|
-
});
|
|
67
|
-
expect(activeTab).toHaveTextContent('Query');
|
|
68
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
69
|
-
expect(activeTabPanel).toHaveTextContent('query configuration');
|
|
70
|
-
});
|
|
71
|
-
it('switches selected tab on click', ()=>{
|
|
72
|
-
renderTabs();
|
|
73
|
-
const jsonTab = _react.screen.getByRole('tab', {
|
|
74
|
-
name: 'JSON'
|
|
75
|
-
});
|
|
76
|
-
_userEvent.default.click(jsonTab);
|
|
77
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
78
|
-
selected: true
|
|
79
|
-
});
|
|
80
|
-
expect(activeTab).toBe(jsonTab);
|
|
81
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
82
|
-
expect(activeTabPanel).toHaveTextContent('JSON editor');
|
|
83
|
-
});
|
|
84
|
-
it('switches selected tab on keyboard interactions', ()=>{
|
|
85
|
-
renderTabs();
|
|
86
|
-
const vizTab = _react.screen.getByRole('tab', {
|
|
87
|
-
name: 'Settings'
|
|
88
|
-
});
|
|
89
|
-
_userEvent.default.tab();
|
|
90
|
-
_userEvent.default.keyboard('{arrowright}{space}');
|
|
91
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
92
|
-
selected: true
|
|
93
|
-
});
|
|
94
|
-
expect(activeTab).toBe(vizTab);
|
|
95
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
96
|
-
expect(activeTabPanel).toHaveTextContent('settings configuration');
|
|
97
|
-
});
|
|
98
|
-
it('renders tabs in correct order', ()=>{
|
|
99
|
-
renderTabs();
|
|
100
|
-
const tabList = _react.screen.getByRole('tablist');
|
|
101
|
-
const tabs = (0, _react.getAllByRole)(tabList, 'tab');
|
|
102
|
-
expect(tabs).toHaveLength(3);
|
|
103
|
-
expect(tabs[0]).toHaveTextContent('Query');
|
|
104
|
-
expect(tabs[1]).toHaveTextContent('Settings');
|
|
105
|
-
expect(tabs[2]).toHaveTextContent('JSON');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
19
|
-
const _react = require("@testing-library/react");
|
|
20
|
-
const _react1 = require("react");
|
|
21
|
-
const _test = require("../../test");
|
|
22
|
-
const _pluginEditor = require("./PluginEditor");
|
|
23
|
-
function _interopRequireDefault(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
describe('PluginEditor', ()=>{
|
|
29
|
-
const renderComponent = ({ pluginType ='Panel' , defaultPluginKinds , value } = {})=>{
|
|
30
|
-
const testValue = value || {
|
|
31
|
-
kind: 'BertPanel1',
|
|
32
|
-
spec: {
|
|
33
|
-
option1: 'Option1Value'
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// A test helper component that includes the state that's controlled from outside
|
|
37
|
-
let onChange = jest.fn();
|
|
38
|
-
function TestHelperForm() {
|
|
39
|
-
const [value, setValue] = (0, _react1.useState)(testValue);
|
|
40
|
-
onChange = jest.fn((v)=>setValue(v));
|
|
41
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginEditor.PluginEditor, {
|
|
42
|
-
pluginType: pluginType,
|
|
43
|
-
pluginKindLabel: "Panel Type",
|
|
44
|
-
value: value,
|
|
45
|
-
onChange: onChange
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(TestHelperForm, {}), undefined, {
|
|
49
|
-
defaultPluginKinds
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
onChange
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
// Opens the PluginKindSelect and waits for loading to finish (i.e. options to appear)
|
|
56
|
-
const openPluginKind = async ()=>{
|
|
57
|
-
const select = _react.screen.getByRole('button', {
|
|
58
|
-
name: 'Panel Type'
|
|
59
|
-
});
|
|
60
|
-
_userEvent.default.click(select);
|
|
61
|
-
const options = await _react.screen.findAllByRole('option');
|
|
62
|
-
return options;
|
|
63
|
-
};
|
|
64
|
-
it('shows plugin kind and spec editor', async ()=>{
|
|
65
|
-
renderComponent();
|
|
66
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
67
|
-
name: 'Panel Type'
|
|
68
|
-
});
|
|
69
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 1'));
|
|
70
|
-
const specEditor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
71
|
-
expect(specEditor).toHaveValue('Option1Value');
|
|
72
|
-
});
|
|
73
|
-
it('initializes kind and spec together', async ()=>{
|
|
74
|
-
const { onChange } = renderComponent();
|
|
75
|
-
// Switch to a new plugin kind
|
|
76
|
-
await openPluginKind();
|
|
77
|
-
const newPluginKind = _react.screen.getByRole('option', {
|
|
78
|
-
name: 'Bert Panel 2'
|
|
79
|
-
});
|
|
80
|
-
_userEvent.default.click(newPluginKind);
|
|
81
|
-
// Wait for the editor of the other plugin
|
|
82
|
-
const newEditor = await _react.screen.findByLabelText('BertPanel2 editor');
|
|
83
|
-
expect(newEditor).toBeInTheDocument();
|
|
84
|
-
expect(newEditor).toHaveValue('');
|
|
85
|
-
// Make sure onChange was only called once (i.e. initializes both kind and spec at the same time
|
|
86
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
87
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
88
|
-
kind: 'BertPanel2',
|
|
89
|
-
spec: {
|
|
90
|
-
option2: ''
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it('remembers previous spec values', async ()=>{
|
|
95
|
-
renderComponent();
|
|
96
|
-
// Use the current editor to make a change to the spec value
|
|
97
|
-
let editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
98
|
-
_userEvent.default.clear(editor);
|
|
99
|
-
_userEvent.default.type(editor, 'MyNewValue');
|
|
100
|
-
// Switch to a new plugin kind
|
|
101
|
-
await openPluginKind();
|
|
102
|
-
const newPluginKind = _react.screen.getByRole('option', {
|
|
103
|
-
name: 'Bert Panel 2'
|
|
104
|
-
});
|
|
105
|
-
_userEvent.default.click(newPluginKind);
|
|
106
|
-
// Wait for the other editor to appear, then switch back
|
|
107
|
-
const newEditor = await _react.screen.findByLabelText('BertPanel2 editor');
|
|
108
|
-
expect(newEditor).toHaveValue('');
|
|
109
|
-
await openPluginKind();
|
|
110
|
-
const oldPluginKind = _react.screen.getByRole('option', {
|
|
111
|
-
name: 'Bert Panel 1'
|
|
112
|
-
});
|
|
113
|
-
_userEvent.default.click(oldPluginKind);
|
|
114
|
-
// Make sure the editor from the first plugin appears and has our modified value from before the switch
|
|
115
|
-
editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
116
|
-
expect(editor).toHaveValue('MyNewValue');
|
|
117
|
-
});
|
|
118
|
-
describe('when defaultPluginKinds specified in plugin registry', ()=>{
|
|
119
|
-
it('uses default kind when one is not provided', async ()=>{
|
|
120
|
-
renderComponent({
|
|
121
|
-
pluginType: 'Panel',
|
|
122
|
-
defaultPluginKinds: {
|
|
123
|
-
Panel: 'BertPanel2'
|
|
124
|
-
},
|
|
125
|
-
value: {
|
|
126
|
-
kind: '',
|
|
127
|
-
spec: {}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
// Wait for default panel kind to load.
|
|
131
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
132
|
-
name: 'Panel Type'
|
|
133
|
-
});
|
|
134
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 2'));
|
|
135
|
-
});
|
|
136
|
-
it('does not use default when kind is provided', async ()=>{
|
|
137
|
-
renderComponent({
|
|
138
|
-
pluginType: 'Panel',
|
|
139
|
-
defaultPluginKinds: {
|
|
140
|
-
Panel: 'BertPanel2'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
// Wait for specified panel kind to load.
|
|
144
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
145
|
-
name: 'Panel Type'
|
|
146
|
-
});
|
|
147
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 1'));
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
19
|
-
const _react = require("@testing-library/react");
|
|
20
|
-
const _test = require("../test");
|
|
21
|
-
const _pluginKindSelect = require("./PluginKindSelect");
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : {
|
|
24
|
-
default: obj
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('PluginKindSelect', ()=>{
|
|
28
|
-
const renderComponent = (props)=>{
|
|
29
|
-
return (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginKindSelect.PluginKindSelect, {
|
|
30
|
-
...props
|
|
31
|
-
}));
|
|
32
|
-
};
|
|
33
|
-
// Opens the select and waits for loading to finish (i.e. options to appear)
|
|
34
|
-
const openSelect = async ()=>{
|
|
35
|
-
const select = _react.screen.getByRole('button');
|
|
36
|
-
_userEvent.default.click(select);
|
|
37
|
-
const options = await _react.screen.findAllByRole('option');
|
|
38
|
-
return options;
|
|
39
|
-
};
|
|
40
|
-
it('displays the list of plugins for a plugin type', async ()=>{
|
|
41
|
-
renderComponent({
|
|
42
|
-
pluginType: 'Panel',
|
|
43
|
-
value: ''
|
|
44
|
-
});
|
|
45
|
-
// Open the select and verify the list of options from the test plugin data
|
|
46
|
-
const options = await openSelect();
|
|
47
|
-
expect(options).toHaveLength(2);
|
|
48
|
-
let option = _react.screen.queryByRole('option', {
|
|
49
|
-
name: 'Bert Panel 1'
|
|
50
|
-
});
|
|
51
|
-
expect(option).toBeInTheDocument();
|
|
52
|
-
option = _react.screen.queryByRole('option', {
|
|
53
|
-
name: 'Bert Panel 2'
|
|
54
|
-
});
|
|
55
|
-
expect(option).toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
it('shows the correct selected value', async ()=>{
|
|
58
|
-
renderComponent({
|
|
59
|
-
pluginType: 'Variable',
|
|
60
|
-
value: 'ErnieVariable'
|
|
61
|
-
});
|
|
62
|
-
// Use findByRole to wait for loading to finish and selected value to appear
|
|
63
|
-
const select = await _react.screen.findByRole('button', {
|
|
64
|
-
name: 'Ernie Variable'
|
|
65
|
-
});
|
|
66
|
-
expect(select).toBeInTheDocument();
|
|
67
|
-
});
|
|
68
|
-
it('can select new value', async ()=>{
|
|
69
|
-
let onChangeValue = undefined;
|
|
70
|
-
const onChange = jest.fn((e)=>{
|
|
71
|
-
onChangeValue = e.target.value;
|
|
72
|
-
});
|
|
73
|
-
renderComponent({
|
|
74
|
-
pluginType: 'Variable',
|
|
75
|
-
value: 'ErnieVariable',
|
|
76
|
-
onChange
|
|
77
|
-
});
|
|
78
|
-
await openSelect();
|
|
79
|
-
const newOption = _react.screen.getByRole('option', {
|
|
80
|
-
name: 'Bert Variable'
|
|
81
|
-
});
|
|
82
|
-
_userEvent.default.click(newOption);
|
|
83
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
84
|
-
expect(onChangeValue).toBe('BertVariable');
|
|
85
|
-
});
|
|
86
|
-
});
|