@perses-dev/plugin-system 0.34.0 → 0.35.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.
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "CalculationSelector", {
19
19
  get: ()=>CalculationSelector
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _material = require("@mui/material");
23
22
  const _components = require("@perses-dev/components");
24
23
  const _core = require("@perses-dev/core");
25
24
  const CALC_OPTIONS = Object.entries(_core.CALCULATIONS_CONFIG).map(([id, config])=>{
@@ -35,16 +34,12 @@ function CalculationSelector({ value , onChange }) {
35
34
  const calcConfig = _core.CALCULATIONS_CONFIG[value];
36
35
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
37
36
  label: "Calculation",
38
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
37
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
39
38
  value: {
40
39
  ...calcConfig,
41
40
  id: value
42
41
  },
43
42
  options: CALC_OPTIONS,
44
- isOptionEqualToValue: (option, value)=>option.id === value.id,
45
- renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
46
- ...params
47
- }),
48
43
  onChange: handleCalculationChange,
49
44
  disableClearable: true
50
45
  })
@@ -35,6 +35,12 @@ const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config]
35
35
  ...config
36
36
  };
37
37
  });
38
+ const VALUE_OPTIONS = Object.entries(_model.LEGEND_VALUE_CONFIG).map(([id, config])=>{
39
+ return {
40
+ id: id,
41
+ ...config
42
+ };
43
+ });
38
44
  function LegendOptionsEditor({ value , onChange }) {
39
45
  const handleLegendShowChange = (_, checked)=>{
40
46
  // legend is hidden when legend obj is undefined
@@ -56,11 +62,31 @@ function LegendOptionsEditor({ value , onChange }) {
56
62
  mode: newValue.id
57
63
  });
58
64
  };
65
+ const handleLegendValueChange = (_, newValue)=>{
66
+ onChange({
67
+ ...value,
68
+ position: currentPosition,
69
+ values: newValue.map((value)=>{
70
+ return value.id;
71
+ })
72
+ });
73
+ };
59
74
  const isValidLegend = (0, _model.validateLegendSpec)(value);
60
75
  const currentPosition = (0, _core.getLegendPosition)(value === null || value === void 0 ? void 0 : value.position);
61
76
  const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
62
77
  const currentMode = (0, _core.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
63
78
  const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
79
+ const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
80
+ const legendValuesConfig = currentValues.reduce((result, item)=>{
81
+ const config = _model.LEGEND_VALUE_CONFIG[item];
82
+ if (config) {
83
+ result.push({
84
+ ...config,
85
+ id: item
86
+ });
87
+ }
88
+ return result;
89
+ }, []);
64
90
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
65
91
  children: [
66
92
  !isValidLegend && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorAlert, {
@@ -78,16 +104,12 @@ function LegendOptionsEditor({ value , onChange }) {
78
104
  }),
79
105
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
80
106
  label: "Position",
81
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
107
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
82
108
  value: {
83
109
  ...legendPositionConfig,
84
110
  id: currentPosition
85
111
  },
86
112
  options: POSITION_OPTIONS,
87
- isOptionEqualToValue: (option, value)=>option.id === value.id,
88
- renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
89
- ...params
90
- }),
91
113
  onChange: handleLegendPositionChange,
92
114
  disabled: value === undefined,
93
115
  disableClearable: true
@@ -95,20 +117,36 @@ function LegendOptionsEditor({ value , onChange }) {
95
117
  }),
96
118
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
97
119
  label: "Mode",
98
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
120
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
99
121
  value: {
100
122
  ...legendModeConfig,
101
123
  id: currentMode
102
124
  },
103
125
  options: MODE_OPTIONS,
104
- isOptionEqualToValue: (option, value)=>option.id === value.id,
105
- renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
106
- ...params
107
- }),
108
126
  onChange: handleLegendModeChange,
109
127
  disabled: value === undefined,
110
128
  disableClearable: true
111
129
  })
130
+ }),
131
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
132
+ label: "Values",
133
+ description: "Computed values ignore nulls.",
134
+ control: // For some reason, the inferred option type doesn't always seem to work
135
+ // quite right when `multiple` is true. Explicitly setting the generics
136
+ // to work around this.
137
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
138
+ multiple: true,
139
+ disableCloseOnSelect: true,
140
+ disableClearable: true,
141
+ value: legendValuesConfig,
142
+ options: VALUE_OPTIONS,
143
+ onChange: handleLegendValueChange,
144
+ disabled: value === undefined || currentMode !== 'Table',
145
+ limitTags: 1,
146
+ ChipProps: {
147
+ size: 'small'
148
+ }
149
+ })
112
150
  })
113
151
  ]
114
152
  });
@@ -21,11 +21,23 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ legendValues: ()=>legendValues,
24
25
  LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
25
26
  LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
27
+ LEGEND_VALUE_CONFIG: ()=>LEGEND_VALUE_CONFIG,
26
28
  validateLegendSpec: ()=>validateLegendSpec
27
29
  });
28
30
  const _core = require("@perses-dev/core");
31
+ const legendValues = [
32
+ 'Mean',
33
+ 'First',
34
+ 'FirstNumber',
35
+ 'Last',
36
+ 'LastNumber',
37
+ 'Min',
38
+ 'Max',
39
+ 'Sum'
40
+ ];
29
41
  const LEGEND_POSITIONS_CONFIG = {
30
42
  Bottom: {
31
43
  label: 'Bottom'
@@ -42,6 +54,10 @@ const LEGEND_MODE_CONFIG = {
42
54
  label: 'Table'
43
55
  }
44
56
  };
57
+ const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
58
+ config[value] = _core.CALCULATIONS_CONFIG[value];
59
+ return config;
60
+ }, {});
45
61
  function validateLegendSpec(legend) {
46
62
  if (legend === undefined) {
47
63
  // undefined is valid since this is how legend is hidden by default
@@ -1 +1 @@
1
- {"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":";AAeA,OAAO,EAA0C,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAU3F,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAyBhF"}
1
+ {"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":";AAcA,OAAO,EAA0C,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAU3F,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAuBhF"}
@@ -11,8 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { TextField, Autocomplete } from '@mui/material';
15
- import { OptionsEditorControl } from '@perses-dev/components';
14
+ import { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';
16
15
  import { CALCULATIONS_CONFIG } from '@perses-dev/core';
17
16
  const CALC_OPTIONS = Object.entries(CALCULATIONS_CONFIG).map(([id, config])=>{
18
17
  return {
@@ -27,16 +26,12 @@ export function CalculationSelector({ value , onChange }) {
27
26
  const calcConfig = CALCULATIONS_CONFIG[value];
28
27
  return /*#__PURE__*/ _jsx(OptionsEditorControl, {
29
28
  label: "Calculation",
30
- control: /*#__PURE__*/ _jsx(Autocomplete, {
29
+ control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
31
30
  value: {
32
31
  ...calcConfig,
33
32
  id: value
34
33
  },
35
34
  options: CALC_OPTIONS,
36
- isOptionEqualToValue: (option, value)=>option.id === value.id,
37
- renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
38
- ...params
39
- }),
40
35
  onChange: handleCalculationChange,
41
36
  disableClearable: true
42
37
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { TextField, Autocomplete } from '@mui/material';\nimport { OptionsEditorControl } from '@perses-dev/components';\nimport { CALCULATIONS_CONFIG, CalculationConfig, CalculationType } from '@perses-dev/core';\n\ntype AutocompleteCalculationOption = CalculationConfig & { id: CalculationType };\nconst CALC_OPTIONS: AutocompleteCalculationOption[] = Object.entries(CALCULATIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as CalculationType,\n ...config,\n };\n});\n\nexport interface CalculationSelectorProps {\n value: CalculationType;\n onChange: (unit: CalculationType) => void;\n}\n\nexport function CalculationSelector({ value, onChange }: CalculationSelectorProps) {\n const handleCalculationChange = (_: unknown, newValue: AutocompleteCalculationOption) => {\n onChange(newValue.id);\n };\n\n const calcConfig = CALCULATIONS_CONFIG[value];\n\n return (\n <OptionsEditorControl\n label=\"Calculation\"\n control={\n <Autocomplete\n value={{\n ...calcConfig,\n id: value,\n }}\n options={CALC_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleCalculationChange}\n disableClearable\n ></Autocomplete>\n }\n />\n );\n}\n"],"names":["TextField","Autocomplete","OptionsEditorControl","CALCULATIONS_CONFIG","CALC_OPTIONS","Object","entries","map","id","config","CalculationSelector","value","onChange","handleCalculationChange","_","newValue","calcConfig","label","control","options","isOptionEqualToValue","option","renderInput","params","disableClearable"],"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,SAAS,EAAEC,YAAY,QAAQ,eAAe,CAAC;AACxD,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAC9D,SAASC,mBAAmB,QAA4C,kBAAkB,CAAC;AAG3F,MAAMC,YAAY,GAAoCC,MAAM,CAACC,OAAO,CAACH,mBAAmB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC9G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAOH,OAAO,SAASC,mBAAmB,CAAC,EAAEC,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAA4B,EAAE;IACjF,MAAMC,uBAAuB,GAAG,CAACC,CAAU,EAAEC,QAAuC,GAAK;QACvFH,QAAQ,CAACG,QAAQ,CAACP,EAAE,CAAC,CAAC;IACxB,CAAC,AAAC;IAEF,MAAMQ,UAAU,GAAGb,mBAAmB,CAACQ,KAAK,CAAC,AAAC;IAE9C,qBACE,KAACT,oBAAoB;QACnBe,KAAK,EAAC,aAAa;QACnBC,OAAO,gBACL,KAACjB,YAAY;YACXU,KAAK,EAAE;gBACL,GAAGK,UAAU;gBACbR,EAAE,EAAEG,KAAK;aACV;YACDQ,OAAO,EAAEf,YAAY;YACrBgB,oBAAoB,EAAE,CAACC,MAAM,EAAEV,KAAK,GAAKU,MAAM,CAACb,EAAE,KAAKG,KAAK,CAACH,EAAE;YAC/Dc,WAAW,EAAE,CAACC,MAAM,iBAAK,KAACvB,SAAS;oBAAE,GAAGuB,MAAM;kBAAI;YAClDX,QAAQ,EAAEC,uBAAuB;YACjCW,gBAAgB;UACF;MAElB,CACF;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport { CALCULATIONS_CONFIG, CalculationConfig, CalculationType } from '@perses-dev/core';\n\ntype AutocompleteCalculationOption = CalculationConfig & { id: CalculationType };\nconst CALC_OPTIONS: AutocompleteCalculationOption[] = Object.entries(CALCULATIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as CalculationType,\n ...config,\n };\n});\n\nexport interface CalculationSelectorProps {\n value: CalculationType;\n onChange: (unit: CalculationType) => void;\n}\n\nexport function CalculationSelector({ value, onChange }: CalculationSelectorProps) {\n const handleCalculationChange = (_: unknown, newValue: AutocompleteCalculationOption) => {\n onChange(newValue.id);\n };\n\n const calcConfig = CALCULATIONS_CONFIG[value];\n\n return (\n <OptionsEditorControl\n label=\"Calculation\"\n control={\n <SettingsAutocomplete\n value={{\n ...calcConfig,\n id: value,\n }}\n options={CALC_OPTIONS}\n onChange={handleCalculationChange}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n );\n}\n"],"names":["OptionsEditorControl","SettingsAutocomplete","CALCULATIONS_CONFIG","CALC_OPTIONS","Object","entries","map","id","config","CalculationSelector","value","onChange","handleCalculationChange","_","newValue","calcConfig","label","control","options","disableClearable"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,oBAAoB,EAAEC,oBAAoB,QAAQ,wBAAwB,CAAC;AACpF,SAASC,mBAAmB,QAA4C,kBAAkB,CAAC;AAG3F,MAAMC,YAAY,GAAoCC,MAAM,CAACC,OAAO,CAACH,mBAAmB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC9G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAOH,OAAO,SAASC,mBAAmB,CAAC,EAAEC,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAA4B,EAAE;IACjF,MAAMC,uBAAuB,GAAG,CAACC,CAAU,EAAEC,QAAuC,GAAK;QACvFH,QAAQ,CAACG,QAAQ,CAACP,EAAE,CAAC,CAAC;IACxB,CAAC,AAAC;IAEF,MAAMQ,UAAU,GAAGb,mBAAmB,CAACQ,KAAK,CAAC,AAAC;IAE9C,qBACE,KAACV,oBAAoB;QACnBgB,KAAK,EAAC,aAAa;QACnBC,OAAO,gBACL,KAAChB,oBAAoB;YACnBS,KAAK,EAAE;gBACL,GAAGK,UAAU;gBACbR,EAAE,EAAEG,KAAK;aACV;YACDQ,OAAO,EAAEf,YAAY;YACrBQ,QAAQ,EAAEC,uBAAuB;YACjCO,gBAAgB;UACM;MAE1B,CACF;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAGL,iBAAiB,EAGlB,MAAM,aAAa,CAAC;AAoBrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAwEhF"}
1
+ {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAGL,iBAAiB,EAKlB,MAAM,aAAa,CAAC;AA4BrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eA6GhF"}
@@ -11,10 +11,10 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { Autocomplete, Switch, TextField } from '@mui/material';
14
+ import { Switch } from '@mui/material';
15
15
  import { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';
16
- import { ErrorAlert, OptionsEditorControl } from '@perses-dev/components';
17
- import { LEGEND_MODE_CONFIG, LEGEND_POSITIONS_CONFIG, validateLegendSpec } from '../../model';
16
+ import { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';
17
+ import { LEGEND_MODE_CONFIG, LEGEND_POSITIONS_CONFIG, validateLegendSpec, LEGEND_VALUE_CONFIG } from '../../model';
18
18
  const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
19
19
  return {
20
20
  id: id,
@@ -27,6 +27,12 @@ const MODE_OPTIONS = Object.entries(LEGEND_MODE_CONFIG).map(([id, config])=>{
27
27
  ...config
28
28
  };
29
29
  });
30
+ const VALUE_OPTIONS = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config])=>{
31
+ return {
32
+ id: id,
33
+ ...config
34
+ };
35
+ });
30
36
  export function LegendOptionsEditor({ value , onChange }) {
31
37
  const handleLegendShowChange = (_, checked)=>{
32
38
  // legend is hidden when legend obj is undefined
@@ -48,11 +54,31 @@ export function LegendOptionsEditor({ value , onChange }) {
48
54
  mode: newValue.id
49
55
  });
50
56
  };
57
+ const handleLegendValueChange = (_, newValue)=>{
58
+ onChange({
59
+ ...value,
60
+ position: currentPosition,
61
+ values: newValue.map((value)=>{
62
+ return value.id;
63
+ })
64
+ });
65
+ };
51
66
  const isValidLegend = validateLegendSpec(value);
52
67
  const currentPosition = getLegendPosition(value === null || value === void 0 ? void 0 : value.position);
53
68
  const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];
54
69
  const currentMode = getLegendMode(value === null || value === void 0 ? void 0 : value.mode);
55
70
  const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];
71
+ const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
72
+ const legendValuesConfig = currentValues.reduce((result, item)=>{
73
+ const config = LEGEND_VALUE_CONFIG[item];
74
+ if (config) {
75
+ result.push({
76
+ ...config,
77
+ id: item
78
+ });
79
+ }
80
+ return result;
81
+ }, []);
56
82
  return /*#__PURE__*/ _jsxs(_Fragment, {
57
83
  children: [
58
84
  !isValidLegend && /*#__PURE__*/ _jsx(ErrorAlert, {
@@ -70,16 +96,12 @@ export function LegendOptionsEditor({ value , onChange }) {
70
96
  }),
71
97
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
72
98
  label: "Position",
73
- control: /*#__PURE__*/ _jsx(Autocomplete, {
99
+ control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
74
100
  value: {
75
101
  ...legendPositionConfig,
76
102
  id: currentPosition
77
103
  },
78
104
  options: POSITION_OPTIONS,
79
- isOptionEqualToValue: (option, value)=>option.id === value.id,
80
- renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
81
- ...params
82
- }),
83
105
  onChange: handleLegendPositionChange,
84
106
  disabled: value === undefined,
85
107
  disableClearable: true
@@ -87,20 +109,36 @@ export function LegendOptionsEditor({ value , onChange }) {
87
109
  }),
88
110
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
89
111
  label: "Mode",
90
- control: /*#__PURE__*/ _jsx(Autocomplete, {
112
+ control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
91
113
  value: {
92
114
  ...legendModeConfig,
93
115
  id: currentMode
94
116
  },
95
117
  options: MODE_OPTIONS,
96
- isOptionEqualToValue: (option, value)=>option.id === value.id,
97
- renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
98
- ...params
99
- }),
100
118
  onChange: handleLegendModeChange,
101
119
  disabled: value === undefined,
102
120
  disableClearable: true
103
121
  })
122
+ }),
123
+ /*#__PURE__*/ _jsx(OptionsEditorControl, {
124
+ label: "Values",
125
+ description: "Computed values ignore nulls.",
126
+ control: // For some reason, the inferred option type doesn't always seem to work
127
+ // quite right when `multiple` is true. Explicitly setting the generics
128
+ // to work around this.
129
+ /*#__PURE__*/ _jsx(SettingsAutocomplete, {
130
+ multiple: true,
131
+ disableCloseOnSelect: true,
132
+ disableClearable: true,
133
+ value: legendValuesConfig,
134
+ options: VALUE_OPTIONS,
135
+ onChange: handleLegendValueChange,
136
+ disabled: value === undefined || currentMode !== 'Table',
137
+ limitTags: 1,
138
+ ChipProps: {
139
+ size: 'small'
140
+ }
141
+ })
104
142
  })
105
143
  ]
106
144
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Autocomplete, Switch, SwitchProps, TextField } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl } from '@perses-dev/components';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: LegendSpecOptions['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['mode'],\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n return (\n <>\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <Autocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></Autocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <Autocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleLegendModeChange}\n disabled={value === undefined}\n disableClearable\n ></Autocomplete>\n }\n />\n </>\n );\n}\n"],"names":["Autocomplete","Switch","TextField","DEFAULT_LEGEND","getLegendMode","getLegendPosition","ErrorAlert","OptionsEditorControl","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","error","name","message","label","control","options","isOptionEqualToValue","option","renderInput","params","disabled","disableClearable"],"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,YAAY,EAAEC,MAAM,EAAeC,SAAS,QAAQ,eAAe,CAAC;AAC7E,SAASC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AACpF,SAASC,UAAU,EAAEC,oBAAoB,QAAQ,wBAAwB,CAAC;AAC1E,SACEC,kBAAkB,EAClBC,uBAAuB,EAGvBC,kBAAkB,QACb,aAAa,CAAC;AAIrB,MAAMC,gBAAgB,GAA2BC,MAAM,CAACC,OAAO,CAACJ,uBAAuB,CAAC,CAACK,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC7G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAIH,MAAMC,YAAY,GAAuBL,MAAM,CAACC,OAAO,CAACL,kBAAkB,CAAC,CAACM,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAChG,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AA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CAAC"}
1
+ {"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Switch, SwitchProps } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n LEGEND_VALUE_CONFIG,\n LegendValue,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['mode'],\n ...config,\n };\n});\n\ntype LegendValueOption = LegendSingleSelectConfig & { id: LegendValue };\nconst VALUE_OPTIONS: LegendValueOption[] = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendValue,\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const handleLegendValueChange = (_: unknown, newValue: LegendValueOption[]) => {\n onChange({\n ...value,\n position: currentPosition,\n values: newValue.map((value) => {\n return value.id;\n }),\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n const currentValues = value?.values || [];\n const legendValuesConfig = currentValues.reduce((result, item) => {\n const config = LEGEND_VALUE_CONFIG[item];\n if (config) {\n result.push({ ...config, id: item });\n }\n return result;\n }, [] as LegendValueOption[]);\n\n return (\n <>\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n onChange={handleLegendModeChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Values\"\n description=\"Computed values ignore nulls.\"\n control={\n // For some reason, the inferred option type doesn't always seem to work\n // quite right when `multiple` is true. Explicitly setting the generics\n // to work around this.\n <SettingsAutocomplete<LegendValueOption, true, true>\n multiple={true}\n disableCloseOnSelect\n disableClearable\n value={legendValuesConfig}\n options={VALUE_OPTIONS}\n onChange={handleLegendValueChange}\n disabled={value === undefined || currentMode !== 'Table'}\n limitTags={1}\n ChipProps={{\n size: 'small',\n }}\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","DEFAULT_LEGEND","getLegendMode","getLegendPosition","ErrorAlert","OptionsEditorControl","SettingsAutocomplete","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","LEGEND_VALUE_CONFIG","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","VALUE_OPTIONS","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","handleLegendValueChange","values","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","currentValues","legendValuesConfig","reduce","result","item","push","error","name","message","label","control","options","disabled","disableClearable","description","multiple","disableCloseOnSelect","limitTags","ChipProps","size"],"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,MAAM,QAAqB,eAAe,CAAC;AACpD,SAASC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AACpF,SAASC,UAAU,EAAEC,oBAAoB,EAAEC,oBAAoB,QAAQ,wBAAwB,CAAC;AAChG,SACEC,kBAAkB,EAClBC,uBAAuB,EAGvBC,kBAAkB,EAClBC,mBAAmB,QAEd,aAAa,CAAC;AAIrB,MAAMC,gBA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BAAgB;oBAChBhC,KAAK,EAAEoB,kBAAkB;oBACzBU,OAAO,EAAEhC,aAAa;oBACtBG,QAAQ,EAAEY,uBAAuB;oBACjCkB,QAAQ,EAAE/B,KAAK,KAAKO,SAAS,IAAIU,WAAW,KAAK,OAAO;oBACxDmB,SAAS,EAAE,CAAC;oBACZC,SAAS,EAAE;wBACTC,IAAI,EAAE,OAAO;qBACd;kBACD;cAEJ;;MACD,CACH;AACJ,CAAC"}
@@ -1,9 +1,15 @@
1
- import { LegendMode, LegendOptionsBase, LegendPositions } from '@perses-dev/core';
2
- export declare type LegendSpecOptions = LegendOptionsBase;
1
+ import { CalculationType, LegendMode, LegendOptionsBase, LegendPositions } from '@perses-dev/core';
2
+ export declare const legendValues: CalculationType[];
3
+ export declare type LegendValue = (typeof legendValues)[number];
4
+ export interface LegendSpecOptions extends LegendOptionsBase {
5
+ values?: LegendValue[];
6
+ }
3
7
  export declare type LegendSingleSelectConfig = {
4
8
  label: string;
9
+ description?: string;
5
10
  };
6
11
  export declare const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>>;
7
12
  export declare const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>>;
13
+ export declare const LEGEND_VALUE_CONFIG: Partial<Record<"First" | "Last" | "FirstNumber" | "LastNumber" | "Mean" | "Sum" | "Min" | "Max", LegendSingleSelectConfig>>;
8
14
  export declare function validateLegendSpec(legend?: LegendOptionsBase): boolean;
9
15
  //# sourceMappingURL=legend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAS1B,oBAAY,iBAAiB,GAAG,iBAAiB,CAAC;AAElD,oBAAY,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAG/F,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAGrF,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,iBAAiB,WAa5D"}
1
+ {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAU1B,eAAO,MAAM,YAAY,EAAE,eAAe,EASzC,CAAC;AACF,oBAAY,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAKxD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,oBAAY,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAG/F,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAGrF,CAAC;AAEF,eAAO,MAAM,mBAAmB,6HAIgC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,iBAAiB,WAa5D"}
@@ -10,7 +10,24 @@
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 { isValidLegendMode, isValidLegendPosition } from '@perses-dev/core';
13
+ import { CALCULATIONS_CONFIG, isValidLegendMode, isValidLegendPosition } from '@perses-dev/core';
14
+ // This file contains legend-related model code specific to panel plugin specs.
15
+ // See the `core` package for common/shared legend model code and the
16
+ // `components` package for legend model code specific to the Legend component.
17
+ // Explicity listing the calculations we intend to use for legend values because
18
+ // we want them ordered in a specific way, and it may be possible in the future
19
+ // that we only use a subset of calculations for the legend because the calculations
20
+ // are also used by other features.
21
+ export const legendValues = [
22
+ 'Mean',
23
+ 'First',
24
+ 'FirstNumber',
25
+ 'Last',
26
+ 'LastNumber',
27
+ 'Min',
28
+ 'Max',
29
+ 'Sum'
30
+ ];
14
31
  export const LEGEND_POSITIONS_CONFIG = {
15
32
  Bottom: {
16
33
  label: 'Bottom'
@@ -27,6 +44,10 @@ export const LEGEND_MODE_CONFIG = {
27
44
  label: 'Table'
28
45
  }
29
46
  };
47
+ export const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
48
+ config[value] = CALCULATIONS_CONFIG[value];
49
+ return config;
50
+ }, {});
30
51
  export function validateLegendSpec(legend) {
31
52
  if (legend === undefined) {
32
53
  // undefined is valid since this is how legend is hidden by default
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/legend.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 {\n LegendMode,\n LegendOptionsBase,\n LegendPositions,\n isValidLegendMode,\n isValidLegendPosition,\n} from '@perses-dev/core';\n\n// This file contains legend-related model code specific to panel plugin specs.\n// See the `core` package for common/shared legend model code and the\n// `components` package for legend model code specific to the Legend component.\n\n// Note: explicitly defining different options for the legend spec and\n// legend component that extend from some common options, so we can allow the\n// component and the spec to diverge in some upcoming work.\nexport type LegendSpecOptions = LegendOptionsBase;\n\nexport type LegendSingleSelectConfig = {\n label: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport function validateLegendSpec(legend?: LegendOptionsBase) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n\n return true;\n}\n"],"names":["isValidLegendMode","isValidLegendPosition","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","validateLegendSpec","legend","undefined","position","mode"],"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,SAIEA,iBAAiB,EACjBC,qBAAqB,QAChB,kBAAkB,CAAC;AAe1B,OAAO,MAAMC,uBAAuB,GAAgE;IAClGC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,kBAAkB,GAA2D;IACxFC,IAAI,EAAE;QAAEH,KAAK,EAAE,MAAM;KAAE;IACvBI,KAAK,EAAE;QAAEJ,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,SAASK,kBAAkB,CAACC,MAA0B,EAAE;IAC7D,IAAIA,MAAM,KAAKC,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACV,qBAAqB,CAACS,MAAM,CAACE,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAIF,MAAM,CAACG,IAAI,IAAI,CAACb,iBAAiB,CAACU,MAAM,CAACG,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"sources":["../../src/model/legend.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 {\n CALCULATIONS_CONFIG,\n CalculationType,\n LegendMode,\n LegendOptionsBase,\n LegendPositions,\n isValidLegendMode,\n isValidLegendPosition,\n} from '@perses-dev/core';\n\n// This file contains legend-related model code specific to panel plugin specs.\n// See the `core` package for common/shared legend model code and the\n// `components` package for legend model code specific to the Legend component.\n\n// Explicity listing the calculations we intend to use for legend values because\n// we want them ordered in a specific way, and it may be possible in the future\n// that we only use a subset of calculations for the legend because the calculations\n// are also used by other features.\nexport const legendValues: CalculationType[] = [\n 'Mean',\n 'First',\n 'FirstNumber',\n 'Last',\n 'LastNumber',\n 'Min',\n 'Max',\n 'Sum',\n];\nexport type LegendValue = (typeof legendValues)[number];\n\n// Note: explicitly defining different options for the legend spec and\n// legend component that extend from some common options, so we can allow the\n// component and the spec to diverge in some upcoming work.\nexport interface LegendSpecOptions extends LegendOptionsBase {\n values?: LegendValue[];\n}\n\nexport type LegendSingleSelectConfig = {\n label: string;\n description?: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value) => {\n config[value] = CALCULATIONS_CONFIG[value];\n\n return config;\n}, {} as Partial<Record<LegendValue, LegendSingleSelectConfig>>);\n\nexport function validateLegendSpec(legend?: LegendOptionsBase) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n\n return true;\n}\n"],"names":["CALCULATIONS_CONFIG","isValidLegendMode","isValidLegendPosition","legendValues","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","LEGEND_VALUE_CONFIG","reduce","config","value","validateLegendSpec","legend","undefined","position","mode"],"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,SACEA,mBAAmB,EAKnBC,iBAAiB,EACjBC,qBAAqB,QAChB,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,qEAAqE;AACrE,+EAA+E;AAE/E,gFAAgF;AAChF,+EAA+E;AAC/E,oFAAoF;AACpF,mCAAmC;AACnC,OAAO,MAAMC,YAAY,GAAsB;IAC7C,MAAM;IACN,OAAO;IACP,aAAa;IACb,MAAM;IACN,YAAY;IACZ,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC;AAeF,OAAO,MAAMC,uBAAuB,GAAgE;IAClGC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,kBAAkB,GAA2D;IACxFC,IAAI,EAAE;QAAEH,KAAK,EAAE,MAAM;KAAE;IACvBI,KAAK,EAAE;QAAEJ,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAMK,mBAAmB,GAAGR,YAAY,CAACS,MAAM,CAAC,CAACC,MAAM,EAAEC,KAAK,GAAK;IACxED,MAAM,CAACC,KAAK,CAAC,GAAGd,mBAAmB,CAACc,KAAK,CAAC,CAAC;IAE3C,OAAOD,MAAM,CAAC;AAChB,CAAC,EAAE,EAAE,CAA2D,CAAC;AAEjE,OAAO,SAASE,kBAAkB,CAACC,MAA0B,EAAE;IAC7D,IAAIA,MAAM,KAAKC,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACf,qBAAqB,CAACc,MAAM,CAACE,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAIF,MAAM,CAACG,IAAI,IAAI,CAAClB,iBAAiB,CAACe,MAAM,CAACG,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.34.0",
3
+ "version": "0.35.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",
@@ -28,14 +28,14 @@
28
28
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
29
  },
30
30
  "dependencies": {
31
- "@perses-dev/components": "0.34.0",
32
- "@perses-dev/core": "0.34.0",
31
+ "@perses-dev/components": "0.35.0",
32
+ "@perses-dev/core": "0.35.0",
33
33
  "immer": "^9.0.15",
34
34
  "use-immer": "^0.7.0",
35
35
  "use-query-params": "^2.1.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@perses-dev/storybook": "0.34.0"
38
+ "@perses-dev/storybook": "0.35.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@mui/material": "^5.10.0",