@perses-dev/components 0.55.1 → 0.56.0-beta.1
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/AlignSelector/AlignSelector.js +115 -25
- package/dist/AlignSelector/AlignSelector.js.map +1 -1
- package/dist/CodeEditor/CodeEditor.d.ts +19 -0
- package/dist/CodeEditor/CodeEditor.d.ts.map +1 -0
- package/dist/CodeEditor/CodeEditor.js +122 -0
- package/dist/CodeEditor/CodeEditor.js.map +1 -0
- package/dist/ColorPicker/ColorPicker.js +153 -61
- package/dist/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js +147 -52
- package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +144 -41
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/DensitySelector/DensitySelector.js +53 -20
- package/dist/DensitySelector/DensitySelector.js.map +1 -1
- package/dist/Dialog/Dialog.d.ts +3 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +202 -49
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js +79 -27
- package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +184 -113
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/DragAndDrop/DragButton.js +131 -52
- package/dist/DragAndDrop/DragButton.js.map +1 -1
- package/dist/DragAndDrop/DropIndicator.js +51 -26
- package/dist/DragAndDrop/DropIndicator.js.map +1 -1
- package/dist/Drawer/Drawer.js +75 -15
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.js +179 -90
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/ErrorAlert.js +14 -4
- package/dist/ErrorAlert.js.map +1 -1
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js +463 -190
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js.map +1 -1
- package/dist/FontSizeSelector/FontSizeSelector.js +82 -50
- package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -1
- package/dist/FormEditor/FormActions.js +88 -14
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.js +246 -99
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.js +90 -25
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +105 -42
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/JSONEditor.d.ts +2 -6
- package/dist/JSONEditor.d.ts.map +1 -1
- package/dist/JSONEditor.js +24 -37
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Legend/CompactLegend.js +77 -27
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.js +184 -82
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/LegendColorBadge.js +54 -9
- package/dist/Legend/LegendColorBadge.js.map +1 -1
- package/dist/Legend/ListLegend.js +46 -16
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.js +184 -48
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +90 -48
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +2 -2
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +148 -67
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/ModeSelector/ModeSelector.js +61 -19
- package/dist/ModeSelector/ModeSelector.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +20 -9
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +130 -54
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +17 -6
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +76 -28
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/Overlay/Overlay.js +71 -27
- package/dist/Overlay/Overlay.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +96 -38
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/RepeatGrid/RepeatGrid.js +117 -45
- package/dist/RepeatGrid/RepeatGrid.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +99 -38
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/SortSelector/SortSelector.js +51 -18
- package/dist/SortSelector/SortSelector.js.map +1 -1
- package/dist/SortSelector/SortSelectorButtons.js +109 -25
- package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
- package/dist/Table/InnerTable.js +46 -15
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +3 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +410 -158
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableBody.js +15 -4
- package/dist/Table/TableBody.js.map +1 -1
- package/dist/Table/TableCell.js +294 -107
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +101 -32
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableFoot.js +15 -4
- package/dist/Table/TableFoot.js.map +1 -1
- package/dist/Table/TableHead.js +15 -4
- package/dist/Table/TableHead.js.map +1 -1
- package/dist/Table/TableHeaderCell.js +119 -62
- package/dist/Table/TableHeaderCell.js.map +1 -1
- package/dist/Table/TableRow.js +33 -9
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +5 -4
- package/dist/Table/TableToolbar.d.ts.map +1 -1
- package/dist/Table/TableToolbar.js +172 -100
- package/dist/Table/TableToolbar.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +11 -11
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +442 -204
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +27 -7
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +6 -5
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.js +57 -32
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
- package/dist/Table/hooks/useTableKeyboardNav.js +115 -74
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +86 -69
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +44 -15
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +33 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +137 -47
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +341 -174
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +368 -162
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +580 -210
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +189 -65
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +168 -78
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js +38 -11
- package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +229 -72
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +73 -27
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +221 -121
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +44 -38
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeZoneSelector.js +131 -36
- package/dist/TimeZoneSelector.js.map +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js +18 -7
- package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +830 -334
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +252 -90
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js +170 -59
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js +800 -322
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js +218 -91
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/YAMLEditor/YAMLEditor.d.ts +12 -0
- package/dist/YAMLEditor/YAMLEditor.d.ts.map +1 -0
- package/dist/YAMLEditor/YAMLEditor.js +41 -0
- package/dist/YAMLEditor/YAMLEditor.js.map +1 -0
- package/dist/YAMLEditor/index.d.ts +2 -0
- package/dist/YAMLEditor/index.d.ts.map +1 -0
- package/dist/YAMLEditor/index.js +15 -0
- package/dist/YAMLEditor/index.js.map +1 -0
- package/dist/YAMLEditor/yaml-utils.d.ts +11 -0
- package/dist/YAMLEditor/yaml-utils.d.ts.map +1 -0
- package/dist/YAMLEditor/yaml-utils.js +52 -0
- package/dist/YAMLEditor/yaml-utils.js.map +1 -0
- package/dist/YAxisLabel.js +64 -20
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/context/ChartsProvider.js +32 -16
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/context/ItemActionsProvider.js +110 -61
- package/dist/context/ItemActionsProvider.js.map +1 -1
- package/dist/context/SelectionProvider.js +170 -66
- package/dist/context/SelectionProvider.js.map +1 -1
- package/dist/context/SnackbarProvider.js +101 -44
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/context/TimeZoneProvider.js +35 -14
- package/dist/context/TimeZoneProvider.js.map +1 -1
- package/dist/controls/TextField.js +86 -25
- package/dist/controls/TextField.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/browser-storage.js +64 -34
- package/dist/utils/browser-storage.js.map +1 -1
- package/package.json +15 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { c as _c } from "react-compiler-runtime";
|
|
2
3
|
// Copyright The Perses Authors
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -22,205 +23,371 @@ import { InfoTooltip } from "../InfoTooltip/index.js";
|
|
|
22
23
|
import { OptionsEditorControl, OptionsEditorGroup } from "../OptionsEditorLayout/index.js";
|
|
23
24
|
import { ThresholdInput } from "./ThresholdInput.js";
|
|
24
25
|
const DEFAULT_STEP = 10;
|
|
25
|
-
export function ThresholdsEditor(
|
|
26
|
+
export function ThresholdsEditor(t0) {
|
|
27
|
+
const $ = _c(52);
|
|
28
|
+
const { thresholds, onChange, hideDefault, disablePercentMode } = t0;
|
|
26
29
|
const chartsTheme = useChartsTheme();
|
|
27
|
-
const { thresholds:
|
|
30
|
+
const { thresholds: t1 } = chartsTheme;
|
|
31
|
+
const { defaultColor, palette } = t1;
|
|
28
32
|
const defaultThresholdColor = thresholds?.defaultColor ?? defaultColor;
|
|
29
33
|
const steps = thresholds?.steps;
|
|
30
|
-
// every time a new threshold is added, we want to focus the recently added input
|
|
31
34
|
const recentlyAddedInputRef = useRef(null);
|
|
32
35
|
const focusRef = useRef(false);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const step = draft.steps[i];
|
|
36
|
+
let t2;
|
|
37
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
38
|
+
t2 = ()=>{
|
|
39
|
+
if (!recentlyAddedInputRef.current || !focusRef.current) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
recentlyAddedInputRef.current?.focus();
|
|
43
|
+
focusRef.current = false;
|
|
44
|
+
};
|
|
45
|
+
$[0] = t2;
|
|
46
|
+
} else {
|
|
47
|
+
t2 = $[0];
|
|
48
|
+
}
|
|
49
|
+
useEffect(t2);
|
|
50
|
+
let t3;
|
|
51
|
+
if ($[1] !== onChange || $[2] !== thresholds) {
|
|
52
|
+
t3 = (e, i)=>{
|
|
53
|
+
if (thresholds !== undefined) {
|
|
54
|
+
onChange(produce(thresholds, (draft)=>{
|
|
55
|
+
const step = draft.steps?.[i];
|
|
53
56
|
if (step) {
|
|
54
|
-
step.
|
|
57
|
+
step.value = Number(e.target.value);
|
|
55
58
|
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
// sort thresholds in ascending order every time an input blurs
|
|
72
|
-
const handleThresholdBlur = ()=>{
|
|
73
|
-
if (steps !== undefined) {
|
|
74
|
-
const sortedSteps = [
|
|
75
|
-
...steps
|
|
76
|
-
];
|
|
77
|
-
sortedSteps.sort((a, b)=>a.value - b.value);
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
$[1] = onChange;
|
|
63
|
+
$[2] = thresholds;
|
|
64
|
+
$[3] = t3;
|
|
65
|
+
} else {
|
|
66
|
+
t3 = $[3];
|
|
67
|
+
}
|
|
68
|
+
const handleThresholdValueChange = t3;
|
|
69
|
+
let t4;
|
|
70
|
+
if ($[4] !== onChange || $[5] !== thresholds) {
|
|
71
|
+
t4 = (color, i_0)=>{
|
|
78
72
|
if (thresholds !== undefined) {
|
|
79
|
-
onChange(produce(thresholds, (
|
|
80
|
-
|
|
73
|
+
onChange(produce(thresholds, (draft_0)=>{
|
|
74
|
+
if (draft_0.steps !== undefined) {
|
|
75
|
+
const step_0 = draft_0.steps[i_0];
|
|
76
|
+
if (step_0) {
|
|
77
|
+
step_0.color = color;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
81
80
|
}));
|
|
82
81
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
};
|
|
83
|
+
$[4] = onChange;
|
|
84
|
+
$[5] = thresholds;
|
|
85
|
+
$[6] = t4;
|
|
86
|
+
} else {
|
|
87
|
+
t4 = $[6];
|
|
88
|
+
}
|
|
89
|
+
const handleThresholdColorChange = t4;
|
|
90
|
+
let t5;
|
|
91
|
+
if ($[7] !== onChange || $[8] !== thresholds) {
|
|
92
|
+
t5 = (color_0)=>{
|
|
93
|
+
if (thresholds !== undefined) {
|
|
94
|
+
onChange(produce(thresholds, (draft_1)=>{
|
|
95
|
+
draft_1.defaultColor = color_0;
|
|
96
|
+
}));
|
|
97
|
+
} else {
|
|
98
|
+
onChange({
|
|
99
|
+
defaultColor: color_0
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
$[7] = onChange;
|
|
104
|
+
$[8] = thresholds;
|
|
105
|
+
$[9] = t5;
|
|
106
|
+
} else {
|
|
107
|
+
t5 = $[9];
|
|
108
|
+
}
|
|
109
|
+
const handleDefaultColorChange = t5;
|
|
110
|
+
let t6;
|
|
111
|
+
if ($[10] !== onChange || $[11] !== steps || $[12] !== thresholds) {
|
|
112
|
+
t6 = ()=>{
|
|
113
|
+
if (steps !== undefined) {
|
|
114
|
+
const sortedSteps = [
|
|
115
|
+
...steps
|
|
116
|
+
];
|
|
117
|
+
sortedSteps.sort(_temp);
|
|
118
|
+
if (thresholds !== undefined) {
|
|
119
|
+
onChange(produce(thresholds, (draft_2)=>{
|
|
120
|
+
draft_2.steps = sortedSteps;
|
|
121
|
+
}));
|
|
90
122
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
value: DEFAULT_STEP
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
$[10] = onChange;
|
|
126
|
+
$[11] = steps;
|
|
127
|
+
$[12] = thresholds;
|
|
128
|
+
$[13] = t6;
|
|
129
|
+
} else {
|
|
130
|
+
t6 = $[13];
|
|
131
|
+
}
|
|
132
|
+
const handleThresholdBlur = t6;
|
|
133
|
+
let t7;
|
|
134
|
+
if ($[14] !== onChange || $[15] !== thresholds) {
|
|
135
|
+
t7 = (i_1)=>{
|
|
136
|
+
if (thresholds !== undefined) {
|
|
137
|
+
const updatedThresholds = produce(thresholds, (draft_3)=>{
|
|
138
|
+
if (draft_3.steps) {
|
|
139
|
+
draft_3.steps.splice(i_1, 1);
|
|
110
140
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
});
|
|
142
|
+
onChange(updatedThresholds);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
$[14] = onChange;
|
|
146
|
+
$[15] = thresholds;
|
|
147
|
+
$[16] = t7;
|
|
148
|
+
} else {
|
|
149
|
+
t7 = $[16];
|
|
150
|
+
}
|
|
151
|
+
const deleteThreshold = t7;
|
|
152
|
+
let t8;
|
|
153
|
+
if ($[17] !== onChange || $[18] !== palette || $[19] !== thresholds) {
|
|
154
|
+
t8 = ()=>{
|
|
155
|
+
focusRef.current = true;
|
|
156
|
+
if (thresholds === undefined) {
|
|
157
|
+
onChange({
|
|
158
|
+
steps: [
|
|
159
|
+
{
|
|
160
|
+
value: DEFAULT_STEP
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
if (thresholds && thresholds.steps === undefined) {
|
|
166
|
+
onChange(produce(thresholds, _temp2));
|
|
167
|
+
} else {
|
|
168
|
+
onChange(produce(thresholds, (draft_5)=>{
|
|
169
|
+
const steps_0 = draft_5.steps;
|
|
170
|
+
if (steps_0?.length) {
|
|
171
|
+
const lastStep = steps_0[steps_0.length - 1];
|
|
172
|
+
const color_1 = palette[steps_0.length] ?? getRandomColor();
|
|
173
|
+
steps_0.push({
|
|
174
|
+
color: color_1,
|
|
175
|
+
value: (lastStep?.value ?? 0) + DEFAULT_STEP
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
if (steps_0) {
|
|
179
|
+
steps_0.push({
|
|
180
|
+
value: DEFAULT_STEP
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}));
|
|
127
185
|
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
$[17] = onChange;
|
|
189
|
+
$[18] = palette;
|
|
190
|
+
$[19] = thresholds;
|
|
191
|
+
$[20] = t8;
|
|
192
|
+
} else {
|
|
193
|
+
t8 = $[20];
|
|
194
|
+
}
|
|
195
|
+
const addThresholdInput = t8;
|
|
196
|
+
let t9;
|
|
197
|
+
if ($[21] !== onChange || $[22] !== thresholds) {
|
|
198
|
+
t9 = (event, value)=>{
|
|
199
|
+
const mode = value === "percent" ? "percent" : undefined;
|
|
200
|
+
if (thresholds !== undefined) {
|
|
201
|
+
onChange(produce(thresholds, (draft_6)=>{
|
|
202
|
+
draft_6.mode = mode;
|
|
203
|
+
}));
|
|
204
|
+
} else {
|
|
205
|
+
onChange({
|
|
206
|
+
mode
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
$[21] = onChange;
|
|
211
|
+
$[22] = thresholds;
|
|
212
|
+
$[23] = t9;
|
|
213
|
+
} else {
|
|
214
|
+
t9 = $[23];
|
|
215
|
+
}
|
|
216
|
+
const handleModeChange = t9;
|
|
217
|
+
let t10;
|
|
218
|
+
if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
|
|
219
|
+
t10 = /*#__PURE__*/ _jsx(PlusIcon, {});
|
|
220
|
+
$[24] = t10;
|
|
221
|
+
} else {
|
|
222
|
+
t10 = $[24];
|
|
223
|
+
}
|
|
224
|
+
let t11;
|
|
225
|
+
if ($[25] !== addThresholdInput) {
|
|
226
|
+
t11 = /*#__PURE__*/ _jsx(InfoTooltip, {
|
|
146
227
|
description: "Add threshold",
|
|
147
228
|
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
148
229
|
size: "small",
|
|
149
230
|
"aria-label": "add threshold",
|
|
150
231
|
onClick: addThresholdInput,
|
|
151
|
-
children:
|
|
232
|
+
children: t10
|
|
152
233
|
})
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
234
|
+
});
|
|
235
|
+
$[25] = addThresholdInput;
|
|
236
|
+
$[26] = t11;
|
|
237
|
+
} else {
|
|
238
|
+
t11 = $[26];
|
|
239
|
+
}
|
|
240
|
+
const t12 = thresholds?.mode ?? "absolute";
|
|
241
|
+
let t13;
|
|
242
|
+
if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
|
|
243
|
+
t13 = {
|
|
244
|
+
height: "36px",
|
|
245
|
+
marginLeft: "auto"
|
|
246
|
+
};
|
|
247
|
+
$[27] = t13;
|
|
248
|
+
} else {
|
|
249
|
+
t13 = $[27];
|
|
250
|
+
}
|
|
251
|
+
let t14;
|
|
252
|
+
if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
|
|
253
|
+
t14 = /*#__PURE__*/ _jsx(ToggleButton, {
|
|
254
|
+
"aria-label": "absolute",
|
|
255
|
+
value: "absolute",
|
|
256
|
+
sx: {
|
|
257
|
+
fontWeight: 500
|
|
258
|
+
},
|
|
259
|
+
children: "Absolute"
|
|
260
|
+
});
|
|
261
|
+
$[28] = t14;
|
|
262
|
+
} else {
|
|
263
|
+
t14 = $[28];
|
|
264
|
+
}
|
|
265
|
+
let t15;
|
|
266
|
+
if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
|
|
267
|
+
t15 = /*#__PURE__*/ _jsx(ToggleButton, {
|
|
268
|
+
"aria-label": "percent",
|
|
269
|
+
value: "percent",
|
|
270
|
+
sx: {
|
|
271
|
+
fontWeight: 500
|
|
272
|
+
},
|
|
273
|
+
children: "Percent"
|
|
274
|
+
});
|
|
275
|
+
$[29] = t15;
|
|
276
|
+
} else {
|
|
277
|
+
t15 = $[29];
|
|
278
|
+
}
|
|
279
|
+
let t16;
|
|
280
|
+
if ($[30] !== disablePercentMode || $[31] !== handleModeChange || $[32] !== t12) {
|
|
281
|
+
t16 = /*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
282
|
+
label: "Mode",
|
|
283
|
+
description: "Percentage means thresholds relative to min & max",
|
|
284
|
+
control: /*#__PURE__*/ _jsxs(ToggleButtonGroup, {
|
|
285
|
+
exclusive: true,
|
|
286
|
+
disabled: disablePercentMode,
|
|
287
|
+
value: t12,
|
|
288
|
+
onChange: handleModeChange,
|
|
289
|
+
sx: t13,
|
|
207
290
|
children: [
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
color: defaultThresholdColor,
|
|
211
|
-
onColorChange: handleDefaultColorChange
|
|
212
|
-
}),
|
|
213
|
-
/*#__PURE__*/ _jsx(Typography, {
|
|
214
|
-
children: "Default"
|
|
215
|
-
})
|
|
291
|
+
t14,
|
|
292
|
+
t15
|
|
216
293
|
]
|
|
217
294
|
})
|
|
218
|
-
|
|
219
|
-
|
|
295
|
+
});
|
|
296
|
+
$[30] = disablePercentMode;
|
|
297
|
+
$[31] = handleModeChange;
|
|
298
|
+
$[32] = t12;
|
|
299
|
+
$[33] = t16;
|
|
300
|
+
} else {
|
|
301
|
+
t16 = $[33];
|
|
302
|
+
}
|
|
303
|
+
let t17;
|
|
304
|
+
if ($[34] !== defaultThresholdColor || $[35] !== deleteThreshold || $[36] !== handleThresholdBlur || $[37] !== handleThresholdColorChange || $[38] !== handleThresholdValueChange || $[39] !== palette || $[40] !== steps || $[41] !== thresholds?.mode) {
|
|
305
|
+
t17 = steps && steps.map((step_1, i_2)=>/*#__PURE__*/ _jsx(ThresholdInput, {
|
|
306
|
+
inputRef: i_2 === steps.length - 1 ? recentlyAddedInputRef : undefined,
|
|
307
|
+
label: `T${i_2 + 1}`,
|
|
308
|
+
color: step_1.color ?? palette[i_2] ?? defaultThresholdColor,
|
|
309
|
+
value: step_1.value,
|
|
310
|
+
mode: thresholds?.mode,
|
|
311
|
+
onColorChange: (color_2)=>handleThresholdColorChange(color_2, i_2),
|
|
312
|
+
onChange: (e_0)=>{
|
|
313
|
+
handleThresholdValueChange(e_0, i_2);
|
|
314
|
+
},
|
|
315
|
+
onDelete: ()=>{
|
|
316
|
+
deleteThreshold(i_2);
|
|
317
|
+
},
|
|
318
|
+
onBlur: handleThresholdBlur
|
|
319
|
+
}, i_2)).toReversed();
|
|
320
|
+
$[34] = defaultThresholdColor;
|
|
321
|
+
$[35] = deleteThreshold;
|
|
322
|
+
$[36] = handleThresholdBlur;
|
|
323
|
+
$[37] = handleThresholdColorChange;
|
|
324
|
+
$[38] = handleThresholdValueChange;
|
|
325
|
+
$[39] = palette;
|
|
326
|
+
$[40] = steps;
|
|
327
|
+
$[41] = thresholds?.mode;
|
|
328
|
+
$[42] = t17;
|
|
329
|
+
} else {
|
|
330
|
+
t17 = $[42];
|
|
331
|
+
}
|
|
332
|
+
let t18;
|
|
333
|
+
if ($[43] !== defaultThresholdColor || $[44] !== handleDefaultColorChange || $[45] !== hideDefault) {
|
|
334
|
+
t18 = !hideDefault && /*#__PURE__*/ _jsxs(Stack, {
|
|
335
|
+
flex: 1,
|
|
336
|
+
direction: "row",
|
|
337
|
+
alignItems: "center",
|
|
338
|
+
spacing: 1,
|
|
339
|
+
children: [
|
|
340
|
+
/*#__PURE__*/ _jsx(OptionsColorPicker, {
|
|
341
|
+
label: "default",
|
|
342
|
+
color: defaultThresholdColor,
|
|
343
|
+
onColorChange: handleDefaultColorChange
|
|
344
|
+
}),
|
|
345
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
346
|
+
children: "Default"
|
|
347
|
+
})
|
|
348
|
+
]
|
|
349
|
+
});
|
|
350
|
+
$[43] = defaultThresholdColor;
|
|
351
|
+
$[44] = handleDefaultColorChange;
|
|
352
|
+
$[45] = hideDefault;
|
|
353
|
+
$[46] = t18;
|
|
354
|
+
} else {
|
|
355
|
+
t18 = $[46];
|
|
356
|
+
}
|
|
357
|
+
let t19;
|
|
358
|
+
if ($[47] !== t11 || $[48] !== t16 || $[49] !== t17 || $[50] !== t18) {
|
|
359
|
+
t19 = /*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
360
|
+
title: "Thresholds",
|
|
361
|
+
icon: t11,
|
|
362
|
+
children: [
|
|
363
|
+
t16,
|
|
364
|
+
t17,
|
|
365
|
+
t18
|
|
366
|
+
]
|
|
367
|
+
});
|
|
368
|
+
$[47] = t11;
|
|
369
|
+
$[48] = t16;
|
|
370
|
+
$[49] = t17;
|
|
371
|
+
$[50] = t18;
|
|
372
|
+
$[51] = t19;
|
|
373
|
+
} else {
|
|
374
|
+
t19 = $[51];
|
|
375
|
+
}
|
|
376
|
+
return t19;
|
|
377
|
+
}
|
|
378
|
+
function _temp2(draft_4) {
|
|
379
|
+
draft_4.steps = [
|
|
380
|
+
{
|
|
381
|
+
value: DEFAULT_STEP
|
|
382
|
+
}
|
|
383
|
+
];
|
|
384
|
+
}
|
|
385
|
+
function _temp(a, b) {
|
|
386
|
+
return a.value - b.value;
|
|
220
387
|
}
|
|
221
388
|
// https://www.paulirish.com/2009/random-hex-color-code-snippets/
|
|
222
389
|
const getRandomColor = ()=>{
|
|
223
|
-
return
|
|
390
|
+
return "#" + Math.floor(Math.random() * 16777216).toString(16).padStart(6, "0");
|
|
224
391
|
};
|
|
225
392
|
|
|
226
393
|
//# sourceMappingURL=ThresholdsEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ThresholdsEditor/ThresholdsEditor.tsx"],"sourcesContent":["// Copyright 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 { IconButton, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';\nimport { Stack } from '@mui/system';\nimport { produce } from 'immer';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport type { ReactElement } from 'react';\nimport React, { useEffect, useRef } from 'react';\n\nimport { OptionsColorPicker } from '../ColorPicker/OptionsColorPicker';\nimport { useChartsTheme } from '../context/ChartsProvider';\nimport { InfoTooltip } from '../InfoTooltip';\nimport type { ThresholdOptions } from '../model';\nimport { OptionsEditorControl, OptionsEditorGroup } from '../OptionsEditorLayout';\nimport { ThresholdInput } from './ThresholdInput';\n\nexport interface ThresholdsEditorProps {\n onChange: (thresholds: ThresholdOptions) => void;\n thresholds?: ThresholdOptions;\n hideDefault?: boolean;\n disablePercentMode?: boolean;\n}\n\nconst DEFAULT_STEP = 10;\n\nexport function ThresholdsEditor({\n thresholds,\n onChange,\n hideDefault,\n disablePercentMode,\n}: ThresholdsEditorProps): ReactElement {\n const chartsTheme = useChartsTheme();\n const {\n thresholds: { defaultColor, palette },\n } = chartsTheme;\n const defaultThresholdColor = thresholds?.defaultColor ?? defaultColor;\n\n const steps = thresholds?.steps;\n // every time a new threshold is added, we want to focus the recently added input\n const recentlyAddedInputRef = useRef<HTMLInputElement | null>(null);\n const focusRef = useRef(false);\n useEffect(() => {\n if (!recentlyAddedInputRef.current || !focusRef.current) return;\n recentlyAddedInputRef.current?.focus();\n focusRef.current = false;\n });\n\n const handleThresholdValueChange = (e: React.ChangeEvent<HTMLInputElement>, i: number): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n const step = draft.steps?.[i];\n if (step) {\n step.value = Number(e.target.value);\n }\n }),\n );\n }\n };\n\n const handleThresholdColorChange = (color: string, i: number): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n if (draft.steps !== undefined) {\n const step = draft.steps[i];\n if (step) {\n step.color = color;\n }\n }\n }),\n );\n }\n };\n\n const handleDefaultColorChange = (color: string): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.defaultColor = color;\n }),\n );\n } else {\n onChange({\n defaultColor: color,\n });\n }\n };\n\n // sort thresholds in ascending order every time an input blurs\n const handleThresholdBlur = (): void => {\n if (steps !== undefined) {\n const sortedSteps = [...steps];\n sortedSteps.sort((a, b) => a.value - b.value);\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.steps = sortedSteps;\n }),\n );\n }\n }\n };\n\n const deleteThreshold = (i: number): void => {\n if (thresholds !== undefined) {\n const updatedThresholds = produce(thresholds, (draft) => {\n if (draft.steps) {\n draft.steps.splice(i, 1);\n }\n });\n onChange(updatedThresholds);\n }\n };\n\n const addThresholdInput = (): void => {\n focusRef.current = true;\n if (thresholds === undefined) {\n onChange({\n steps: [{ value: DEFAULT_STEP }],\n });\n } else if (thresholds && thresholds.steps === undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.steps = [{ value: DEFAULT_STEP }];\n }),\n );\n } else {\n onChange(\n produce(thresholds, (draft) => {\n const steps = draft.steps;\n if (steps?.length) {\n const lastStep = steps[steps.length - 1];\n const color = palette[steps.length] ?? getRandomColor(); // we will assign color from the palette first, then generate random color\n steps.push({ color, value: (lastStep?.value ?? 0) + DEFAULT_STEP }); // set new threshold value to last step value + 10\n } else if (steps) {\n steps.push({ value: DEFAULT_STEP });\n }\n }),\n );\n }\n };\n\n const handleModeChange = (event: React.MouseEvent, value: string): void => {\n const mode = value === 'percent' ? 'percent' : undefined;\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.mode = mode;\n }),\n );\n } else {\n onChange({ mode });\n }\n };\n\n return (\n <OptionsEditorGroup\n title=\"Thresholds\"\n icon={\n <InfoTooltip description=\"Add threshold\">\n <IconButton size=\"small\" aria-label=\"add threshold\" onClick={addThresholdInput}>\n <PlusIcon />\n </IconButton>\n </InfoTooltip>\n }\n >\n <OptionsEditorControl\n label=\"Mode\"\n description=\"Percentage means thresholds relative to min & max\"\n control={\n <ToggleButtonGroup\n exclusive\n disabled={disablePercentMode}\n value={thresholds?.mode ?? 'absolute'}\n onChange={handleModeChange}\n sx={{ height: '36px', marginLeft: 'auto' }}\n >\n <ToggleButton aria-label=\"absolute\" value=\"absolute\" sx={{ fontWeight: 500 }}>\n Absolute\n </ToggleButton>\n <ToggleButton aria-label=\"percent\" value=\"percent\" sx={{ fontWeight: 500 }}>\n Percent\n </ToggleButton>\n </ToggleButtonGroup>\n }\n />\n {steps &&\n steps\n .map((step, i) => (\n <ThresholdInput\n inputRef={i === steps.length - 1 ? recentlyAddedInputRef : undefined}\n key={i}\n label={`T${i + 1}`}\n color={step.color ?? palette[i] ?? defaultThresholdColor}\n value={step.value}\n mode={thresholds?.mode}\n onColorChange={(color) => handleThresholdColorChange(color, i)}\n onChange={(e) => {\n handleThresholdValueChange(e, i);\n }}\n onDelete={() => {\n deleteThreshold(i);\n }}\n onBlur={handleThresholdBlur}\n />\n ))\n .toReversed()}\n {!hideDefault && (\n <Stack flex={1} direction=\"row\" alignItems=\"center\" spacing={1}>\n <OptionsColorPicker label=\"default\" color={defaultThresholdColor} onColorChange={handleDefaultColorChange} />\n <Typography>Default</Typography>\n </Stack>\n )}\n </OptionsEditorGroup>\n );\n}\n\n// https://www.paulirish.com/2009/random-hex-color-code-snippets/\nconst getRandomColor = (): string => {\n return (\n '#' +\n Math.floor(Math.random() * 16777216)\n .toString(16)\n .padStart(6, '0')\n );\n};\n"],"names":["IconButton","ToggleButton","ToggleButtonGroup","Typography","Stack","produce","PlusIcon","React","useEffect","useRef","OptionsColorPicker","useChartsTheme","InfoTooltip","OptionsEditorControl","OptionsEditorGroup","ThresholdInput","DEFAULT_STEP","ThresholdsEditor","thresholds","onChange","hideDefault","disablePercentMode","chartsTheme","defaultColor","palette","defaultThresholdColor","steps","recentlyAddedInputRef","focusRef","current","focus","handleThresholdValueChange","e","i","undefined","draft","step","value","Number","target","handleThresholdColorChange","color","handleDefaultColorChange","handleThresholdBlur","sortedSteps","sort","a","b","deleteThreshold","updatedThresholds","splice","addThresholdInput","length","lastStep","getRandomColor","push","handleModeChange","event","mode","title","icon","description","size","aria-label","onClick","label","control","exclusive","disabled","sx","height","marginLeft","fontWeight","map","inputRef","onColorChange","onDelete","onBlur","toReversed","flex","direction","alignItems","spacing","Math","floor","random","toString","padStart"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oE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AI;gCAAEG,YAAY;4BAAI;sCAAG;;;;;YAMjF9C,SACCA,MACG+C,GAAG,CAAC,CAACrC,MAAMH,kBACV,KAAClB;oBACC2D,UAAUzC,MAAMP,MAAM0B,MAAM,GAAG,IAAIzB,wBAAwBO;oBAE3D+B,OAAO,CAAC,CAAC,EAAEhC,IAAI,GAAG;oBAClBQ,OAAOL,KAAKK,KAAK,IAAIjB,OAAO,CAACS,EAAE,IAAIR;oBACnCY,OAAOD,KAAKC,KAAK;oBACjBqB,MAAMxC,YAAYwC;oBAClBiB,eAAe,CAAClC,QAAUD,2BAA2BC,OAAOR;oBAC5Dd,UAAU,CAACa;wBACTD,2BAA2BC,GAAGC;oBAChC;oBACA2C,UAAU;wBACR5B,gBAAgBf;oBAClB;oBACA4C,QAAQlC;mBAZHV,IAeR6C,UAAU;YACd,CAAC1D,6BACA,MAAChB;gBAAM2E,MAAM;gBAAGC,WAAU;gBAAMC,YAAW;gBAASC,SAAS;;kCAC3D,KAACxE;wBAAmBuD,OAAM;wBAAUxB,OAAOhB;wBAAuBkD,eAAejC;;kCACjF,KAACvC;kCAAW;;;;;;AAKtB;AAEA,iEAAiE;AACjE,MAAMmD,iBAAiB;IACrB,OACE,MACA6B,KAAKC,KAAK,CAACD,KAAKE,MAAM,KAAK,UACxBC,QAAQ,CAAC,IACTC,QAAQ,CAAC,GAAG;AAEnB"}
|
|
1
|
+
{"version":3,"sources":["../../src/ThresholdsEditor/ThresholdsEditor.tsx"],"sourcesContent":["// Copyright 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 { IconButton, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';\nimport { Stack } from '@mui/system';\nimport { produce } from 'immer';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport type { ReactElement } from 'react';\nimport React, { useEffect, useRef } from 'react';\n\nimport { OptionsColorPicker } from '../ColorPicker/OptionsColorPicker';\nimport { useChartsTheme } from '../context/ChartsProvider';\nimport { InfoTooltip } from '../InfoTooltip';\nimport type { ThresholdOptions } from '../model';\nimport { OptionsEditorControl, OptionsEditorGroup } from '../OptionsEditorLayout';\nimport { ThresholdInput } from './ThresholdInput';\n\nexport interface ThresholdsEditorProps {\n onChange: (thresholds: ThresholdOptions) => void;\n thresholds?: ThresholdOptions;\n hideDefault?: boolean;\n disablePercentMode?: boolean;\n}\n\nconst DEFAULT_STEP = 10;\n\nexport function ThresholdsEditor({\n thresholds,\n onChange,\n hideDefault,\n disablePercentMode,\n}: ThresholdsEditorProps): ReactElement {\n const chartsTheme = useChartsTheme();\n const {\n thresholds: { defaultColor, palette },\n } = chartsTheme;\n const defaultThresholdColor = thresholds?.defaultColor ?? defaultColor;\n\n const steps = thresholds?.steps;\n // every time a new threshold is added, we want to focus the recently added input\n const recentlyAddedInputRef = useRef<HTMLInputElement | null>(null);\n const focusRef = useRef(false);\n useEffect(() => {\n if (!recentlyAddedInputRef.current || !focusRef.current) return;\n recentlyAddedInputRef.current?.focus();\n focusRef.current = false;\n });\n\n const handleThresholdValueChange = (e: React.ChangeEvent<HTMLInputElement>, i: number): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n const step = draft.steps?.[i];\n if (step) {\n step.value = Number(e.target.value);\n }\n }),\n );\n }\n };\n\n const handleThresholdColorChange = (color: string, i: number): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n if (draft.steps !== undefined) {\n const step = draft.steps[i];\n if (step) {\n step.color = color;\n }\n }\n }),\n );\n }\n };\n\n const handleDefaultColorChange = (color: string): void => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.defaultColor = color;\n }),\n );\n } else {\n onChange({\n defaultColor: color,\n });\n }\n };\n\n // sort thresholds in ascending order every time an input blurs\n const handleThresholdBlur = (): void => {\n if (steps !== undefined) {\n const sortedSteps = [...steps];\n sortedSteps.sort((a, b) => a.value - b.value);\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.steps = sortedSteps;\n }),\n );\n }\n }\n };\n\n const deleteThreshold = (i: number): void => {\n if (thresholds !== undefined) {\n const updatedThresholds = produce(thresholds, (draft) => {\n if (draft.steps) {\n draft.steps.splice(i, 1);\n }\n });\n onChange(updatedThresholds);\n }\n };\n\n const addThresholdInput = (): void => {\n focusRef.current = true;\n if (thresholds === undefined) {\n onChange({\n steps: [{ value: DEFAULT_STEP }],\n });\n } else if (thresholds && thresholds.steps === undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.steps = [{ value: DEFAULT_STEP }];\n }),\n );\n } else {\n onChange(\n produce(thresholds, (draft) => {\n const steps = draft.steps;\n if (steps?.length) {\n const lastStep = steps[steps.length - 1];\n const color = palette[steps.length] ?? getRandomColor(); // we will assign color from the palette first, then generate random color\n steps.push({ color, value: (lastStep?.value ?? 0) + DEFAULT_STEP }); // set new threshold value to last step value + 10\n } else if (steps) {\n steps.push({ value: DEFAULT_STEP });\n }\n }),\n );\n }\n };\n\n const handleModeChange = (event: React.MouseEvent, value: string): void => {\n const mode = value === 'percent' ? 'percent' : undefined;\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.mode = mode;\n }),\n );\n } else {\n onChange({ mode });\n }\n };\n\n return (\n <OptionsEditorGroup\n title=\"Thresholds\"\n icon={\n <InfoTooltip description=\"Add threshold\">\n <IconButton size=\"small\" aria-label=\"add threshold\" onClick={addThresholdInput}>\n <PlusIcon />\n </IconButton>\n </InfoTooltip>\n }\n >\n <OptionsEditorControl\n label=\"Mode\"\n description=\"Percentage means thresholds relative to min & max\"\n control={\n <ToggleButtonGroup\n exclusive\n disabled={disablePercentMode}\n value={thresholds?.mode ?? 'absolute'}\n onChange={handleModeChange}\n sx={{ height: '36px', marginLeft: 'auto' }}\n >\n <ToggleButton aria-label=\"absolute\" value=\"absolute\" sx={{ fontWeight: 500 }}>\n Absolute\n </ToggleButton>\n <ToggleButton aria-label=\"percent\" value=\"percent\" sx={{ fontWeight: 500 }}>\n Percent\n </ToggleButton>\n </ToggleButtonGroup>\n }\n />\n {steps &&\n steps\n .map((step, i) => (\n <ThresholdInput\n inputRef={i === steps.length - 1 ? recentlyAddedInputRef : undefined}\n key={i}\n label={`T${i + 1}`}\n color={step.color ?? palette[i] ?? defaultThresholdColor}\n value={step.value}\n mode={thresholds?.mode}\n onColorChange={(color) => handleThresholdColorChange(color, i)}\n onChange={(e) => {\n handleThresholdValueChange(e, i);\n }}\n onDelete={() => {\n deleteThreshold(i);\n }}\n onBlur={handleThresholdBlur}\n />\n ))\n .toReversed()}\n {!hideDefault && (\n <Stack flex={1} direction=\"row\" alignItems=\"center\" spacing={1}>\n <OptionsColorPicker label=\"default\" color={defaultThresholdColor} onColorChange={handleDefaultColorChange} />\n <Typography>Default</Typography>\n </Stack>\n )}\n </OptionsEditorGroup>\n );\n}\n\n// https://www.paulirish.com/2009/random-hex-color-code-snippets/\nconst getRandomColor = (): string => {\n return (\n '#' +\n Math.floor(Math.random() * 16777216)\n .toString(16)\n .padStart(6, '0')\n );\n};\n"],"names":["IconButton","ToggleButton","ToggleButtonGroup","Typography","Stack","produce","PlusIcon","React","useEffect","useRef","OptionsColorPicker","useChartsTheme","InfoTooltip","OptionsEditorControl","OptionsEditorGroup","ThresholdInput","DEFAULT_STEP","getRandomColor","Math","floor","random","toString","padStart"],"mappings":";;AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,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