@perses-dev/components 0.54.0-beta.1 → 0.54.0-beta.3

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.
Files changed (216) hide show
  1. package/dist/AlignSelector/AlignSelector.js +1 -1
  2. package/dist/AlignSelector/AlignSelector.js.map +1 -1
  3. package/dist/ColorPicker/ColorPicker.js +1 -1
  4. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  5. package/dist/ColorPicker/OptionsColorPicker.js +1 -1
  6. package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
  7. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  8. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  9. package/dist/Dialog/DiscardChangesConfirmationDialog.js +1 -1
  10. package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
  11. package/dist/DragAndDrop/DragAndDropList.js +1 -1
  12. package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
  13. package/dist/DragAndDrop/DragButton.js +1 -1
  14. package/dist/DragAndDrop/DragButton.js.map +1 -1
  15. package/dist/DragAndDrop/DropIndicator.js +1 -1
  16. package/dist/DragAndDrop/DropIndicator.js.map +1 -1
  17. package/dist/Drawer/Drawer.js +1 -1
  18. package/dist/Drawer/Drawer.js.map +1 -1
  19. package/dist/EChart/EChart.js +1 -1
  20. package/dist/EChart/EChart.js.map +1 -1
  21. package/dist/ErrorAlert.js +1 -1
  22. package/dist/ErrorAlert.js.map +1 -1
  23. package/dist/FormEditor/FormActions.js +1 -1
  24. package/dist/FormEditor/FormActions.js.map +1 -1
  25. package/dist/FormatControls/FormatControls.js +1 -1
  26. package/dist/FormatControls/FormatControls.js.map +1 -1
  27. package/dist/JSONEditor.js +1 -1
  28. package/dist/JSONEditor.js.map +1 -1
  29. package/dist/Legend/CompactLegend.js +1 -1
  30. package/dist/Legend/CompactLegend.js.map +1 -1
  31. package/dist/Legend/Legend.js +1 -1
  32. package/dist/Legend/Legend.js.map +1 -1
  33. package/dist/Legend/LegendColorBadge.js +1 -1
  34. package/dist/Legend/LegendColorBadge.js.map +1 -1
  35. package/dist/Legend/ListLegend.js +1 -1
  36. package/dist/Legend/ListLegend.js.map +1 -1
  37. package/dist/Legend/ListLegendItem.js +1 -1
  38. package/dist/Legend/ListLegendItem.js.map +1 -1
  39. package/dist/Legend/TableLegend.d.ts.map +1 -1
  40. package/dist/Legend/TableLegend.js +18 -4
  41. package/dist/Legend/TableLegend.js.map +1 -1
  42. package/dist/LinksEditor/LinkEditorForm.js +1 -1
  43. package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
  44. package/dist/LinksEditor/LinksEditor.js +1 -1
  45. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  46. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +1 -1
  47. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
  48. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  49. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  50. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +1 -1
  51. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
  52. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +1 -1
  53. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  54. package/dist/Overlay/Overlay.js +1 -1
  55. package/dist/Overlay/Overlay.js.map +1 -1
  56. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +1 -1
  57. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
  58. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -1
  59. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  60. package/dist/SortSelector/SortSelectorButtons.js +1 -1
  61. package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
  62. package/dist/Table/InnerTable.js +1 -1
  63. package/dist/Table/InnerTable.js.map +1 -1
  64. package/dist/Table/Table.d.ts +1 -1
  65. package/dist/Table/Table.d.ts.map +1 -1
  66. package/dist/Table/Table.js +25 -12
  67. package/dist/Table/Table.js.map +1 -1
  68. package/dist/Table/TableBody.js +1 -1
  69. package/dist/Table/TableBody.js.map +1 -1
  70. package/dist/Table/TableCell.js +1 -1
  71. package/dist/Table/TableCell.js.map +1 -1
  72. package/dist/Table/TableCheckbox.js +1 -1
  73. package/dist/Table/TableCheckbox.js.map +1 -1
  74. package/dist/Table/TableFoot.js +1 -1
  75. package/dist/Table/TableFoot.js.map +1 -1
  76. package/dist/Table/TableHead.js +1 -1
  77. package/dist/Table/TableHead.js.map +1 -1
  78. package/dist/Table/TableHeaderCell.d.ts +20 -1
  79. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  80. package/dist/Table/TableHeaderCell.js +56 -24
  81. package/dist/Table/TableHeaderCell.js.map +1 -1
  82. package/dist/Table/TableRow.js +1 -1
  83. package/dist/Table/TableRow.js.map +1 -1
  84. package/dist/Table/TableToolbar.d.ts +13 -1
  85. package/dist/Table/TableToolbar.d.ts.map +1 -1
  86. package/dist/Table/TableToolbar.js +15 -4
  87. package/dist/Table/TableToolbar.js.map +1 -1
  88. package/dist/Table/VirtualizedTable.d.ts +6 -4
  89. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  90. package/dist/Table/VirtualizedTable.js +151 -128
  91. package/dist/Table/VirtualizedTable.js.map +1 -1
  92. package/dist/Table/VirtualizedTableContainer.js +1 -1
  93. package/dist/Table/VirtualizedTableContainer.js.map +1 -1
  94. package/dist/Table/hooks/useFuzzySearch.d.ts +5 -3
  95. package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
  96. package/dist/Table/hooks/useFuzzySearch.js +32 -13
  97. package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
  98. package/dist/Table/model/table-model.d.ts +42 -2
  99. package/dist/Table/model/table-model.d.ts.map +1 -1
  100. package/dist/Table/model/table-model.js +37 -19
  101. package/dist/Table/model/table-model.js.map +1 -1
  102. package/dist/ThresholdsEditor/ThresholdInput.js +1 -1
  103. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  104. package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -1
  105. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  106. package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
  107. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  108. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
  109. package/dist/TimeRangeSelector/TimeRangeSelector.js +25 -2
  110. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  111. package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -1
  112. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  113. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +1 -1
  114. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
  115. package/dist/TimeSeriesTooltip/SeriesMarker.js +1 -1
  116. package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
  117. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +1 -1
  118. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  119. package/dist/TimeSeriesTooltip/TooltipContent.js +1 -1
  120. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  121. package/dist/TimeSeriesTooltip/TooltipHeader.js +1 -1
  122. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  123. package/dist/TimeZoneSelector.js +1 -1
  124. package/dist/TimeZoneSelector.js.map +1 -1
  125. package/dist/ToolbarIconButton/ToolbarIconButton.js +1 -1
  126. package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  127. package/dist/TransformsEditor/TransformEditor.js +1 -1
  128. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  129. package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
  130. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  131. package/dist/TransformsEditor/TransformsEditor.js +1 -1
  132. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  133. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +1 -1
  134. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -1
  135. package/dist/ValueMappingEditor/ValueMappingEditor.js +1 -1
  136. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
  137. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +1 -1
  138. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
  139. package/dist/ValueMappingEditor/ValueMappingsEditor.js +1 -1
  140. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
  141. package/dist/YAxisLabel.js +1 -1
  142. package/dist/YAxisLabel.js.map +1 -1
  143. package/dist/cjs/Legend/TableLegend.js +16 -2
  144. package/dist/cjs/Table/Table.js +24 -11
  145. package/dist/cjs/Table/TableHeaderCell.js +54 -22
  146. package/dist/cjs/Table/TableToolbar.js +13 -2
  147. package/dist/cjs/Table/VirtualizedTable.js +150 -127
  148. package/dist/cjs/Table/hooks/useFuzzySearch.js +30 -11
  149. package/dist/cjs/Table/model/table-model.js +43 -19
  150. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +23 -0
  151. package/dist/cjs/model/index.js +1 -0
  152. package/dist/cjs/model/value-mapping.js +16 -0
  153. package/dist/cjs/theme/typography.js +1 -1
  154. package/dist/cjs/utils/format.js +20 -0
  155. package/dist/cjs/utils/index.js +4 -0
  156. package/dist/cjs/utils/mathjs.js +14 -3
  157. package/dist/cjs/utils/regexp.js +54 -0
  158. package/dist/cjs/utils/time-series-data.js +141 -0
  159. package/dist/cjs/utils/transform-data.js +157 -0
  160. package/dist/cjs/utils/value-mapping.js +105 -0
  161. package/dist/context/ChartsProvider.js +1 -1
  162. package/dist/context/ChartsProvider.js.map +1 -1
  163. package/dist/context/ItemActionsProvider.js +1 -1
  164. package/dist/context/ItemActionsProvider.js.map +1 -1
  165. package/dist/context/SelectionProvider.js +1 -1
  166. package/dist/context/SelectionProvider.js.map +1 -1
  167. package/dist/context/SnackbarProvider.js +1 -1
  168. package/dist/context/SnackbarProvider.js.map +1 -1
  169. package/dist/context/TimeZoneProvider.js +1 -1
  170. package/dist/context/TimeZoneProvider.js.map +1 -1
  171. package/dist/controls/TextField.js +1 -1
  172. package/dist/controls/TextField.js.map +1 -1
  173. package/dist/model/index.d.ts +1 -0
  174. package/dist/model/index.d.ts.map +1 -1
  175. package/dist/model/index.js +1 -0
  176. package/dist/model/index.js.map +1 -1
  177. package/dist/model/value-mapping.d.ts +35 -0
  178. package/dist/model/value-mapping.d.ts.map +1 -0
  179. package/dist/model/value-mapping.js +15 -0
  180. package/dist/model/value-mapping.js.map +1 -0
  181. package/dist/test/render.js +1 -1
  182. package/dist/test/render.js.map +1 -1
  183. package/dist/theme/typography.js +1 -1
  184. package/dist/theme/typography.js.map +1 -1
  185. package/dist/utils/format.d.ts +1 -0
  186. package/dist/utils/format.d.ts.map +1 -1
  187. package/dist/utils/format.js +17 -0
  188. package/dist/utils/format.js.map +1 -1
  189. package/dist/utils/index.d.ts +4 -0
  190. package/dist/utils/index.d.ts.map +1 -1
  191. package/dist/utils/index.js +4 -0
  192. package/dist/utils/index.js.map +1 -1
  193. package/dist/utils/mathjs.d.ts +8 -1
  194. package/dist/utils/mathjs.d.ts.map +1 -1
  195. package/dist/utils/mathjs.js +5 -2
  196. package/dist/utils/mathjs.js.map +1 -1
  197. package/dist/utils/regexp.d.ts +11 -0
  198. package/dist/utils/regexp.d.ts.map +1 -0
  199. package/dist/utils/regexp.js +42 -0
  200. package/dist/utils/regexp.js.map +1 -0
  201. package/dist/utils/request-interpolation.d.ts +1 -1
  202. package/dist/utils/request-interpolation.d.ts.map +1 -1
  203. package/dist/utils/request-interpolation.js.map +1 -1
  204. package/dist/utils/time-series-data.d.ts +15 -0
  205. package/dist/utils/time-series-data.d.ts.map +1 -0
  206. package/dist/utils/time-series-data.js +130 -0
  207. package/dist/utils/time-series-data.js.map +1 -0
  208. package/dist/utils/transform-data.d.ts +7 -0
  209. package/dist/utils/transform-data.d.ts.map +1 -0
  210. package/dist/utils/transform-data.js +214 -0
  211. package/dist/utils/transform-data.js.map +1 -0
  212. package/dist/utils/value-mapping.d.ts +3 -0
  213. package/dist/utils/value-mapping.d.ts.map +1 -0
  214. package/dist/utils/value-mapping.js +97 -0
  215. package/dist/utils/value-mapping.js.map +1 -0
  216. package/package.json +3 -2
@@ -0,0 +1,54 @@
1
+ // Copyright 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
+ /**
14
+ * Checks if a string is a regex pattern.
15
+ */ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ function _export(target, all) {
20
+ for(var name in all)Object.defineProperty(target, name, {
21
+ enumerable: true,
22
+ get: Object.getOwnPropertyDescriptor(all, name).get
23
+ });
24
+ }
25
+ _export(exports, {
26
+ get createRegexFromString () {
27
+ return createRegexFromString;
28
+ },
29
+ get isRegexPattern () {
30
+ return isRegexPattern;
31
+ }
32
+ });
33
+ function isRegexPattern(input) {
34
+ return Boolean(input?.startsWith('/'));
35
+ }
36
+ function createRegexFromString(input) {
37
+ if (!input) {
38
+ throw new Error('Input string cannot be empty');
39
+ }
40
+ if (!isRegexPattern(input)) {
41
+ return new RegExp(`^${input}$`);
42
+ }
43
+ const regexPattern = /^\/(.+)\/([gimy]*)$/;
44
+ const matches = input.match(regexPattern);
45
+ if (!matches) {
46
+ throw new Error(`Invalid regular expression format: ${input}`);
47
+ }
48
+ const [, pattern = '', flags = ''] = matches;
49
+ try {
50
+ return new RegExp(pattern, flags);
51
+ } catch (error) {
52
+ throw new Error(`Failed to create RegExp ${error}`);
53
+ }
54
+ }
@@ -0,0 +1,141 @@
1
+ // Copyright 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
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get MIN_STEP_INTERVAL_MS () {
25
+ return MIN_STEP_INTERVAL_MS;
26
+ },
27
+ get getCommonTimeScale () {
28
+ return getCommonTimeScale;
29
+ },
30
+ get getTimeSeriesValues () {
31
+ return getTimeSeriesValues;
32
+ }
33
+ });
34
+ const _mathjs = require("./mathjs");
35
+ const MIN_STEP_INTERVAL_MS = 10;
36
+ function getTimeSeriesValues(series, timeScale) {
37
+ let timestamp = timeScale.startMs;
38
+ const values = series.values;
39
+ const processedValues = [];
40
+ for (const valueTuple of values){
41
+ // Fill in values up to the current series value timestamp with nulls
42
+ while(timestamp < valueTuple[0]){
43
+ processedValues.push([
44
+ timestamp,
45
+ null
46
+ ]);
47
+ timestamp += timeScale.stepMs;
48
+ }
49
+ // Now add the current value since timestamp should match
50
+ processedValues.push([
51
+ timestamp,
52
+ valueTuple[1]
53
+ ]);
54
+ timestamp += timeScale.stepMs;
55
+ }
56
+ // Add null values at the end of the series if necessary
57
+ while(timestamp <= timeScale.endMs){
58
+ processedValues.push([
59
+ timestamp,
60
+ null
61
+ ]);
62
+ timestamp += timeScale.stepMs;
63
+ }
64
+ return processedValues;
65
+ }
66
+ function getCommonTimeScale(seriesData) {
67
+ let timeRange = undefined;
68
+ const steps = [];
69
+ for (const data of seriesData){
70
+ if (data && 'timeRange' in data) {
71
+ if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
72
+ // Keep track of query steps so we can calculate a common one for the graph
73
+ steps.push(data.stepMs);
74
+ // If we don't have an overall time range yet, just start with this one
75
+ if (timeRange === undefined) {
76
+ timeRange = data.timeRange;
77
+ continue;
78
+ }
79
+ // Otherwise, see if this query has a start or end outside of the current
80
+ // time range
81
+ if (data.timeRange.start < timeRange.start) {
82
+ timeRange.start = data.timeRange.start;
83
+ }
84
+ if (data.timeRange.end > timeRange.end) {
85
+ timeRange.end = data.timeRange.end;
86
+ }
87
+ } else if (data && 'values' in data) {
88
+ for(let i = 0; i < data.values.length; i++){
89
+ const values = data.values[i];
90
+ if (values === undefined) {
91
+ continue;
92
+ }
93
+ const [timestamp] = values;
94
+ const start = new Date(timestamp);
95
+ const end = new Date(timestamp);
96
+ if (timeRange === undefined) {
97
+ timeRange = {
98
+ start,
99
+ end
100
+ };
101
+ continue;
102
+ }
103
+ if (start < timeRange.start) {
104
+ timeRange.start = start;
105
+ }
106
+ if (end > timeRange.end) {
107
+ timeRange.end = end;
108
+ }
109
+ }
110
+ if (timeRange === undefined) return undefined;
111
+ const startMs = timeRange.start.valueOf();
112
+ const endMs = timeRange.end.valueOf();
113
+ const rangeMs = endMs - startMs;
114
+ return {
115
+ startMs,
116
+ endMs,
117
+ rangeMs,
118
+ stepMs: MIN_STEP_INTERVAL_MS
119
+ };
120
+ }
121
+ }
122
+ if (timeRange === undefined) return undefined;
123
+ // Use the greatest common divisor of all step values as the overall step
124
+ // for the x axis (or if only one query, just use that query's step value)
125
+ let stepMs;
126
+ if (steps.length === 1) {
127
+ stepMs = steps[0];
128
+ } else {
129
+ const calculatedStepMs = (0, _mathjs.gcd)(...steps);
130
+ stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
131
+ }
132
+ const startMs = timeRange.start.valueOf();
133
+ const endMs = timeRange.end.valueOf();
134
+ const rangeMs = endMs - startMs;
135
+ return {
136
+ startMs,
137
+ endMs,
138
+ stepMs,
139
+ rangeMs
140
+ };
141
+ }
@@ -0,0 +1,157 @@
1
+ // Copyright 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
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get applyJoinTransform () {
25
+ return applyJoinTransform;
26
+ },
27
+ get applyMergeColumnsTransform () {
28
+ return applyMergeColumnsTransform;
29
+ },
30
+ get applyMergeIndexedColumnsTransform () {
31
+ return applyMergeIndexedColumnsTransform;
32
+ },
33
+ get applyMergeSeriesTransform () {
34
+ return applyMergeSeriesTransform;
35
+ },
36
+ get transformData () {
37
+ return transformData;
38
+ }
39
+ });
40
+ function applyJoinTransform(data, columns) {
41
+ // If column is undefined or empty, return data as is
42
+ if (columns.length === 0) {
43
+ return data;
44
+ }
45
+ const rowHashed = {};
46
+ for (const row of data){
47
+ const rowHash = Object.keys(row).filter((k)=>columns.includes(k)).map((k)=>row[k]).join('|');
48
+ const rowHashedValue = rowHashed[rowHash];
49
+ if (rowHashedValue) {
50
+ rowHashed[rowHash] = {
51
+ ...rowHashedValue,
52
+ ...row
53
+ };
54
+ } else {
55
+ rowHashed[rowHash] = {
56
+ ...row
57
+ };
58
+ }
59
+ }
60
+ return Object.values(rowHashed);
61
+ }
62
+ function applyMergeColumnsTransform(data, selectedColumns, outputName) {
63
+ const result = [];
64
+ for (const row of data){
65
+ const columns = Object.keys(row).filter((k)=>selectedColumns.includes(k));
66
+ const selectedColumnValues = {};
67
+ for (const column of columns){
68
+ selectedColumnValues[column] = row[column];
69
+ delete row[column];
70
+ }
71
+ for (const column of columns){
72
+ result.push({
73
+ ...row,
74
+ [outputName]: selectedColumnValues[column]
75
+ });
76
+ }
77
+ if (columns.length === 0) {
78
+ result.push(row);
79
+ }
80
+ }
81
+ return result;
82
+ }
83
+ function applyMergeIndexedColumnsTransform(data, column) {
84
+ const result = [];
85
+ for (const entry of data){
86
+ const indexedColumns = Object.keys(entry).filter((k)=>new RegExp('^((' + column + ' #\\d+)|(' + column + '))$').test(k));
87
+ const indexedColumnValues = {};
88
+ for (const indexedColumn of indexedColumns){
89
+ indexedColumnValues[indexedColumn] = entry[indexedColumn];
90
+ delete entry[indexedColumn];
91
+ }
92
+ for (const indexedColumn of indexedColumns){
93
+ result.push({
94
+ ...entry,
95
+ [column]: indexedColumnValues[indexedColumn]
96
+ });
97
+ }
98
+ if (indexedColumns.length === 0) {
99
+ result.push(entry);
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ function applyMergeSeriesTransform(data) {
105
+ let result = [
106
+ ...data
107
+ ];
108
+ const labelColumns = Array.from(new Set(data.flatMap(Object.keys).map((label)=>label.replace(/ #\d+/, '')).filter((label)=>label !== 'value')));
109
+ for (const label of labelColumns){
110
+ result = applyMergeIndexedColumnsTransform(result, label);
111
+ }
112
+ result = applyJoinTransform(result, labelColumns);
113
+ return result;
114
+ }
115
+ function transformData(data, transforms) {
116
+ let result = data;
117
+ // Apply transforms by their orders
118
+ for (const transform of transforms ?? []){
119
+ if (transform.spec.disabled) continue;
120
+ switch(transform.kind){
121
+ case 'JoinByColumnValue':
122
+ {
123
+ if (transform.spec.columns && transform.spec.columns.length > 0) {
124
+ result = applyJoinTransform(result, transform.spec.columns);
125
+ }
126
+ break;
127
+ }
128
+ case 'MergeIndexedColumns':
129
+ {
130
+ if (transform.spec.column) {
131
+ result = applyMergeIndexedColumnsTransform(result, transform.spec.column);
132
+ }
133
+ break;
134
+ }
135
+ case 'MergeColumns':
136
+ {
137
+ if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {
138
+ result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);
139
+ }
140
+ break;
141
+ }
142
+ case 'MergeSeries':
143
+ {
144
+ result = applyMergeSeriesTransform(result);
145
+ break;
146
+ }
147
+ }
148
+ }
149
+ // Ordering data column alphabetically
150
+ result = result.map((row)=>{
151
+ return Object.keys(row).sort().reduce((obj, key)=>{
152
+ obj[key] = row[key];
153
+ return obj;
154
+ }, {});
155
+ });
156
+ return result;
157
+ }
@@ -0,0 +1,105 @@
1
+ // Copyright 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
+ Object.defineProperty(exports, "applyValueMapping", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return applyValueMapping;
21
+ }
22
+ });
23
+ const _regexp = require("./regexp");
24
+ function applyValueMapping(value, mappings = []) {
25
+ if (!mappings.length) {
26
+ return {
27
+ value
28
+ };
29
+ }
30
+ const mappedItem = {
31
+ value
32
+ };
33
+ mappings.forEach((mapping)=>{
34
+ switch(mapping.kind){
35
+ case 'Value':
36
+ {
37
+ const valueOptions = mapping.spec;
38
+ if (String(valueOptions.value) === String(value)) {
39
+ mappedItem.value = valueOptions.result.value || mappedItem.value;
40
+ mappedItem.color = valueOptions.result.color;
41
+ }
42
+ break;
43
+ }
44
+ case 'Range':
45
+ {
46
+ const rangeOptions = mapping.spec;
47
+ const newValue = value;
48
+ if (rangeOptions.from === undefined && rangeOptions.to === undefined) {
49
+ break;
50
+ }
51
+ const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;
52
+ const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;
53
+ if (newValue >= from && newValue <= to) {
54
+ mappedItem.value = rangeOptions.result.value || mappedItem.value;
55
+ mappedItem.color = rangeOptions.result.color;
56
+ }
57
+ break;
58
+ }
59
+ case 'Regex':
60
+ {
61
+ const regexOptions = mapping.spec;
62
+ const stringValue = value.toString();
63
+ if (!regexOptions.pattern) {
64
+ break;
65
+ }
66
+ const regex = (0, _regexp.createRegexFromString)(regexOptions.pattern);
67
+ if (stringValue.match(regex)) {
68
+ if (regexOptions.result.value !== null) {
69
+ mappedItem.value = stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;
70
+ mappedItem.color = regexOptions.result.color;
71
+ }
72
+ }
73
+ break;
74
+ }
75
+ case 'Misc':
76
+ {
77
+ const miscOptions = mapping.spec;
78
+ if (isMiscValueMatch(miscOptions.value, value)) {
79
+ mappedItem.value = miscOptions.result.value || mappedItem.value;
80
+ mappedItem.color = miscOptions.result.color;
81
+ }
82
+ break;
83
+ }
84
+ default:
85
+ break;
86
+ }
87
+ });
88
+ return mappedItem;
89
+ }
90
+ function isMiscValueMatch(miscValue, value) {
91
+ switch(miscValue){
92
+ case 'empty':
93
+ return value === '';
94
+ case 'null':
95
+ return value === null || value === undefined;
96
+ case 'NaN':
97
+ return Number.isNaN(value);
98
+ case 'true':
99
+ return value === true;
100
+ case 'false':
101
+ return value === false;
102
+ default:
103
+ return false;
104
+ }
105
+ }
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { createContext, useContext, useMemo, useState } from 'react';
15
15
  export function ChartsProvider(props) {
16
16
  const { children, chartsTheme, enablePinning = false, enableSyncGrouping = true } = props;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/ChartsProvider.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 React, { createContext, ReactElement, useContext, useMemo, useState } from 'react';\nimport { PersesChartsTheme } from '../model';\nimport { CursorCoordinates } from '../TimeSeriesTooltip';\n\nexport interface ChartsProviderProps {\n chartsTheme: PersesChartsTheme;\n enablePinning?: boolean;\n enableSyncGrouping?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface SharedChartsState {\n chartsTheme: PersesChartsTheme;\n enablePinning: boolean;\n enableSyncGrouping: boolean;\n lastTooltipPinnedCoords: CursorCoordinates | null;\n setLastTooltipPinnedCoords: (lastTooltipPinnedCoords: CursorCoordinates | null) => void;\n}\n\nexport function ChartsProvider(props: ChartsProviderProps): ReactElement {\n const { children, chartsTheme, enablePinning = false, enableSyncGrouping = true } = props;\n\n const [lastTooltipPinnedCoords, setLastTooltipPinnedCoords] = useState<CursorCoordinates | null>(null);\n\n const ctx = useMemo(() => {\n return {\n chartsTheme,\n enablePinning,\n lastTooltipPinnedCoords,\n enableSyncGrouping,\n setLastTooltipPinnedCoords,\n };\n }, [chartsTheme, enablePinning, enableSyncGrouping, lastTooltipPinnedCoords, setLastTooltipPinnedCoords]);\n\n return <ChartsThemeContext.Provider value={ctx}>{children}</ChartsThemeContext.Provider>;\n}\n\nexport const ChartsThemeContext = createContext<SharedChartsState | undefined>(undefined);\n\nexport function useChartsContext(): SharedChartsState {\n const ctx = useContext(ChartsThemeContext);\n if (ctx === undefined) {\n throw new Error('No ChartsThemeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useChartsTheme(): PersesChartsTheme {\n const ctx = useChartsContext();\n return ctx.chartsTheme;\n}\n"],"names":["React","createContext","useContext","useMemo","useState","ChartsProvider","props","children","chartsTheme","enablePinning","enableSyncGrouping","lastTooltipPinnedCoords","setLastTooltipPinnedCoords","ctx","ChartsThemeContext","Provider","value","undefined","useChartsContext","Error","useChartsTheme"],"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,OAAOA,SAASC,aAAa,EAAgBC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAmB1F,OAAO,SAASC,eAAeC,KAA0B;IACvD,MAAM,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,gBAAgB,KAAK,EAAEC,qBAAqB,IAAI,EAAE,GAAGJ;IAEpF,MAAM,CAACK,yBAAyBC,2BAA2B,GAAGR,SAAmC;IAEjG,MAAMS,MAAMV,QAAQ;QAClB,OAAO;YACLK;YACAC;YACAE;YACAD;YACAE;QACF;IACF,GAAG;QAACJ;QAAaC;QAAeC;QAAoBC;QAAyBC;KAA2B;IAExG,qBAAO,KAACE,mBAAmBC,QAAQ;QAACC,OAAOH;kBAAMN;;AACnD;AAEA,OAAO,MAAMO,mCAAqBb,cAA6CgB,WAAW;AAE1F,OAAO,SAASC;IACd,MAAML,MAAMX,WAAWY;IACvB,IAAID,QAAQI,WAAW;QACrB,MAAM,IAAIE,MAAM;IAClB;IACA,OAAON;AACT;AAEA,OAAO,SAASO;IACd,MAAMP,MAAMK;IACZ,OAAOL,IAAIL,WAAW;AACxB"}
1
+ {"version":3,"sources":["../../src/context/ChartsProvider.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 React, { createContext, ReactElement, useContext, useMemo, useState } from 'react';\nimport { PersesChartsTheme } from '../model';\nimport { CursorCoordinates } from '../TimeSeriesTooltip';\n\nexport interface ChartsProviderProps {\n chartsTheme: PersesChartsTheme;\n enablePinning?: boolean;\n enableSyncGrouping?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface SharedChartsState {\n chartsTheme: PersesChartsTheme;\n enablePinning: boolean;\n enableSyncGrouping: boolean;\n lastTooltipPinnedCoords: CursorCoordinates | null;\n setLastTooltipPinnedCoords: (lastTooltipPinnedCoords: CursorCoordinates | null) => void;\n}\n\nexport function ChartsProvider(props: ChartsProviderProps): ReactElement {\n const { children, chartsTheme, enablePinning = false, enableSyncGrouping = true } = props;\n\n const [lastTooltipPinnedCoords, setLastTooltipPinnedCoords] = useState<CursorCoordinates | null>(null);\n\n const ctx = useMemo(() => {\n return {\n chartsTheme,\n enablePinning,\n lastTooltipPinnedCoords,\n enableSyncGrouping,\n setLastTooltipPinnedCoords,\n };\n }, [chartsTheme, enablePinning, enableSyncGrouping, lastTooltipPinnedCoords, setLastTooltipPinnedCoords]);\n\n return <ChartsThemeContext.Provider value={ctx}>{children}</ChartsThemeContext.Provider>;\n}\n\nexport const ChartsThemeContext = createContext<SharedChartsState | undefined>(undefined);\n\nexport function useChartsContext(): SharedChartsState {\n const ctx = useContext(ChartsThemeContext);\n if (ctx === undefined) {\n throw new Error('No ChartsThemeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useChartsTheme(): PersesChartsTheme {\n const ctx = useChartsContext();\n return ctx.chartsTheme;\n}\n"],"names":["React","createContext","useContext","useMemo","useState","ChartsProvider","props","children","chartsTheme","enablePinning","enableSyncGrouping","lastTooltipPinnedCoords","setLastTooltipPinnedCoords","ctx","ChartsThemeContext","Provider","value","undefined","useChartsContext","Error","useChartsTheme"],"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,OAAOA,SAASC,aAAa,EAAgBC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAmB1F,OAAO,SAASC,eAAeC,KAA0B;IACvD,MAAM,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,gBAAgB,KAAK,EAAEC,qBAAqB,IAAI,EAAE,GAAGJ;IAEpF,MAAM,CAACK,yBAAyBC,2BAA2B,GAAGR,SAAmC;IAEjG,MAAMS,MAAMV,QAAQ;QAClB,OAAO;YACLK;YACAC;YACAE;YACAD;YACAE;QACF;IACF,GAAG;QAACJ;QAAaC;QAAeC;QAAoBC;QAAyBC;KAA2B;IAExG,qBAAO,KAACE,mBAAmBC,QAAQ;QAACC,OAAOH;kBAAMN;;AACnD;AAEA,OAAO,MAAMO,mCAAqBb,cAA6CgB,WAAW;AAE1F,OAAO,SAASC;IACd,MAAML,MAAMX,WAAWY;IACvB,IAAID,QAAQI,WAAW;QACrB,MAAM,IAAIE,MAAM;IAClB;IACA,OAAON;AACT;AAEA,OAAO,SAASO;IACd,MAAMP,MAAMK;IACZ,OAAOL,IAAIL,WAAW;AACxB"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { createContext, useCallback, useContext, useMemo, useState } from 'react';
15
15
  const ItemActionsContext = /*#__PURE__*/ createContext(undefined);
16
16
  export function ItemActionsProvider({ children }) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/ItemActionsProvider.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 { createContext, ReactElement, ReactNode, useCallback, useContext, useMemo, useState } from 'react';\n\nexport interface ItemActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n}\n\nexport interface ActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n itemStatuses?: Map<unknown, ItemActionStatus>;\n}\n\nexport interface ActionState<Id = unknown> {\n actionStatuses: Map<string, ActionStatus>;\n setActionStatus: (actionName: string, status: Partial<ActionStatus>, itemId?: Id) => void;\n clearActionStatus: (actionName?: string) => void;\n}\n\nexport interface ItemActionsProviderProps {\n children: ReactNode;\n}\n\nconst ItemActionsContext = createContext<ActionState<unknown> | undefined>(undefined);\n\nexport function ItemActionsProvider({ children }: ItemActionsProviderProps): ReactElement {\n const [actionStatuses, setActionStatuses] = useState(new Map<string, ActionStatus>());\n\n const setActionStatus = useCallback((actionName: string, status: Partial<ActionStatus>, itemId?: unknown) => {\n setActionStatuses((prev) => {\n const newMap = new Map(prev);\n const existingStatus = newMap.get(actionName) || { loading: false };\n\n if (itemId !== undefined) {\n // Update item-level status for individual actions\n const itemStatuses = new Map(existingStatus.itemStatuses || new Map());\n const existingItemStatus = itemStatuses.get(itemId) || { loading: false };\n itemStatuses.set(itemId, { ...existingItemStatus, ...status } as ItemActionStatus);\n newMap.set(actionName, { ...existingStatus, itemStatuses });\n } else {\n // Update action-level status for batch actions\n newMap.set(actionName, { ...existingStatus, ...status });\n }\n\n return newMap;\n });\n }, []);\n\n const clearActionStatus = useCallback((actionName?: string) => {\n setActionStatuses((prev) => {\n if (actionName === undefined) {\n return new Map();\n }\n if (!prev.has(actionName)) return prev;\n const newMap = new Map(prev);\n newMap.delete(actionName);\n return newMap;\n });\n }, []);\n\n const ctx = useMemo<ActionState<unknown>>(\n () => ({\n actionStatuses,\n setActionStatus,\n clearActionStatus,\n }),\n [actionStatuses, setActionStatus, clearActionStatus]\n );\n\n return <ItemActionsContext.Provider value={ctx}>{children}</ItemActionsContext.Provider>;\n}\n\nconst noOp = (): void => {};\nconst emptyActionStatuses = new Map<string, ActionStatus>();\nconst defaultState: ActionState<unknown> & { hasContext: false } = {\n actionStatuses: emptyActionStatuses,\n setActionStatus: noOp,\n clearActionStatus: noOp,\n hasContext: false,\n};\n\nexport function useItemActions<Id = string | number>(): ActionState<Id> & { hasContext: boolean } {\n const ctx = useContext(ItemActionsContext);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as ActionState<Id> & { hasContext: false };\n\n return { ...ctx, hasContext: true } as ActionState<Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useState","ItemActionsContext","undefined","ItemActionsProvider","children","actionStatuses","setActionStatuses","Map","setActionStatus","actionName","status","itemId","prev","newMap","existingStatus","get","loading","itemStatuses","existingItemStatus","set","clearActionStatus","has","delete","ctx","Provider","value","noOp","emptyActionStatuses","defaultState","hasContext","useItemActions","memoizedResult"],"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,aAAa,EAA2BC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAyB3G,MAAMC,mCAAqBL,cAAgDM;AAE3E,OAAO,SAASC,oBAAoB,EAAEC,QAAQ,EAA4B;IACxE,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGN,SAAS,IAAIO;IAEzD,MAAMC,kBAAkBX,YAAY,CAACY,YAAoBC,QAA+BC;QACtFL,kBAAkB,CAACM;YACjB,MAAMC,SAAS,IAAIN,IAAIK;YACvB,MAAME,iBAAiBD,OAAOE,GAAG,CAACN,eAAe;gBAAEO,SAAS;YAAM;YAElE,IAAIL,WAAWT,WAAW;gBACxB,kDAAkD;gBAClD,MAAMe,eAAe,IAAIV,IAAIO,eAAeG,YAAY,IAAI,IAAIV;gBAChE,MAAMW,qBAAqBD,aAAaF,GAAG,CAACJ,WAAW;oBAAEK,SAAS;gBAAM;gBACxEC,aAAaE,GAAG,CAACR,QAAQ;oBAAE,GAAGO,kBAAkB;oBAAE,GAAGR,MAAM;gBAAC;gBAC5DG,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAEG;gBAAa;YAC3D,OAAO;gBACL,+CAA+C;gBAC/CJ,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAE,GAAGJ,MAAM;gBAAC;YACxD;YAEA,OAAOG;QACT;IACF,GAAG,EAAE;IAEL,MAAMO,oBAAoBvB,YAAY,CAACY;QACrCH,kBAAkB,CAACM;YACjB,IAAIH,eAAeP,WAAW;gBAC5B,OAAO,IAAIK;YACb;YACA,IAAI,CAACK,KAAKS,GAAG,CAACZ,aAAa,OAAOG;YAClC,MAAMC,SAAS,IAAIN,IAAIK;YACvBC,OAAOS,MAAM,CAACb;YACd,OAAOI;QACT;IACF,GAAG,EAAE;IAEL,MAAMU,MAAMxB,QACV,IAAO,CAAA;YACLM;YACAG;YACAY;QACF,CAAA,GACA;QAACf;QAAgBG;QAAiBY;KAAkB;IAGtD,qBAAO,KAACnB,mBAAmBuB,QAAQ;QAACC,OAAOF;kBAAMnB;;AACnD;AAEA,MAAMsB,OAAO,KAAa;AAC1B,MAAMC,sBAAsB,IAAIpB;AAChC,MAAMqB,eAA6D;IACjEvB,gBAAgBsB;IAChBnB,iBAAiBkB;IACjBN,mBAAmBM;IACnBG,YAAY;AACd;AAEA,OAAO,SAASC;IACd,MAAMP,MAAMzB,WAAWG;IAEvB,MAAM8B,iBAAiBhC,QAAQ;QAC7B,IAAI,CAACwB,KAAK,OAAOK;QAEjB,OAAO;YAAE,GAAGL,GAAG;YAAEM,YAAY;QAAK;IACpC,GAAG;QAACN;KAAI;IAER,OAAOQ;AACT"}
1
+ {"version":3,"sources":["../../src/context/ItemActionsProvider.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 { createContext, ReactElement, ReactNode, useCallback, useContext, useMemo, useState } from 'react';\n\nexport interface ItemActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n}\n\nexport interface ActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n itemStatuses?: Map<unknown, ItemActionStatus>;\n}\n\nexport interface ActionState<Id = unknown> {\n actionStatuses: Map<string, ActionStatus>;\n setActionStatus: (actionName: string, status: Partial<ActionStatus>, itemId?: Id) => void;\n clearActionStatus: (actionName?: string) => void;\n}\n\nexport interface ItemActionsProviderProps {\n children: ReactNode;\n}\n\nconst ItemActionsContext = createContext<ActionState<unknown> | undefined>(undefined);\n\nexport function ItemActionsProvider({ children }: ItemActionsProviderProps): ReactElement {\n const [actionStatuses, setActionStatuses] = useState(new Map<string, ActionStatus>());\n\n const setActionStatus = useCallback((actionName: string, status: Partial<ActionStatus>, itemId?: unknown) => {\n setActionStatuses((prev) => {\n const newMap = new Map(prev);\n const existingStatus = newMap.get(actionName) || { loading: false };\n\n if (itemId !== undefined) {\n // Update item-level status for individual actions\n const itemStatuses = new Map(existingStatus.itemStatuses || new Map());\n const existingItemStatus = itemStatuses.get(itemId) || { loading: false };\n itemStatuses.set(itemId, { ...existingItemStatus, ...status } as ItemActionStatus);\n newMap.set(actionName, { ...existingStatus, itemStatuses });\n } else {\n // Update action-level status for batch actions\n newMap.set(actionName, { ...existingStatus, ...status });\n }\n\n return newMap;\n });\n }, []);\n\n const clearActionStatus = useCallback((actionName?: string) => {\n setActionStatuses((prev) => {\n if (actionName === undefined) {\n return new Map();\n }\n if (!prev.has(actionName)) return prev;\n const newMap = new Map(prev);\n newMap.delete(actionName);\n return newMap;\n });\n }, []);\n\n const ctx = useMemo<ActionState<unknown>>(\n () => ({\n actionStatuses,\n setActionStatus,\n clearActionStatus,\n }),\n [actionStatuses, setActionStatus, clearActionStatus]\n );\n\n return <ItemActionsContext.Provider value={ctx}>{children}</ItemActionsContext.Provider>;\n}\n\nconst noOp = (): void => {};\nconst emptyActionStatuses = new Map<string, ActionStatus>();\nconst defaultState: ActionState<unknown> & { hasContext: false } = {\n actionStatuses: emptyActionStatuses,\n setActionStatus: noOp,\n clearActionStatus: noOp,\n hasContext: false,\n};\n\nexport function useItemActions<Id = string | number>(): ActionState<Id> & { hasContext: boolean } {\n const ctx = useContext(ItemActionsContext);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as ActionState<Id> & { hasContext: false };\n\n return { ...ctx, hasContext: true } as ActionState<Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useState","ItemActionsContext","undefined","ItemActionsProvider","children","actionStatuses","setActionStatuses","Map","setActionStatus","actionName","status","itemId","prev","newMap","existingStatus","get","loading","itemStatuses","existingItemStatus","set","clearActionStatus","has","delete","ctx","Provider","value","noOp","emptyActionStatuses","defaultState","hasContext","useItemActions","memoizedResult"],"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,aAAa,EAA2BC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAyB3G,MAAMC,mCAAqBL,cAAgDM;AAE3E,OAAO,SAASC,oBAAoB,EAAEC,QAAQ,EAA4B;IACxE,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGN,SAAS,IAAIO;IAEzD,MAAMC,kBAAkBX,YAAY,CAACY,YAAoBC,QAA+BC;QACtFL,kBAAkB,CAACM;YACjB,MAAMC,SAAS,IAAIN,IAAIK;YACvB,MAAME,iBAAiBD,OAAOE,GAAG,CAACN,eAAe;gBAAEO,SAAS;YAAM;YAElE,IAAIL,WAAWT,WAAW;gBACxB,kDAAkD;gBAClD,MAAMe,eAAe,IAAIV,IAAIO,eAAeG,YAAY,IAAI,IAAIV;gBAChE,MAAMW,qBAAqBD,aAAaF,GAAG,CAACJ,WAAW;oBAAEK,SAAS;gBAAM;gBACxEC,aAAaE,GAAG,CAACR,QAAQ;oBAAE,GAAGO,kBAAkB;oBAAE,GAAGR,MAAM;gBAAC;gBAC5DG,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAEG;gBAAa;YAC3D,OAAO;gBACL,+CAA+C;gBAC/CJ,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAE,GAAGJ,MAAM;gBAAC;YACxD;YAEA,OAAOG;QACT;IACF,GAAG,EAAE;IAEL,MAAMO,oBAAoBvB,YAAY,CAACY;QACrCH,kBAAkB,CAACM;YACjB,IAAIH,eAAeP,WAAW;gBAC5B,OAAO,IAAIK;YACb;YACA,IAAI,CAACK,KAAKS,GAAG,CAACZ,aAAa,OAAOG;YAClC,MAAMC,SAAS,IAAIN,IAAIK;YACvBC,OAAOS,MAAM,CAACb;YACd,OAAOI;QACT;IACF,GAAG,EAAE;IAEL,MAAMU,MAAMxB,QACV,IAAO,CAAA;YACLM;YACAG;YACAY;QACF,CAAA,GACA;QAACf;QAAgBG;QAAiBY;KAAkB;IAGtD,qBAAO,KAACnB,mBAAmBuB,QAAQ;QAACC,OAAOF;kBAAMnB;;AACnD;AAEA,MAAMsB,OAAO,KAAa;AAC1B,MAAMC,sBAAsB,IAAIpB;AAChC,MAAMqB,eAA6D;IACjEvB,gBAAgBsB;IAChBnB,iBAAiBkB;IACjBN,mBAAmBM;IACnBG,YAAY;AACd;AAEA,OAAO,SAASC;IACd,MAAMP,MAAMzB,WAAWG;IAEvB,MAAM8B,iBAAiBhC,QAAQ;QAC7B,IAAI,CAACwB,KAAK,OAAOK;QAEjB,OAAO;YAAE,GAAGL,GAAG;YAAEM,YAAY;QAAK;IACpC,GAAG;QAACN;KAAI;IAER,OAAOQ;AACT"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
15
15
  const SelectionContext = /*#__PURE__*/ createContext(undefined);
16
16
  const defaultGetId = (_item, index)=>index;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/SelectionProvider.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 {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap]\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId]\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","SelectionProvider","children","selectionMap","setSelectionMap","Map","getIdRef","registerGetId","fn","current","setSelection","items","newMap","forEach","item","id","set","toggleSelection","prev","has","delete","removeFromSelection","clearSelection","isSelected","ctx","Provider","value","noOp","noOpIsSelected","emptyMap","defaultState","hasContext","useSelection","options","getId","memoizedResult","_","rest"],"mappings":"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"}
1
+ {"version":3,"sources":["../../src/context/SelectionProvider.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 {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap]\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId]\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","SelectionProvider","children","selectionMap","setSelectionMap","Map","getIdRef","registerGetId","fn","current","setSelection","items","newMap","forEach","item","id","set","toggleSelection","prev","has","delete","removeFromSelection","clearSelection","isSelected","ctx","Provider","value","noOp","noOpIsSelected","emptyMap","defaultState","hasContext","useSelection","options","getId","memoizedResult","_","rest"],"mappings":"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"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { useCallback } from 'react';
15
15
  import { styled } from '@mui/material/styles';
16
16
  import { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from 'notistack';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/SnackbarProvider.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 React, { useCallback } from 'react';\nimport { styled } from '@mui/material/styles';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n MaterialDesignContent,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar]\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant']\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant]\n );\n}\n"],"names":["React","useCallback","styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"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,OAAOA,SAASC,WAAW,QAAQ,QAAQ;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SACEC,oBAAoBC,iBAAiB,EAErCC,eAAeC,YAAY,EAI3BC,qBAAqB,QAChB,YAAY;AAmBnB;;;CAGC,GACD,OAAO,SAASJ,iBAAiB,EAC/BK,QAAQ,EACR,GAAGC,OAC4C;IAC/C,qBACE,KAACL;QACE,GAAGK,KAAK;QACTC,YAAY;YACVC,OAAOT,OAAOK,uBAAuB,IAAO,CAAA;oBAC1C,gCAAgC;wBAC9BK,YAAY;oBACd;gBACF,CAAA;QACF;kBAECJ;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASH;IACd,MAAM,EAAEQ,eAAe,EAAEC,aAAa,EAAE,GAAGR;IAE3C,oCAAoC;IACpC,MAAMS,gBAAgBC,mBAAmBH,iBAAiB;IAC1D,MAAMI,eAAeD,mBAAmBH,iBAAiB;IACzD,MAAMK,kBAAkBF,mBAAmBH,iBAAiB;IAC5D,MAAMM,kBAAkBH,mBAAmBH,iBAAiB;IAE5D,MAAMO,oBAA0DnB,YAC9D,CAACU,OAAOU;QACN,kEAAkE;QAClE,yCAAyC;QACzC,MAAMC,UAAUX,iBAAiBY,QAAQZ,MAAMW,OAAO,GAAG,CAAC,8BAA8B,EAAEX,OAAO;QAEjG,OAAOI,cAAcO,SAASD;IAChC,GACA;QAACN;KAAc;IAGjB,OAAO;QACLF;QACAC;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF;AAEA,uDAAuD;AACvD,SAASJ,mBACPH,eAAoD,EACpDW,OAAiC;IAEjC,OAAOvB,YACL,CAACqB,SAASD;QACR,MAAMI,aAA4B;YAChC,GAAGJ,OAAO;YACVG;QACF;QACA,OAAOX,gBAAgBS,SAASG;IAClC,GACA;QAACZ;QAAiBW;KAAQ;AAE9B"}
1
+ {"version":3,"sources":["../../src/context/SnackbarProvider.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 React, { useCallback } from 'react';\nimport { styled } from '@mui/material/styles';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n MaterialDesignContent,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar]\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant']\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant]\n );\n}\n"],"names":["React","useCallback","styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"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,OAAOA,SAASC,WAAW,QAAQ,QAAQ;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SACEC,oBAAoBC,iBAAiB,EAErCC,eAAeC,YAAY,EAI3BC,qBAAqB,QAChB,YAAY;AAmBnB;;;CAGC,GACD,OAAO,SAASJ,iBAAiB,EAC/BK,QAAQ,EACR,GAAGC,OAC4C;IAC/C,qBACE,KAACL;QACE,GAAGK,KAAK;QACTC,YAAY;YACVC,OAAOT,OAAOK,uBAAuB,IAAO,CAAA;oBAC1C,gCAAgC;wBAC9BK,YAAY;oBACd;gBACF,CAAA;QACF;kBAECJ;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASH;IACd,MAAM,EAAEQ,eAAe,EAAEC,aAAa,EAAE,GAAGR;IAE3C,oCAAoC;IACpC,MAAMS,gBAAgBC,mBAAmBH,iBAAiB;IAC1D,MAAMI,eAAeD,mBAAmBH,iBAAiB;IACzD,MAAMK,kBAAkBF,mBAAmBH,iBAAiB;IAC5D,MAAMM,kBAAkBH,mBAAmBH,iBAAiB;IAE5D,MAAMO,oBAA0DnB,YAC9D,CAACU,OAAOU;QACN,kEAAkE;QAClE,yCAAyC;QACzC,MAAMC,UAAUX,iBAAiBY,QAAQZ,MAAMW,OAAO,GAAG,CAAC,8BAA8B,EAAEX,OAAO;QAEjG,OAAOI,cAAcO,SAASD;IAChC,GACA;QAACN;KAAc;IAGjB,OAAO;QACLF;QACAC;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF;AAEA,uDAAuD;AACvD,SAASJ,mBACPH,eAAoD,EACpDW,OAAiC;IAEjC,OAAOvB,YACL,CAACqB,SAASD;QACR,MAAMI,aAA4B;YAChC,GAAGJ,OAAO;YACVG;QACF;QACA,OAAOX,gBAAgBS,SAASG;IAClC,GACA;QAACZ;QAAiBW;KAAQ;AAE9B"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { createContext, useContext } from 'react';
15
15
  import { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';
16
16
  export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);