@perses-dev/components 0.50.0 → 0.51.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/ColorPicker/ColorPicker.js +2 -2
  2. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  3. package/dist/ContentWithLegend/model/content-with-legend-model.js +2 -3
  4. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  5. package/dist/DragAndDrop/DragButton.d.ts +2 -2
  6. package/dist/DragAndDrop/DragButton.d.ts.map +1 -1
  7. package/dist/DragAndDrop/DragButton.js +6 -4
  8. package/dist/DragAndDrop/DragButton.js.map +1 -1
  9. package/dist/Drawer/Drawer.js +1 -1
  10. package/dist/Drawer/Drawer.js.map +1 -1
  11. package/dist/EChart/EChart.js +3 -4
  12. package/dist/EChart/EChart.js.map +1 -1
  13. package/dist/GaugeChart/GaugeChart.js +2 -5
  14. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  15. package/dist/InfoTooltip/InfoTooltip.js +5 -4
  16. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  17. package/dist/Legend/ListLegendItem.js +3 -4
  18. package/dist/Legend/ListLegendItem.js.map +1 -1
  19. package/dist/LineChart/LineChart.js +4 -8
  20. package/dist/LineChart/LineChart.js.map +1 -1
  21. package/dist/LinksEditor/LinksEditor.js +9 -18
  22. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  23. package/dist/Overlay/Overlay.js +1 -1
  24. package/dist/Overlay/Overlay.js.map +1 -1
  25. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -2
  26. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  27. package/dist/StatChart/StatChart.d.ts +4 -4
  28. package/dist/StatChart/StatChart.d.ts.map +1 -1
  29. package/dist/StatChart/StatChart.js +9 -15
  30. package/dist/StatChart/StatChart.js.map +1 -1
  31. package/dist/StatChart/calculateFontSize.js +2 -4
  32. package/dist/StatChart/calculateFontSize.js.map +1 -1
  33. package/dist/StatChart/utils/formatStatChartValue.d.ts +3 -0
  34. package/dist/StatChart/utils/formatStatChartValue.d.ts.map +1 -0
  35. package/dist/StatChart/utils/formatStatChartValue.js +26 -0
  36. package/dist/StatChart/utils/formatStatChartValue.js.map +1 -0
  37. package/dist/StatusHistoryChart/StatusHistoryChart.d.ts +16 -3
  38. package/dist/StatusHistoryChart/StatusHistoryChart.d.ts.map +1 -1
  39. package/dist/StatusHistoryChart/StatusHistoryChart.js +9 -26
  40. package/dist/StatusHistoryChart/StatusHistoryChart.js.map +1 -1
  41. package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts +2 -1
  42. package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts.map +1 -1
  43. package/dist/StatusHistoryChart/StatusHistoryTooltip.js +3 -3
  44. package/dist/StatusHistoryChart/StatusHistoryTooltip.js.map +1 -1
  45. package/dist/StatusHistoryChart/utils/get-color.d.ts +1 -1
  46. package/dist/StatusHistoryChart/utils/get-color.d.ts.map +1 -1
  47. package/dist/StatusHistoryChart/utils/get-color.js +5 -5
  48. package/dist/StatusHistoryChart/utils/get-color.js.map +1 -1
  49. package/dist/Table/Table.js +5 -5
  50. package/dist/Table/Table.js.map +1 -1
  51. package/dist/Table/TableCell.js +5 -6
  52. package/dist/Table/TableCell.js.map +1 -1
  53. package/dist/Table/VirtualizedTable.js +11 -14
  54. package/dist/Table/VirtualizedTable.js.map +1 -1
  55. package/dist/Table/hooks/useTableKeyboardNav.js +1 -1
  56. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
  57. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +7 -13
  58. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
  59. package/dist/Table/model/table-model.js +1 -1
  60. package/dist/Table/model/table-model.js.map +1 -1
  61. package/dist/ThresholdsEditor/ThresholdsEditor.js +15 -23
  62. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  63. package/dist/TimeChart/TimeChart.js +3 -6
  64. package/dist/TimeChart/TimeChart.js.map +1 -1
  65. package/dist/TimeSeriesTooltip/LineChartTooltip.js +6 -11
  66. package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -1
  67. package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -2
  68. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  69. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +2 -3
  70. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  71. package/dist/TimeSeriesTooltip/TooltipHeader.js +4 -10
  72. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  73. package/dist/TimeSeriesTooltip/nearby-series.js +13 -23
  74. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  75. package/dist/TimeSeriesTooltip/utils.js +2 -4
  76. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  77. package/dist/TransformsEditor/TransformEditor.js +4 -7
  78. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  79. package/dist/TransformsEditor/TransformEditorContainer.js +3 -5
  80. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  81. package/dist/TransformsEditor/TransformsEditor.js +3 -6
  82. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  83. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +10 -0
  84. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -0
  85. package/dist/ValueMappingEditor/ValueMappingEditor.js +374 -0
  86. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -0
  87. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +8 -0
  88. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -0
  89. package/dist/ValueMappingEditor/ValueMappingsEditor.js +118 -0
  90. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -0
  91. package/dist/ValueMappingEditor/index.d.ts +2 -0
  92. package/dist/ValueMappingEditor/index.d.ts.map +1 -0
  93. package/dist/ValueMappingEditor/index.js +15 -0
  94. package/dist/ValueMappingEditor/index.js.map +1 -0
  95. package/dist/cjs/ColorPicker/ColorPicker.js +2 -2
  96. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -3
  97. package/dist/cjs/DragAndDrop/DragButton.js +5 -3
  98. package/dist/cjs/Drawer/Drawer.js +1 -1
  99. package/dist/cjs/EChart/EChart.js +3 -4
  100. package/dist/cjs/GaugeChart/GaugeChart.js +2 -5
  101. package/dist/cjs/InfoTooltip/InfoTooltip.js +5 -4
  102. package/dist/cjs/Legend/ListLegendItem.js +3 -4
  103. package/dist/cjs/LineChart/LineChart.js +4 -8
  104. package/dist/cjs/LinksEditor/LinksEditor.js +9 -18
  105. package/dist/cjs/Overlay/Overlay.js +1 -1
  106. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +1 -2
  107. package/dist/cjs/StatChart/StatChart.js +11 -17
  108. package/dist/cjs/StatChart/calculateFontSize.js +2 -4
  109. package/dist/cjs/StatChart/utils/formatStatChartValue.js +34 -0
  110. package/dist/cjs/StatusHistoryChart/StatusHistoryChart.js +11 -28
  111. package/dist/cjs/StatusHistoryChart/StatusHistoryTooltip.js +3 -3
  112. package/dist/cjs/StatusHistoryChart/utils/get-color.js +7 -7
  113. package/dist/cjs/Table/Table.js +5 -5
  114. package/dist/cjs/Table/TableCell.js +5 -6
  115. package/dist/cjs/Table/VirtualizedTable.js +11 -14
  116. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +1 -1
  117. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +7 -13
  118. package/dist/cjs/Table/model/table-model.js +1 -1
  119. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +15 -23
  120. package/dist/cjs/TimeChart/TimeChart.js +3 -6
  121. package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +6 -11
  122. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +1 -2
  123. package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +2 -3
  124. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +4 -10
  125. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +13 -23
  126. package/dist/cjs/TimeSeriesTooltip/utils.js +2 -4
  127. package/dist/cjs/TransformsEditor/TransformEditor.js +4 -7
  128. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +3 -5
  129. package/dist/cjs/TransformsEditor/TransformsEditor.js +3 -6
  130. package/dist/cjs/ValueMappingEditor/ValueMappingEditor.js +387 -0
  131. package/dist/cjs/ValueMappingEditor/ValueMappingsEditor.js +131 -0
  132. package/dist/cjs/ValueMappingEditor/index.js +30 -0
  133. package/dist/cjs/context/TimeZoneProvider.js +1 -1
  134. package/dist/cjs/controls/TextField.js +1 -1
  135. package/dist/cjs/index.js +1 -0
  136. package/dist/cjs/utils/chart-actions.js +1 -2
  137. package/dist/cjs/utils/format.js +1 -1
  138. package/dist/cjs/utils/theme-gen.js +5 -7
  139. package/dist/context/TimeZoneProvider.js +1 -1
  140. package/dist/context/TimeZoneProvider.js.map +1 -1
  141. package/dist/controls/TextField.js +1 -1
  142. package/dist/controls/TextField.js.map +1 -1
  143. package/dist/index.d.ts +1 -0
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +1 -0
  146. package/dist/index.js.map +1 -1
  147. package/dist/utils/chart-actions.js +1 -2
  148. package/dist/utils/chart-actions.js.map +1 -1
  149. package/dist/utils/format.js +1 -1
  150. package/dist/utils/format.js.map +1 -1
  151. package/dist/utils/theme-gen.js +5 -7
  152. package/dist/utils/theme-gen.js.map +1 -1
  153. package/package.json +3 -3
@@ -16,10 +16,9 @@ import { HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';
16
16
  import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent, VisualMapComponent } from 'echarts/components';
17
17
  import { use } from 'echarts/core';
18
18
  import { CanvasRenderer } from 'echarts/renderers';
19
- import { useMemo } from 'react';
20
- import { useChartsTheme, useTimeZone } from '../context';
19
+ import { useChartsTheme } from '../context/ChartsProvider';
20
+ import { useTimeZone } from '../context/TimeZoneProvider';
21
21
  import { EChart } from '../EChart';
22
- import { getColorsForValues } from './utils/get-color';
23
22
  import { getFormattedStatusHistoryAxisLabel } from './get-formatted-axis-label';
24
23
  import { generateTooltipHTML } from './StatusHistoryTooltip';
25
24
  use([
@@ -31,34 +30,18 @@ use([
31
30
  TooltipComponent,
32
31
  CanvasRenderer
33
32
  ]);
34
- export function StatusHistoryChart(props) {
35
- const { height, data, xAxisCategories, yAxisCategories, timeScale } = props;
33
+ export const StatusHistoryChart = (props)=>{
34
+ const { height, data, xAxisCategories, yAxisCategories, timeScale, colors } = props;
36
35
  const { timeZone } = useTimeZone();
37
36
  const chartsTheme = useChartsTheme();
38
37
  const theme = useTheme();
39
- const uniqueValues = useMemo(()=>[
40
- ...new Set(data.map((item)=>item[2]))
41
- ].filter((value)=>value !== undefined), [
42
- data
43
- ]);
44
- // get colors from theme and generate colors if not provided
45
- const pieces = useMemo(()=>{
46
- const themeColors = Array.isArray(chartsTheme.echartsTheme.color) ? chartsTheme.echartsTheme.color.filter((color)=>typeof color === 'string') : [];
47
- return uniqueValues.map((value, index)=>({
48
- value,
49
- color: getColorsForValues(uniqueValues, themeColors)[index]
50
- }));
51
- }, [
52
- uniqueValues,
53
- chartsTheme.echartsTheme.color
54
- ]);
55
- var _timeScale_rangeMs;
56
38
  const option = {
57
39
  tooltip: {
58
40
  appendToBody: true,
59
41
  formatter: (params)=>{
60
42
  return generateTooltipHTML({
61
- data: params.data,
43
+ data: params.data.value,
44
+ label: params.data.label,
62
45
  marker: params.marker,
63
46
  xAxisCategories,
64
47
  yAxisCategories,
@@ -81,7 +64,7 @@ export function StatusHistoryChart(props) {
81
64
  },
82
65
  axisLabel: {
83
66
  hideOverlap: true,
84
- formatter: getFormattedStatusHistoryAxisLabel((_timeScale_rangeMs = timeScale === null || timeScale === void 0 ? void 0 : timeScale.rangeMs) !== null && _timeScale_rangeMs !== void 0 ? _timeScale_rangeMs : 0, timeZone)
67
+ formatter: getFormattedStatusHistoryAxisLabel(timeScale?.rangeMs ?? 0, timeZone)
85
68
  }
86
69
  },
87
70
  yAxis: {
@@ -104,7 +87,7 @@ export function StatusHistoryChart(props) {
104
87
  visualMap: {
105
88
  show: false,
106
89
  type: 'piecewise',
107
- pieces
90
+ pieces: colors
108
91
  },
109
92
  series: [
110
93
  {
@@ -144,6 +127,6 @@ export function StatusHistoryChart(props) {
144
127
  theme: chartsTheme.echartsTheme
145
128
  })
146
129
  });
147
- }
130
+ };
148
131
 
149
132
  //# sourceMappingURL=StatusHistoryChart.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatusHistoryChart/StatusHistoryChart.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, useTheme } from '@mui/material';\nimport { HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';\nimport {\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n LegendComponentOption,\n} from 'echarts/components';\nimport { EChartsCoreOption, use } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { TimeScale } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport { useChartsTheme, useTimeZone } from '../context';\nimport { EChart } from '../EChart';\nimport { getColorsForValues } from './utils/get-color';\nimport { getFormattedStatusHistoryAxisLabel } from './get-formatted-axis-label';\nimport { generateTooltipHTML } from './StatusHistoryTooltip';\n\nuse([\n EChartsHeatmapChart,\n VisualMapComponent,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nexport type StatusHistoryData = [number, number, number | undefined];\n\nexport interface StatusHistoryChartProps {\n height: number;\n data: StatusHistoryData[];\n xAxisCategories: number[];\n yAxisCategories: string[];\n legend?: LegendComponentOption;\n timeScale?: TimeScale;\n}\n\nexport function StatusHistoryChart(props: StatusHistoryChartProps): ReactElement {\n const { height, data, xAxisCategories, yAxisCategories, timeScale } = props;\n const { timeZone } = useTimeZone();\n const chartsTheme = useChartsTheme();\n const theme = useTheme();\n\n const uniqueValues = useMemo(\n () => [...new Set(data.map((item) => item[2]))].filter((value): value is number => value !== undefined),\n [data]\n );\n\n // get colors from theme and generate colors if not provided\n const pieces = useMemo(() => {\n const themeColors = Array.isArray(chartsTheme.echartsTheme.color)\n ? chartsTheme.echartsTheme.color.filter((color): color is string => typeof color === 'string')\n : [];\n\n return uniqueValues.map((value, index) => ({\n value,\n color: getColorsForValues(uniqueValues, themeColors)[index],\n }));\n }, [uniqueValues, chartsTheme.echartsTheme.color]);\n\n const option: EChartsCoreOption = {\n tooltip: {\n appendToBody: true,\n formatter: (params: { data: StatusHistoryData; marker: string }) => {\n return generateTooltipHTML({\n data: params.data,\n marker: params.marker,\n xAxisCategories,\n yAxisCategories,\n theme,\n });\n },\n },\n grid: {\n top: '5%',\n bottom: '5%',\n },\n xAxis: {\n type: 'category',\n data: xAxisCategories,\n axisLine: {\n show: false,\n },\n splitArea: {\n show: false,\n },\n axisLabel: {\n hideOverlap: true,\n formatter: getFormattedStatusHistoryAxisLabel(timeScale?.rangeMs ?? 0, timeZone),\n },\n },\n yAxis: {\n type: 'category',\n data: yAxisCategories,\n axisLine: {\n show: false,\n },\n splitArea: {\n show: false,\n interval: 0,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n interval: 0,\n },\n },\n visualMap: {\n show: false,\n type: 'piecewise',\n pieces,\n },\n series: [\n {\n name: 'Status history',\n type: 'heatmap',\n coordinateSystem: 'cartesian2d',\n data: data,\n label: {\n show: false,\n },\n itemStyle: {\n borderWidth: 1,\n borderType: 'solid',\n borderColor: '#ffffff',\n },\n emphasis: {\n itemStyle: {\n opacity: 0.5,\n },\n },\n },\n ],\n };\n\n return (\n <Box style={{ height: height }} sx={{ overflow: 'auto' }}>\n <EChart\n sx={{\n width: '100%',\n height: height,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n </Box>\n );\n}\n"],"names":["Box","useTheme","HeatmapChart","EChartsHeatmapChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","VisualMapComponent","use","CanvasRenderer","useMemo","useChartsTheme","useTimeZone","EChart","getColorsForValues","getFormattedStatusHistoryAxisLabel","generateTooltipHTML","StatusHistoryChart","props","height","data","xAxisCategories","yAxisCategories","timeScale","timeZone","chartsTheme","theme","uniqueValues","Set","map","item","filter","value","undefined","pieces","themeColors","Array","isArray","echartsTheme","color","index","option","tooltip","appendToBody","formatter","params","marker","grid","top","bottom","xAxis","type","axisLine","show","splitArea","axisLabel","hideOverlap","rangeMs","yAxis","interval","splitLine","visualMap","series","name","coordinateSystem","label","itemStyle","borderWidth","borderType","borderColor","emphasis","opacity","style","sx","overflow","width"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AAC9C,SAASC,gBAAgBC,mBAAmB,QAAQ,iBAAiB;AACrE,SACEC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,EAChBC,kBAAkB,QAEb,qBAAqB;AAC5B,SAA4BC,GAAG,QAAQ,eAAe;AACtD,SAASC,cAAc,QAAQ,oBAAoB;AAEnD,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAASC,c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K;YACLC,QAAQ;QACV;QACAC,OAAO;YACLC,MAAM;YACN/B,MAAMC;YACN+B,UAAU;gBACRC,MAAM;YACR;YACAC,WAAW;gBACTD,MAAM;YACR;YACAE,WAAW;gBACTC,aAAa;gBACbZ,WAAW7B,mCAAmCQ,CAAAA,qBAAAA,sBAAAA,gCAAAA,UAAWkC,OAAO,cAAlBlC,gCAAAA,qBAAsB,GAAGC;YACzE;QACF;QACAkC,OAAO;YACLP,MAAM;YACN/B,MAAME;YACN8B,UAAU;gBACRC,MAAM;YACR;YACAC,WAAW;gBACTD,MAAM;gBACNM,UAAU;YACZ;YACAC,WAAW;gBACTP,MAAM;YACR;YACAE,WAAW;gBACTI,UAAU;YACZ;QACF;QACAE,WAAW;YACTR,MAAM;YACNF,MAAM;YACNjB;QACF;QACA4B,QAAQ;YACN;gBACEC,MAAM;gBACNZ,MAAM;gBACNa,kBAAkB;gBAClB5C,MAAMA;gBACN6C,OAAO;oBACLZ,MAAM;gBACR;gBACAa,WAAW;oBACTC,aAAa;oBACbC,YAAY;oBACZC,aAAa;gBACf;gBACAC,UAAU;oBACRJ,WAAW;wBACTK,SAAS;oBACX;gBACF;YACF;SACD;IACH;IAEA,qBACE,KAACxE;QAAIyE,OAAO;YAAErD,QAAQA;QAAO;QAAGsD,IAAI;YAAEC,UAAU;QAAO;kBACrD,cAAA,KAAC7D;YACC4D,IAAI;gBACFE,OAAO;gBACPxD,QAAQA;YACV;YACAsB,QAAQA;YACRf,OAAOD,YAAYa,YAAY;;;AAIvC"}
1
+ {"version":3,"sources":["../../src/StatusHistoryChart/StatusHistoryChart.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, useTheme } from '@mui/material';\nimport { HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';\nimport {\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n LegendComponentOption,\n} from 'echarts/components';\nimport { use } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { TimeScale } from '@perses-dev/core';\nimport { EChartsCoreOption } from 'echarts';\nimport { FC } from 'react';\nimport { useChartsTheme } from '../context/ChartsProvider';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { EChart } from '../EChart';\nimport { getFormattedStatusHistoryAxisLabel } from './get-formatted-axis-label';\nimport { generateTooltipHTML } from './StatusHistoryTooltip';\n\nuse([\n EChartsHeatmapChart,\n VisualMapComponent,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nexport type StatusHistoryData = [number, number, number | undefined];\n\nexport interface StatusHistoryDataItem {\n value: StatusHistoryData;\n label?: string;\n itemStyle?: {\n color?: string;\n borderColor?: string;\n borderWidth?: number;\n };\n}\n\nexport interface StatusHistoryChartProps {\n height: number;\n data: StatusHistoryDataItem[];\n xAxisCategories: number[];\n yAxisCategories: string[];\n legend?: LegendComponentOption;\n timeScale?: TimeScale;\n colors?: Array<{ value: number | string; color: string }>;\n}\n\nexport const StatusHistoryChart: FC<StatusHistoryChartProps> = (props) => {\n const { height, data, xAxisCategories, yAxisCategories, timeScale, colors } = props;\n const { timeZone } = useTimeZone();\n const chartsTheme = useChartsTheme();\n const theme = useTheme();\n\n const option: EChartsCoreOption = {\n tooltip: {\n appendToBody: true,\n formatter: (params: { data: StatusHistoryDataItem; marker: string }) => {\n return generateTooltipHTML({\n data: params.data.value,\n label: params.data.label,\n marker: params.marker,\n xAxisCategories,\n yAxisCategories,\n theme,\n });\n },\n },\n grid: {\n top: '5%',\n bottom: '5%',\n },\n xAxis: {\n type: 'category',\n data: xAxisCategories,\n axisLine: {\n show: false,\n },\n splitArea: {\n show: false,\n },\n axisLabel: {\n hideOverlap: true,\n formatter: getFormattedStatusHistoryAxisLabel(timeScale?.rangeMs ?? 0, timeZone),\n },\n },\n yAxis: {\n type: 'category',\n data: yAxisCategories,\n axisLine: {\n show: false,\n },\n splitArea: {\n show: false,\n interval: 0,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n interval: 0,\n },\n },\n visualMap: {\n show: false,\n type: 'piecewise',\n pieces: colors,\n },\n series: [\n {\n name: 'Status history',\n type: 'heatmap',\n coordinateSystem: 'cartesian2d',\n data: data,\n label: {\n show: false,\n },\n itemStyle: {\n borderWidth: 1,\n borderType: 'solid',\n borderColor: '#ffffff',\n },\n emphasis: {\n itemStyle: {\n opacity: 0.5,\n },\n },\n },\n ],\n };\n\n return (\n <Box style={{ height: height }} sx={{ overflow: 'auto' }}>\n <EChart\n sx={{\n width: '100%',\n height: height,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n </Box>\n );\n};\n"],"names":["Box","useTheme","HeatmapChart","EChartsHeatmapChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","VisualMapComponent","use","CanvasRenderer","useChartsTheme","useTimeZone","EChart","getFormattedStatusHistoryAxisLabel","generateTooltipHTML","StatusHistoryChart","props","height","data","xAxisCategories","yAxisCategories","timeScale","colors","timeZone","chartsTheme","theme","option","tooltip","appendToBody","formatter","params","value","label","marker","grid","top","bottom","xAxis","type","axisLine","show","splitArea","axisLabel","hideOverlap","rangeMs","yAxis","interval","splitLine","visualMap","pieces","series","name","coordinateSystem","itemStyle","borderWidth","borderType","borderColor","emphasis","opacity","style","sx","overflow","width","echartsTheme"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,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mB,UAAU;gBACRC,MAAM;YACR;YACAC,WAAW;gBACTD,MAAM;gBACNM,UAAU;YACZ;YACAC,WAAW;gBACTP,MAAM;YACR;YACAE,WAAW;gBACTI,UAAU;YACZ;QACF;QACAE,WAAW;YACTR,MAAM;YACNF,MAAM;YACNW,QAAQ3B;QACV;QACA4B,QAAQ;YACN;gBACEC,MAAM;gBACNb,MAAM;gBACNc,kBAAkB;gBAClBlC,MAAMA;gBACNc,OAAO;oBACLQ,MAAM;gBACR;gBACAa,WAAW;oBACTC,aAAa;oBACbC,YAAY;oBACZC,aAAa;gBACf;gBACAC,UAAU;oBACRJ,WAAW;wBACTK,SAAS;oBACX;gBACF;YACF;SACD;IACH;IAEA,qBACE,KAAC3D;QAAI4D,OAAO;YAAE1C,QAAQA;QAAO;QAAG2C,IAAI;YAAEC,UAAU;QAAO;kBACrD,cAAA,KAACjD;YACCgD,IAAI;gBACFE,OAAO;gBACP7C,QAAQA;YACV;YACAS,QAAQA;YACRD,OAAOD,YAAYuC,YAAY;;;AAIvC,EAAE"}
@@ -2,11 +2,12 @@ import { Theme } from '@mui/material';
2
2
  import { StatusHistoryData } from './StatusHistoryChart';
3
3
  interface CustomTooltipProps {
4
4
  data: StatusHistoryData;
5
+ label?: string;
5
6
  marker: string;
6
7
  xAxisCategories: number[];
7
8
  yAxisCategories: string[];
8
9
  theme: Theme;
9
10
  }
10
- export declare function generateTooltipHTML({ data, marker, xAxisCategories, yAxisCategories, theme, }: CustomTooltipProps): string;
11
+ export declare function generateTooltipHTML({ data, label, marker, xAxisCategories, yAxisCategories, theme, }: CustomTooltipProps): string;
11
12
  export {};
12
13
  //# sourceMappingURL=StatusHistoryTooltip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StatusHistoryTooltip.d.ts","sourceRoot":"","sources":["../../src/StatusHistoryChart/StatusHistoryTooltip.ts"],"names":[],"mappings":"AAaA,OAAO,EAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,GACN,EAAE,kBAAkB,GAAG,MAAM,CAmC7B"}
1
+ {"version":3,"file":"StatusHistoryTooltip.d.ts","sourceRoot":"","sources":["../../src/StatusHistoryChart/StatusHistoryTooltip.ts"],"names":[],"mappings":"AAaA,OAAO,EAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,KAAK,EACL,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,GACN,EAAE,kBAAkB,GAAG,MAAM,CAmC7B"}
@@ -12,8 +12,8 @@
12
12
  // limitations under the License.
13
13
  import { css } from '@mui/material';
14
14
  import { getDateAndTime } from '../utils';
15
- export function generateTooltipHTML({ data, marker, xAxisCategories, yAxisCategories, theme }) {
16
- const [x, y, value] = data;
15
+ export function generateTooltipHTML({ data, label, marker, xAxisCategories, yAxisCategories, theme }) {
16
+ const [x, y] = data;
17
17
  const xAxisLabel = xAxisCategories[x];
18
18
  const { formattedDate, formattedTime } = getDateAndTime(xAxisLabel);
19
19
  const tooltipHeader = css`
@@ -37,7 +37,7 @@ export function generateTooltipHTML({ data, marker, xAxisCategories, yAxisCatego
37
37
  <strong>${yAxisCategories[y]}</strong>
38
38
  </div>
39
39
  <div>
40
- ${value}
40
+ ${label}
41
41
  </div>
42
42
  </div>
43
43
  </div>
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatusHistoryChart/StatusHistoryTooltip.ts"],"sourcesContent":["// Copyright 2024 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 { css, Theme } from '@mui/material';\nimport { getDateAndTime } from '../utils';\nimport { StatusHistoryData } from './StatusHistoryChart';\n\ninterface CustomTooltipProps {\n data: StatusHistoryData;\n marker: string;\n xAxisCategories: number[];\n yAxisCategories: string[];\n theme: Theme;\n}\n\nexport function generateTooltipHTML({\n data,\n marker,\n xAxisCategories,\n yAxisCategories,\n theme,\n}: CustomTooltipProps): string {\n const [x, y, value] = data;\n const xAxisLabel = xAxisCategories[x];\n\n const { formattedDate, formattedTime } = getDateAndTime(xAxisLabel);\n\n const tooltipHeader = css`\n border-bottom: 1px solid ${theme.palette.grey[500]};\n padding-bottom: 8px;\n `;\n\n const tooltipContentStyles = css`\n display: flex;\n justify-content: space-between;\n padding-top: 8px;\n `;\n\n const labelStyles = css`\n margin-right: 16px;\n `;\n\n return `\n <div>\n <div style=\"${tooltipHeader.styles}\">${formattedDate} ${formattedTime}</div>\n <div style=\"${tooltipContentStyles.styles}\">\n <div style=\"${labelStyles.styles}\">\n ${marker}\n <strong>${yAxisCategories[y]}</strong>\n </div>\n <div>\n ${value}\n </div>\n </div>\n </div>\n `;\n}\n"],"names":["css","getDateAndTime","generateTooltipHTML","data","marker","xAxisCategories","yAxisCategories","theme","x","y","value","xAxisLabel","formattedDate","formattedTime","tooltipHeader","palette","grey","tooltipContentStyles","labelStyles","styles"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,QAAe,gBAAgB;AAC3C,SAASC,cAAc,QAAQ,WAAW;AAW1C,OAAO,SAASC,oBAAoB,EAClCC,IAAI,EACJC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,KAAK,EACc;IACnB,MAAM,CAACC,GAAGC,GAAGC,MAAM,GAAGP;IACtB,MAAMQ,aAAaN,eAAe,CAACG,EAAE;IAErC,MAAM,EAAEI,aAAa,EAAEC,aAAa,EAAE,GAAGZ,eAAeU;IAExD,MAAMG,gBAAgBd,GAAG,CAAC;6BACC,EAAEO,MAAMQ,OAAO,CAACC,IAAI,CAAC,IAAI,CAAC;;EAErD,CAAC;IAED,MAAMC,uBAAuBjB,GAAG,CAAC;;;;EAIjC,CAAC;IAED,MAAMkB,cAAclB,GAAG,CAAC;;EAExB,CAAC;IAED,OAAO,CAAC;;kBAEQ,EAAEc,cAAcK,MAAM,CAAC,EAAE,EAAEP,cAAc,CAAC,EAAEC,cAAc;kBAC1D,EAAEI,qBAAqBE,MAAM,CAAC;oBAC5B,EAAED,YAAYC,MAAM,CAAC;UAC/B,EAAEf,OAAO;kBACD,EAAEE,eAAe,CAACG,EAAE,CAAC;;;UAG7B,EAAEC,MAAM;;;;EAIhB,CAAC;AACH"}
1
+ {"version":3,"sources":["../../src/StatusHistoryChart/StatusHistoryTooltip.ts"],"sourcesContent":["// Copyright 2024 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 { css, Theme } from '@mui/material';\nimport { getDateAndTime } from '../utils';\nimport { StatusHistoryData } from './StatusHistoryChart';\n\ninterface CustomTooltipProps {\n data: StatusHistoryData;\n label?: string;\n marker: string;\n xAxisCategories: number[];\n yAxisCategories: string[];\n theme: Theme;\n}\n\nexport function generateTooltipHTML({\n data,\n label,\n marker,\n xAxisCategories,\n yAxisCategories,\n theme,\n}: CustomTooltipProps): string {\n const [x, y] = data;\n const xAxisLabel = xAxisCategories[x];\n\n const { formattedDate, formattedTime } = getDateAndTime(xAxisLabel);\n\n const tooltipHeader = css`\n border-bottom: 1px solid ${theme.palette.grey[500]};\n padding-bottom: 8px;\n `;\n\n const tooltipContentStyles = css`\n display: flex;\n justify-content: space-between;\n padding-top: 8px;\n `;\n\n const labelStyles = css`\n margin-right: 16px;\n `;\n\n return `\n <div>\n <div style=\"${tooltipHeader.styles}\">${formattedDate} ${formattedTime}</div>\n <div style=\"${tooltipContentStyles.styles}\">\n <div style=\"${labelStyles.styles}\">\n ${marker}\n <strong>${yAxisCategories[y]}</strong>\n </div>\n <div>\n ${label}\n </div>\n </div>\n </div>\n `;\n}\n"],"names":["css","getDateAndTime","generateTooltipHTML","data","label","marker","xAxisCategories","yAxisCategories","theme","x","y","xAxisLabel","formattedDate","formattedTime","tooltipHeader","palette","grey","tooltipContentStyles","labelStyles","styles"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,QAAe,gBAAgB;AAC3C,SAASC,cAAc,QAAQ,WAAW;AAY1C,OAAO,SAASC,oBAAoB,EAClCC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,KAAK,EACc;IACnB,MAAM,CAACC,GAAGC,EAAE,GAAGP;IACf,MAAMQ,aAAaL,eAAe,CAACG,EAAE;IAErC,MAAM,EAAEG,aAAa,EAAEC,aAAa,EAAE,GAAGZ,eAAeU;IAExD,MAAMG,gBAAgBd,GAAG,CAAC;6BACC,EAAEQ,MAAMO,OAAO,CAACC,IAAI,CAAC,IAAI,CAAC;;EAErD,CAAC;IAED,MAAMC,uBAAuBjB,GAAG,CAAC;;;;EAIjC,CAAC;IAED,MAAMkB,cAAclB,GAAG,CAAC;;EAExB,CAAC;IAED,OAAO,CAAC;;kBAEQ,EAAEc,cAAcK,MAAM,CAAC,EAAE,EAAEP,cAAc,CAAC,EAAEC,cAAc;kBAC1D,EAAEI,qBAAqBE,MAAM,CAAC;oBAC5B,EAAED,YAAYC,MAAM,CAAC;UAC/B,EAAEd,OAAO;kBACD,EAAEE,eAAe,CAACG,EAAE,CAAC;;;UAG7B,EAAEN,MAAM;;;;EAIhB,CAAC;AACH"}
@@ -1,4 +1,4 @@
1
- export declare const fallbackColor = "#1f77b4";
1
+ export declare const FALLBACK_COLOR = "#1f77b4";
2
2
  export declare function getColorForValue(value: number | string, baseColor: string): string;
3
3
  export declare function getColorsForValues(uniqueValues: Array<number | string>, themeColors: string[]): string[];
4
4
  export declare function hexToHSL(hex: string): [number, number, number];
@@ -1 +1 @@
1
- {"version":3,"file":"get-color.d.ts","sourceRoot":"","sources":["../../../src/StatusHistoryChart/utils/get-color.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA2ClF;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAaxG;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CA8B9D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAWhE"}
1
+ {"version":3,"file":"get-color.d.ts","sourceRoot":"","sources":["../../../src/StatusHistoryChart/utils/get-color.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA2ClF;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAaxG;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CA8B9D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAWhE"}
@@ -10,11 +10,11 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export const fallbackColor = '#1f77b4';
13
+ export const FALLBACK_COLOR = '#1f77b4';
14
14
  export function getColorForValue(value, baseColor) {
15
15
  // Validate base color
16
16
  if (!baseColor.match(/^#[0-9A-Fa-f]{6}$/)) {
17
- baseColor = fallbackColor;
17
+ baseColor = FALLBACK_COLOR;
18
18
  }
19
19
  try {
20
20
  const [baseH, baseS, baseL] = hexToHSL(baseColor);
@@ -39,7 +39,7 @@ export function getColorForValue(value, baseColor) {
39
39
  }
40
40
  return color;
41
41
  } catch (_) {
42
- return fallbackColor;
42
+ return FALLBACK_COLOR;
43
43
  }
44
44
  }
45
45
  export function getColorsForValues(uniqueValues, themeColors) {
@@ -50,9 +50,9 @@ export function getColorsForValues(uniqueValues, themeColors) {
50
50
  // Use theme colors first, then generate additional ones
51
51
  return uniqueValues.map((value, index)=>{
52
52
  if (index < themeColors.length) {
53
- return themeColors[index] || fallbackColor;
53
+ return themeColors[index] || FALLBACK_COLOR;
54
54
  }
55
- return getColorForValue(value, themeColors[0] || fallbackColor);
55
+ return getColorForValue(value, themeColors[0] || FALLBACK_COLOR);
56
56
  });
57
57
  }
58
58
  export function hexToHSL(hex) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/StatusHistoryChart/utils/get-color.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const fallbackColor = '#1f77b4';\n\nexport function getColorForValue(value: number | string, baseColor: string): string {\n // Validate base color\n if (!baseColor.match(/^#[0-9A-Fa-f]{6}$/)) {\n baseColor = fallbackColor;\n }\n\n try {\n const [baseH, baseS, baseL] = hexToHSL(baseColor);\n\n // Ensure numeric values are valid\n if (isNaN(baseH) || isNaN(baseS) || isNaN(baseL)) {\n throw new Error('Invalid HSL values');\n }\n\n // Create deterministic hash\n const hash = String(value)\n .split('')\n .reduce((acc, char) => acc + char.charCodeAt(0), 0);\n\n const hueStep = 60;\n const lightnessVariation = 15;\n\n const hueOffset = (hash % 6) * hueStep; // 6 segments of 60° each\n const newH = (baseH + hueOffset) % 360;\n const newL = baseL + (hash % 2 ? lightnessVariation : -lightnessVariation);\n\n // Keep saturation high for better distinction\n const newS = Math.min(baseS + 10, 90);\n const color = hslToHex(\n Math.abs(newH),\n Math.min(Math.max(newS, 50), 90), // Keep saturation 50-90%\n Math.min(Math.max(newL, 30), 70) // Keep lightness 30-70%\n );\n\n // Validate generated color\n if (!color.match(/^#[0-9A-Fa-f]{6}$/)) {\n throw new Error('Invalid generated color');\n }\n\n return color;\n } catch (_) {\n return fallbackColor;\n }\n}\n\nexport function getColorsForValues(uniqueValues: Array<number | string>, themeColors: string[]): string[] {\n // If we have enough theme colors, use them\n if (themeColors.length >= uniqueValues.length) {\n return themeColors.slice(0, uniqueValues.length);\n }\n\n // Use theme colors first, then generate additional ones\n return uniqueValues.map((value, index) => {\n if (index < themeColors.length) {\n return themeColors[index] || fallbackColor;\n }\n return getColorForValue(value, themeColors[0] || fallbackColor);\n });\n}\n\nexport function hexToHSL(hex: string): [number, number, number] {\n const r = parseInt(hex.slice(1, 3), 16) / 255;\n const g = parseInt(hex.slice(3, 5), 16) / 255;\n const b = parseInt(hex.slice(5, 7), 16) / 255;\n\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n let h = 0;\n let s = 0;\n const l = (max + min) / 2;\n\n if (max !== min) {\n const d = max - min;\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n\n switch (max) {\n case r:\n h = (g - b) / d + (g < b ? 6 : 0);\n break;\n case g:\n h = (b - r) / d + 2;\n break;\n case b:\n h = (r - g) / d + 4;\n break;\n }\n h /= 6;\n }\n\n return [h * 360, s * 100, l * 100];\n}\n\nexport function hslToHex(h: number, s: number, l: number): string {\n l /= 100;\n const a = (s * Math.min(l, 1 - l)) / 100;\n const f = (n: number): string => {\n const k = (n + h / 30) % 12;\n const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return Math.round(255 * color)\n .toString(16)\n .padStart(2, '0');\n };\n return `#${f(0)}${f(8)}${f(4)}`;\n}\n"],"names":["fallbackColor","getColorForValue","value","baseColor","match","baseH","baseS","baseL","hexToHSL","isNaN","Error","hash","String","split","reduce","acc","char","charCodeAt","hueStep","lightnessVariation","hueOffset","newH","newL","newS","Math","min","color","hslToHex","abs","max","_","getColorsForValues","uniqueValues","themeColors","length","slice","map","index","hex","r","parseInt","g","b","h","s","l","d","a","f","n","k","round","toString","padStart"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,gBAAgB,UAAU;AAEvC,OAAO,SAASC,iBAAiBC,KAAsB,EAAEC,SAAiB;IACxE,sBAAsB;IACtB,IAAI,CAACA,UAAUC,KAAK,CAAC,sBAAsB;QACzCD,YAAYH;IACd;IAEA,IAAI;QACF,MAAM,CAACK,OAAOC,OAAOC,MAAM,GAAGC,SAASL;QAEvC,kCAAkC;QAClC,IAAIM,MAAMJ,UAAUI,MAAMH,UAAUG,MAAMF,QAAQ;YAChD,MAAM,IAAIG,MAAM;QAClB;QAEA,4BAA4B;QAC5B,MAAMC,OAAOC,OAAOV,OACjBW,KAAK,CAAC,IACNC,MAAM,CAAC,CAACC,KAAKC,OAASD,MAAMC,KAAKC,UAAU,CAAC,IAAI;QAEnD,MAAMC,UAAU;QAChB,MAAMC,qBAAqB;QAE3B,MAAMC,YAAY,AAACT,OAAO,IAAKO,SAAS,yBAAyB;QACjE,MAAMG,OAAO,AAAChB,CAAAA,QAAQe,SAAQ,IAAK;QACnC,MAAME,OAAOf,QAASI,CAAAA,OAAO,IAAIQ,qBAAqB,CAACA,kBAAiB;QAExE,8CAA8C;QAC9C,MAAMI,OAAOC,KAAKC,GAAG,CAACnB,QAAQ,IAAI;QAClC,MAAMoB,QAAQC,SACZH,KAAKI,GAAG,C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MJ,GAAE,IAAKqB,IAAKjB,CAAAA,MAAMJ,GAAE;QAEjD,OAAQI;YACN,KAAKU;gBACHI,IAAI,AAACF,CAAAA,IAAIC,CAAAA,IAAKI,IAAKL,CAAAA,IAAIC,IAAI,IAAI,CAAA;gBAC/B;YACF,KAAKD;gBACHE,IAAI,AAACD,CAAAA,IAAIH,CAAAA,IAAKO,IAAI;gBAClB;YACF,KAAKJ;gBACHC,IAAI,AAACJ,CAAAA,IAAIE,CAAAA,IAAKK,IAAI;gBAClB;QACJ;QACAH,KAAK;IACP;IAEA,OAAO;QAACA,IAAI;QAAKC,IAAI;QAAKC,IAAI;KAAI;AACpC;AAEA,OAAO,SAASlB,SAASgB,CAAS,EAAEC,CAAS,EAAEC,CAAS;IACtDA,KAAK;IACL,MAAME,IAAI,AAACH,IAAIpB,KAAKC,GAAG,CAACoB,GAAG,IAAIA,KAAM;IACrC,MAAMG,IAAI,CAACC;QACT,MAAMC,IAAI,AAACD,CAAAA,IAAIN,IAAI,EAAC,IAAK;QACzB,MAAMjB,QAAQmB,IAAIE,IAAIvB,KAAKK,GAAG,CAACL,KAAKC,GAAG,CAACyB,IAAI,GAAG,IAAIA,GAAG,IAAI,CAAC;QAC3D,OAAO1B,KAAK2B,KAAK,CAAC,MAAMzB,OACrB0B,QAAQ,CAAC,IACTC,QAAQ,CAAC,GAAG;IACjB;IACA,OAAO,CAAC,CAAC,EAAEL,EAAE,GAAG,EAAEA,EAAE,GAAG,EAAEA,EAAE,GAAG,CAAC;AACjC"}
1
+ {"version":3,"sources":["../../../src/StatusHistoryChart/utils/get-color.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const FALLBACK_COLOR = '#1f77b4';\n\nexport function getColorForValue(value: number | string, baseColor: string): string {\n // Validate base color\n if (!baseColor.match(/^#[0-9A-Fa-f]{6}$/)) {\n baseColor = FALLBACK_COLOR;\n }\n\n try {\n const [baseH, baseS, baseL] = hexToHSL(baseColor);\n\n // Ensure numeric values are valid\n if (isNaN(baseH) || isNaN(baseS) || isNaN(baseL)) {\n throw new Error('Invalid HSL values');\n }\n\n // Create deterministic hash\n const hash = String(value)\n .split('')\n .reduce((acc, char) => acc + char.charCodeAt(0), 0);\n\n const hueStep = 60;\n const lightnessVariation = 15;\n\n const hueOffset = (hash % 6) * hueStep; // 6 segments of 60° each\n const newH = (baseH + hueOffset) % 360;\n const newL = baseL + (hash % 2 ? lightnessVariation : -lightnessVariation);\n\n // Keep saturation high for better distinction\n const newS = Math.min(baseS + 10, 90);\n const color = hslToHex(\n Math.abs(newH),\n Math.min(Math.max(newS, 50), 90), // Keep saturation 50-90%\n Math.min(Math.max(newL, 30), 70) // Keep lightness 30-70%\n );\n\n // Validate generated color\n if (!color.match(/^#[0-9A-Fa-f]{6}$/)) {\n throw new Error('Invalid generated color');\n }\n\n return color;\n } catch (_) {\n return FALLBACK_COLOR;\n }\n}\n\nexport function getColorsForValues(uniqueValues: Array<number | string>, themeColors: string[]): string[] {\n // If we have enough theme colors, use them\n if (themeColors.length >= uniqueValues.length) {\n return themeColors.slice(0, uniqueValues.length);\n }\n\n // Use theme colors first, then generate additional ones\n return uniqueValues.map((value, index) => {\n if (index < themeColors.length) {\n return themeColors[index] || FALLBACK_COLOR;\n }\n return getColorForValue(value, themeColors[0] || FALLBACK_COLOR);\n });\n}\n\nexport function hexToHSL(hex: string): [number, number, number] {\n const r = parseInt(hex.slice(1, 3), 16) / 255;\n const g = parseInt(hex.slice(3, 5), 16) / 255;\n const b = parseInt(hex.slice(5, 7), 16) / 255;\n\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n let h = 0;\n let s = 0;\n const l = (max + min) / 2;\n\n if (max !== min) {\n const d = max - min;\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n\n switch (max) {\n case r:\n h = (g - b) / d + (g < b ? 6 : 0);\n break;\n case g:\n h = (b - r) / d + 2;\n break;\n case b:\n h = (r - g) / d + 4;\n break;\n }\n h /= 6;\n }\n\n return [h * 360, s * 100, l * 100];\n}\n\nexport function hslToHex(h: number, s: number, l: number): string {\n l /= 100;\n const a = (s * Math.min(l, 1 - l)) / 100;\n const f = (n: number): string => {\n const k = (n + h / 30) % 12;\n const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return Math.round(255 * color)\n .toString(16)\n .padStart(2, '0');\n };\n return `#${f(0)}${f(8)}${f(4)}`;\n}\n"],"names":["FALLBACK_COLOR","getColorForValue","value","baseColor","match","baseH","baseS","baseL","hexToHSL","isNaN","Error","hash","String","split","reduce","acc","char","charCodeAt","hueStep","lightnessVariation","hueOffset","newH","newL","newS","Math","min","color","hslToHex","abs","max","_","getColorsForValues","uniqueValues","themeColors","length","slice","map","index","hex","r","parseInt","g","b","h","s","l","d","a","f","n","k","round","toString","padStart"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,iBAAiB,UAAU;AAExC,OAAO,SAASC,iBAAiBC,KAAsB,EAAEC,SAAiB;IACxE,sBAAsB;IACtB,IAAI,CAACA,UAAUC,KAAK,CAAC,sBAAsB;QACzCD,YAAYH;IACd;IAEA,IAAI;QACF,MAAM,CAACK,OAAOC,OAAOC,MAAM,GAAGC,SAASL;QAEvC,kCAAkC;QAClC,IAAIM,MAAMJ,UAAUI,MAAMH,UAAUG,MAAMF,QAAQ;YAChD,MAAM,IAAIG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OAAO1B,KAAK2B,KAAK,CAAC,MAAMzB,OACrB0B,QAAQ,CAAC,IACTC,QAAQ,CAAC,GAAG;IACjB;IACA,OAAO,CAAC,CAAC,EAAEL,EAAE,GAAG,EAAEA,EAAE,GAAG,EAAEA,EAAE,GAAG,CAAC;AACjC"}
@@ -34,7 +34,7 @@ const DEFAULT_SORTING = [];
34
34
  const theme = useTheme();
35
35
  const handleRowSelectionChange = (rowSelectionUpdater)=>{
36
36
  const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
37
- onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange(newRowSelection);
37
+ onRowSelectionChange?.(newRowSelection);
38
38
  };
39
39
  const handleRowSelectionEvent = useCallback((table, row, isModified)=>{
40
40
  if (rowSelectionVariant === 'standard' || isModified) {
@@ -48,7 +48,7 @@ const DEFAULT_SORTING = [];
48
48
  table.toggleAllRowsSelected();
49
49
  } else {
50
50
  // Focus the selected row.
51
- onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange({
51
+ onRowSelectionChange?.({
52
52
  [row.id]: true
53
53
  });
54
54
  }
@@ -59,14 +59,14 @@ const DEFAULT_SORTING = [];
59
59
  ]);
60
60
  const handleCheckboxChange = useCallback((e, table, row)=>{
61
61
  const nativePointerEvent = e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent) ? e.nativeEvent : undefined;
62
- const isModifed = !!(nativePointerEvent === null || nativePointerEvent === void 0 ? void 0 : nativePointerEvent.metaKey) || !!(nativePointerEvent === null || nativePointerEvent === void 0 ? void 0 : nativePointerEvent.shiftKey);
62
+ const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;
63
63
  handleRowSelectionEvent(table, row, isModifed);
64
64
  }, [
65
65
  handleRowSelectionEvent
66
66
  ]);
67
67
  const handleSortingChange = (sortingUpdater)=>{
68
68
  const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;
69
- onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(newSorting);
69
+ onSortingChange?.(newSorting);
70
70
  };
71
71
  const checkboxColumn = useMemo(()=>{
72
72
  return {
@@ -88,7 +88,7 @@ const DEFAULT_SORTING = [];
88
88
  onChange: (e)=>{
89
89
  handleCheckboxChange(e, table, row);
90
90
  },
91
- color: getCheckboxColor === null || getCheckboxColor === void 0 ? void 0 : getCheckboxColor(row.original),
91
+ color: getCheckboxColor?.(row.original),
92
92
  density: density
93
93
  });
94
94
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Table/Table.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns, DEFAULT_COLUMN_WIDTH } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number): string => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n cellConfigs,\n density = 'standard',\n defaultColumnWidth = DEFAULT_COLUMN_WIDTH,\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>): ReactElement {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }): ReactElement => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }): ReactElement => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n defaultColumnWidth={defaultColumnWidth}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n cellConfigs={cellConfigs}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_COLUMN_WIDTH","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","cellConfigs","density","defaultColumnWidth","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SACEA,aAAa,EACbC,eAAe,EAOfC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAAuBC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC3D,SAASC,gBAAgB,QAAQ,qBAAqB;A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B;IACT,GAAG;QAACjB;QAAgBnC;QAAmBJ;KAAQ;IAE/C,MAAMkB,QAAQlC,cAAc;QAC1BW;QACAK,SAASuD;QACT/C;QACAvB,iBAAiBA;QACjBC,mBAAmBA;QACnBwE,oBAAoB,CAAC,CAACtD;QACtBC,sBAAsBS;QACtBR,iBAAiB8B;QACjB,6EAA6E;QAC7E,oDAAoD;QACpDuB,eAAe;QACfC,OAAO;YACLnD;YACAC;QACF;IACF;IAEA,MAAMmD,iBAAiBzE,YACrB,CAACuC,GAAiDmC;QAChD,MAAM3C,MAAMD,MAAM6C,MAAM,CAACD;QACzB,MAAME,kBAAkBrC,EAAEO,OAAO,IAAIP,EAAEQ,QAAQ;QAC/ClB,wBAAwBC,OAAOC,KAAK6C;IACtC,GACA;QAAC/C;QAAyBC;KAAM;IAGlC,qBACE,KAAC5B;QACE,GAAGsB,UAAU;QACdV,SAASA;QACTC,oBAAoBA;QACpB8D,YAAYJ;QACZK,MAAMhD,MAAMiD,WAAW,GAAGD,IAAI;QAC9BlE,SAASkB,MAAMkD,iBAAiB;QAChCC,SAASnD,MAAMoD,eAAe;QAC9BrE,aAAaA;;AAGnB"}
1
+ {"version":3,"sources":["../../src/Table/Table.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns, DEFAULT_COLUMN_WIDTH } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number): string => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n cellConfigs,\n density = 'standard',\n defaultColumnWidth = DEFAULT_COLUMN_WIDTH,\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>): ReactElement {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }): ReactElement => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }): ReactElement => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n defaultColumnWidth={defaultColumnWidth}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n cellConfigs={cellConfigs}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_COLUMN_WIDTH","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","cellConfigs","density","defaultColumnWidth","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups"],"mappings":"AAAA,oCAAoC;AACpC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AACzC,MAAMmC,OAAO,CAACC,IAAI,CAACC,OAAO;QAAEhD;QAASK;QAAkBmB;KAAqB;IAEhF,MAAM6B,eAA4ClE,QAAQ;QACxD,MAAMmE,mBAAmBhE,+BAA+BQ;QAExD,IAAII,mBAAmB;YACrBoD,iBAAiBC,OAAO,CAAClB;QAC3B;QAEA,OAAOiB;IACT,GAAG;QAACjB;QAAgBnC;QAAmBJ;KAAQ;IAE/C,MAAMkB,QAAQlC,cAAc;QAC1BW;QACAK,SAASuD;QACT/C;QACAvB,iBAAiBA;QACjBC,mBAAmBA;QACnBwE,oBAAoB,CAAC,CAACtD;QACtBC,sBAAsBS;QACtBR,iBAAiB8B;QACjB,6EAA6E;QAC7E,oDAAoD;QACpDuB,eAAe;QACfC,OAAO;YACLnD;YACAC;QACF;IACF;IAEA,MAAMmD,iBAAiBzE,YACrB,CAACuC,GAAiDmC;QAChD,MAAM3C,MAAMD,MAAM6C,MAAM,CAACD;QACzB,MAAME,kBAAkBrC,EAAEO,OAAO,IAAIP,EAAEQ,QAAQ;QAC/ClB,wBAAwBC,OAAOC,KAAK6C;IACtC,GACA;QAAC/C;QAAyBC;KAAM;IAGlC,qBACE,KAAC5B;QACE,GAAGsB,UAAU;QACdV,SAASA;QACTC,oBAAoBA;QACpB8D,YAAYJ;QACZK,MAAMhD,MAAMiD,WAAW,GAAGD,IAAI;QAC9BlE,SAASkB,MAAMkD,iBAAiB;QAChCC,SAASnD,MAAMoD,eAAe;QAC9BrE,aAAaA;;AAGnB"}
@@ -41,9 +41,8 @@ export function TableCell({ children, density, variant, width, focusState = 'non
41
41
  focusState
42
42
  ]);
43
43
  const handleFocus = (e)=>{
44
- var _e_currentTarget;
45
44
  // From https://zellwk.com/blog/keyboard-focusable-elements/
46
- const nestedFocusTarget = (_e_currentTarget = e.currentTarget) === null || _e_currentTarget === void 0 ? void 0 : _e_currentTarget.querySelector('a[href], button, input, textarea, select, details,[role="button"]');
45
+ const nestedFocusTarget = e.currentTarget?.querySelector('a[href], button, input, textarea, select, details,[role="button"]');
47
46
  if (nestedFocusTarget) {
48
47
  // If the cell has a focusable child, focus it instead. Mostly used for
49
48
  // checkbox cells, but could have other uses.
@@ -56,7 +55,7 @@ export function TableCell({ children, density, variant, width, focusState = 'non
56
55
  // plays with the triggering of focus with keyboard interactions.
57
56
  // These report that a focus event happened, so we can adjust the current
58
57
  // tabindex and focuses to the right cell.
59
- onFocusTrigger === null || onFocusTrigger === void 0 ? void 0 : onFocusTrigger(e);
58
+ onFocusTrigger?.(e);
60
59
  };
61
60
  return /*#__PURE__*/ _jsx(StyledMuiTableCell, {
62
61
  ...otherProps,
@@ -83,7 +82,7 @@ export function TableCell({ children, density, variant, width, focusState = 'non
83
82
  minWidth: '100%',
84
83
  whiteSpace: 'nowrap',
85
84
  overflow: 'visible',
86
- backgroundColor: `${backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : theme.palette.background.default} !important`,
85
+ backgroundColor: `${backgroundColor ?? theme.palette.background.default} !important`,
87
86
  outline: `solid 1px ${theme.palette.info.main}`,
88
87
  outlineOffset: '-1px'
89
88
  }
@@ -108,8 +107,8 @@ export function TableCell({ children, density, variant, width, focusState = 'non
108
107
  flexDirection: 'inherit'
109
108
  },
110
109
  style: {
111
- backgroundColor: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : 'inherit',
112
- color: color !== null && color !== void 0 ? color : 'inherit'
110
+ backgroundColor: backgroundColor ?? 'inherit',
111
+ color: color ?? 'inherit'
113
112
  },
114
113
  title: description,
115
114
  "aria-label": description,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Table/TableCell.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableCell as MuiTableCell, styled, TableCellProps as MuiTableCellProps, Box, useTheme } from '@mui/material';\nimport { ReactElement, useEffect, useRef } from 'react';\nimport { TableCellAlignment, TableDensity, getTableCellLayout } from './model/table-model';\n\nconst StyledMuiTableCell = styled(MuiTableCell)(({ theme }) => ({\n padding: 0,\n backgroundColor: 'inherit',\n\n '&.MuiTableCell-head': {\n // Important to avoid scrolling behind the header showing through.\n backgroundColor: theme.palette.background.default,\n },\n '&:focus-visible': {\n outline: `solid 1px ${theme.palette.primary.main}`,\n // Move inward a little to avoid getting cut off when focusing on items\n // at the edge of the table.\n outlineOffset: '-1px',\n borderRadius: 0,\n },\n}));\n\nexport interface TableCellProps extends Omit<MuiTableCellProps, 'tabIndex' | 'align'> {\n density: TableDensity;\n\n // These values are used to adjust the spacing for the first/last columns.\n isLastColumn: boolean;\n isFirstColumn: boolean;\n\n align?: TableCellAlignment;\n\n /**\n * Additional information to be displayed when hovering over the cell. This\n * may be the full cell value (e.g. to enable the user to see the full value\n * if it is ellipsized to fit into the space) or some other descriptive text\n * that is useful for the user.\n *\n * The hover behavior is currently managed with the `title` attribute, but this\n * may be changed to a tooltip in the future.\n */\n description?: string;\n\n /**\n * How the cell should behave related to focus.\n * - `trigger-focus`: the cell should be auto-focused when it renders.\n * - `focus-next`: the cell should have tabindex=\"0\", so that it will be\n * focused the next time someone tabs with a keyboard.\n * - `none`: the cell should have tabindex=\"-1\", so it is not focused by\n * keyboard interactions at this time.\n */\n focusState?: 'trigger-focus' | 'focus-next' | 'none';\n onFocusTrigger?: (e: React.MouseEvent<HTMLTableCellElement> | React.KeyboardEvent<HTMLTableCellElement>) => void;\n color?: string;\n backgroundColor?: string;\n}\n\nexport function TableCell({\n children,\n density,\n variant,\n width,\n focusState = 'none',\n onFocusTrigger,\n isFirstColumn,\n isLastColumn,\n description,\n align,\n color,\n backgroundColor,\n ...otherProps\n}: TableCellProps): ReactElement {\n const theme = useTheme();\n\n const elRef = useRef<HTMLTableCellElement>();\n\n const isHeader = variant === 'head';\n\n useEffect(() => {\n if (focusState === 'trigger-focus' && elRef.current) {\n elRef.current.focus();\n }\n }, [focusState]);\n\n const handleFocus: React.FocusEventHandler<HTMLTableCellElement> = (e) => {\n // From https://zellwk.com/blog/keyboard-focusable-elements/\n const nestedFocusTarget = e.currentTarget?.querySelector<HTMLElement>(\n 'a[href], button, input, textarea, select, details,[role=\"button\"]'\n );\n if (nestedFocusTarget) {\n // If the cell has a focusable child, focus it instead. Mostly used for\n // checkbox cells, but could have other uses.\n nestedFocusTarget.focus();\n }\n };\n\n const handleInteractionFocusTrigger: TableCellProps['onFocusTrigger'] = (e) => {\n // We use `onClick` and `onKeyUp` events instead of `onFocus` because of\n // some ordering issues with when the browser calls events and how this\n // plays with the triggering of focus with keyboard interactions.\n // These report that a focus event happened, so we can adjust the current\n // tabindex and focuses to the right cell.\n onFocusTrigger?.(e);\n };\n\n return (\n <StyledMuiTableCell\n {...otherProps}\n // Modify the tab index based on the currently focused cell. It's important\n // to avoid having tabindex 0 on everything because it essentially traps\n // a keyboard user in the table until they hit \"tab\" for every single\n // cell.\n tabIndex={focusState !== 'none' ? 0 : -1}\n onFocus={handleFocus}\n onClick={handleInteractionFocusTrigger}\n onKeyUp={handleInteractionFocusTrigger}\n style={{ width: width }}\n sx={{\n position: 'relative',\n borderBottom: isHeader ? `solid 1px ${theme.palette.grey[100]}` : `solid 1px ${theme.palette.grey[50]}`,\n '&:hover #original-cell': {\n position: 'absolute',\n top: 0,\n left: 0,\n zIndex: 10,\n width: 'fit-content',\n minWidth: '100%',\n whiteSpace: 'nowrap',\n overflow: 'visible',\n backgroundColor: `${backgroundColor ?? theme.palette.background.default} !important`,\n outline: `solid 1px ${theme.palette.info.main}`,\n outlineOffset: '-1px',\n },\n }}\n ref={elRef}\n >\n <Box\n id=\"original-cell\"\n sx={{\n ...getTableCellLayout(theme, density, { isLastColumn, isFirstColumn }),\n position: 'relative',\n\n // Text truncation. Currently enforced on all cells. We may control\n // this with a prop on column config in the future.\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n\n // Need to inherit from the MUI cell because this manages some ordering\n // that the `TableSortLabel` uses to determine the location of the icon\n // in headers.\n flexDirection: 'inherit',\n }}\n style={{\n backgroundColor: backgroundColor ?? 'inherit',\n color: color ?? 'inherit',\n }}\n title={description}\n aria-label={description}\n textAlign={align}\n >\n {children}\n </Box>\n </StyledMuiTableCell>\n );\n}\n"],"names":["TableCell","MuiTableCell","styled","Box","useTheme","useEffect","useRef","getTableCellLayout","StyledMuiTableCell","theme","padding","backgroundColor","palette","background","default","outline","primary","main","outlineOffset","borderRadius","children","density","variant","width","focusState","onFocusTrigger","isFirstColumn","isLastColumn","description","align","color","otherProps","elRef","isHeader","current","focus","handleFocus","e","nestedFocusTarget","currentTarget","querySelector","handleInteractionFocusTrigger","tabIndex","onFocus","onClick","onKeyUp","style","sx","position","borderBottom","grey","top","left","zIndex","minWidth","whiteSpace","overflow","info","ref","id","textOverflow","flexDirection","title","aria-label","textAlign"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAaC,YAAY,EAAEC,MAAM,EAAuCC,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AACtH,SAAuBC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AACxD,SAA2CC,kBAAkB,QAAQ,sBAAsB;AAE3F,MAAMC,qBAAqBN,OAAOD,cAAc,CAAC,EAAEQ,KAAK,EAAE,GAAM,CAAA;QAC9DC,SAAS;QACTC,iBAAiB;QAEjB,uBAAuB;YACrB,kEAAkE;YAClEA,iBAAiBF,MAAMG,OAAO,CAACC,UAAU,CAACC,OA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,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,EAAEzC,MAAMG,OAAO,CAACsC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvG,0BAA0B;gBACxBF,UAAU;gBACVG,KAAK;gBACLC,MAAM;gBACNC,QAAQ;gBACR9B,OAAO;gBACP+B,UAAU;gBACVC,YAAY;gBACZC,UAAU;gBACV7C,iBAAiB,CAAC,EAAEA,4BAAAA,6BAAAA,kBAAmBF,MAAMG,OAAO,CAACC,UAAU,CAACC,OAAO,CAAC,WAAW,CAAC;gBACpFC,SAAS,CAAC,UAAU,EAAEN,MAAMG,OAAO,CAAC6C,IAAI,CAACxC,IAAI,CAAC,CAAC;gBAC/CC,eAAe;YACjB;QACF;QACAwC,KAAK1B;kBAEL,cAAA,KAAC7B;YACCwD,IAAG;YACHZ,IAAI;gBACF,GAAGxC,mBAAmBE,OAAOY,SAAS;oBAAEM;oBAAcD;gBAAc,EAAE;gBACtEsB,UAAU;gBAEV,mEAAmE;gBACnE,mDAAmD;gBACnDO,YAAY;gBACZC,UAAU;gBACVI,cAAc;gBAEd,uEAAuE;gBACvE,uEAAuE;gBACvE,cAAc;gBACdC,eAAe;YACjB;YACAf,OAAO;gBACLnC,iBAAiBA,4BAAAA,6BAAAA,kBAAmB;gBACpCmB,OAAOA,kBAAAA,mBAAAA,QAAS;YAClB;YACAgC,OAAOlC;YACPmC,cAAYnC;YACZoC,WAAWnC;sBAEVT;;;AAIT"}
1
+ {"version":3,"sources":["../../src/Table/TableCell.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableCell as MuiTableCell, styled, TableCellProps as MuiTableCellProps, Box, useTheme } from '@mui/material';\nimport { ReactElement, useEffect, useRef } from 'react';\nimport { TableCellAlignment, TableDensity, getTableCellLayout } from './model/table-model';\n\nconst StyledMuiTableCell = styled(MuiTableCell)(({ theme }) => ({\n padding: 0,\n backgroundColor: 'inherit',\n\n '&.MuiTableCell-head': {\n // Important to avoid scrolling behind the header showing through.\n backgroundColor: theme.palette.background.default,\n },\n '&:focus-visible': {\n outline: `solid 1px ${theme.palette.primary.main}`,\n // Move inward a little to avoid getting cut off when focusing on items\n // at the edge of the table.\n outlineOffset: '-1px',\n borderRadius: 0,\n },\n}));\n\nexport interface TableCellProps extends Omit<MuiTableCellProps, 'tabIndex' | 'align'> {\n density: TableDensity;\n\n // These values are used to adjust the spacing for the first/last columns.\n isLastColumn: boolean;\n isFirstColumn: boolean;\n\n align?: TableCellAlignment;\n\n /**\n * Additional information to be displayed when hovering over the cell. This\n * may be the full cell value (e.g. to enable the user to see the full value\n * if it is ellipsized to fit into the space) or some other descriptive text\n * that is useful for the user.\n *\n * The hover behavior is currently managed with the `title` attribute, but this\n * may be changed to a tooltip in the future.\n */\n description?: string;\n\n /**\n * How the cell should behave related to focus.\n * - `trigger-focus`: the cell should be auto-focused when it renders.\n * - `focus-next`: the cell should have tabindex=\"0\", so that it will be\n * focused the next time someone tabs with a keyboard.\n * - `none`: the cell should have tabindex=\"-1\", so it is not focused by\n * keyboard interactions at this time.\n */\n focusState?: 'trigger-focus' | 'focus-next' | 'none';\n onFocusTrigger?: (e: React.MouseEvent<HTMLTableCellElement> | React.KeyboardEvent<HTMLTableCellElement>) => void;\n color?: string;\n backgroundColor?: string;\n}\n\nexport function TableCell({\n children,\n density,\n variant,\n width,\n focusState = 'none',\n onFocusTrigger,\n isFirstColumn,\n isLastColumn,\n description,\n align,\n color,\n backgroundColor,\n ...otherProps\n}: TableCellProps): ReactElement {\n const theme = useTheme();\n\n const elRef = useRef<HTMLTableCellElement>();\n\n const isHeader = variant === 'head';\n\n useEffect(() => {\n if (focusState === 'trigger-focus' && elRef.current) {\n elRef.current.focus();\n }\n }, [focusState]);\n\n const handleFocus: React.FocusEventHandler<HTMLTableCellElement> = (e) => {\n // From https://zellwk.com/blog/keyboard-focusable-elements/\n const nestedFocusTarget = e.currentTarget?.querySelector<HTMLElement>(\n 'a[href], button, input, textarea, select, details,[role=\"button\"]'\n );\n if (nestedFocusTarget) {\n // If the cell has a focusable child, focus it instead. Mostly used for\n // checkbox cells, but could have other uses.\n nestedFocusTarget.focus();\n }\n };\n\n const handleInteractionFocusTrigger: TableCellProps['onFocusTrigger'] = (e) => {\n // We use `onClick` and `onKeyUp` events instead of `onFocus` because of\n // some ordering issues with when the browser calls events and how this\n // plays with the triggering of focus with keyboard interactions.\n // These report that a focus event happened, so we can adjust the current\n // tabindex and focuses to the right cell.\n onFocusTrigger?.(e);\n };\n\n return (\n <StyledMuiTableCell\n {...otherProps}\n // Modify the tab index based on the currently focused cell. It's important\n // to avoid having tabindex 0 on everything because it essentially traps\n // a keyboard user in the table until they hit \"tab\" for every single\n // cell.\n tabIndex={focusState !== 'none' ? 0 : -1}\n onFocus={handleFocus}\n onClick={handleInteractionFocusTrigger}\n onKeyUp={handleInteractionFocusTrigger}\n style={{ width: width }}\n sx={{\n position: 'relative',\n borderBottom: isHeader ? `solid 1px ${theme.palette.grey[100]}` : `solid 1px ${theme.palette.grey[50]}`,\n '&:hover #original-cell': {\n position: 'absolute',\n top: 0,\n left: 0,\n zIndex: 10,\n width: 'fit-content',\n minWidth: '100%',\n whiteSpace: 'nowrap',\n overflow: 'visible',\n backgroundColor: `${backgroundColor ?? theme.palette.background.default} !important`,\n outline: `solid 1px ${theme.palette.info.main}`,\n outlineOffset: '-1px',\n },\n }}\n ref={elRef}\n >\n <Box\n id=\"original-cell\"\n sx={{\n ...getTableCellLayout(theme, density, { isLastColumn, isFirstColumn }),\n position: 'relative',\n\n // Text truncation. Currently enforced on all cells. We may control\n // this with a prop on column config in the future.\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n\n // Need to inherit from the MUI cell because this manages some ordering\n // that the `TableSortLabel` uses to determine the location of the icon\n // in headers.\n flexDirection: 'inherit',\n }}\n style={{\n backgroundColor: backgroundColor ?? 'inherit',\n color: color ?? 'inherit',\n }}\n title={description}\n aria-label={description}\n textAlign={align}\n >\n {children}\n </Box>\n </StyledMuiTableCell>\n );\n}\n"],"names":["TableCell","MuiTableCell","styled","Box","useTheme","useEffect","useRef","getTableCellLayout","StyledMuiTableCell","theme","padding","backgroundColor","palette","background","default","outline","primary","main","outlineOffset","borderRadius","children","density","variant","width","focusState","onFocusTrigger","isFirstColumn","isLastColumn","description","align","color","otherProps","elRef","isHeader","current","focus","handleFocus","e","nestedFocusTarget","currentTarget","querySelector","handleInteractionFocusTrigger","tabIndex","onFocus","onClick","onKeyUp","style","sx","position","borderBottom","grey","top","left","zIndex","minWidth","whiteSpace","overflow","info","ref","id","textOverflow","flexDirection","title","aria-label","textAlign"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAaC,YAAY,EAAEC,MAAM,EAAuCC,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AACtH,SAAuBC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AACxD,SAA2CC,kBAAkB,QAAQ,sBAAsB;AAE3F,MAAMC,qBAAqBN,OAAOD,cAAc,CAAC,EAAEQ,KAAK,EAAE,GAAM,CAAA;QAC9DC,SAAS;QACTC,iBAAiB;QAEjB,uBAAuB;YACrB,kEAAkE;YAClEA,iBAAiBF,MAAMG,OAAO,CAACC,UAAU,CAACC,OAAO;QACnD;QACA,mBAAmB;YACjBC,SAAS,CAAC,UAAU,EAAEN,MAAMG,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ACxBF,UAAU;gBACVG,KAAK;gBACLC,MAAM;gBACNC,QAAQ;gBACR9B,OAAO;gBACP+B,UAAU;gBACVC,YAAY;gBACZC,UAAU;gBACV7C,iBAAiB,CAAC,EAAEA,mBAAmBF,MAAMG,OAAO,CAACC,UAAU,CAACC,OAAO,CAAC,WAAW,CAAC;gBACpFC,SAAS,CAAC,UAAU,EAAEN,MAAMG,OAAO,CAAC6C,IAAI,CAACxC,IAAI,CAAC,CAAC;gBAC/CC,eAAe;YACjB;QACF;QACAwC,KAAK1B;kBAEL,cAAA,KAAC7B;YACCwD,IAAG;YACHZ,IAAI;gBACF,GAAGxC,mBAAmBE,OAAOY,SAAS;oBAAEM;oBAAcD;gBAAc,EAAE;gBACtEsB,UAAU;gBAEV,mEAAmE;gBACnE,mDAAmD;gBACnDO,YAAY;gBACZC,UAAU;gBACVI,cAAc;gBAEd,uEAAuE;gBACvE,uEAAuE;gBACvE,cAAc;gBACdC,eAAe;YACjB;YACAf,OAAO;gBACLnC,iBAAiBA,mBAAmB;gBACpCmB,OAAOA,SAAS;YAClB;YACAgC,OAAOlC;YACPmC,cAAYnC;YACZoC,WAAWnC;sBAEVT;;;AAIT"}
@@ -79,10 +79,10 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, o
79
79
  onClick: (e)=>onRowClick(e, row.id),
80
80
  density: density,
81
81
  onMouseOver: (e)=>{
82
- onRowMouseOver === null || onRowMouseOver === void 0 ? void 0 : onRowMouseOver(e, rowEventOpts);
82
+ onRowMouseOver?.(e, rowEventOpts);
83
83
  },
84
84
  onMouseOut: (e)=>{
85
- onRowMouseOut === null || onRowMouseOut === void 0 ? void 0 : onRowMouseOut(e, rowEventOpts);
85
+ onRowMouseOut?.(e, rowEventOpts);
86
86
  }
87
87
  });
88
88
  },
@@ -116,7 +116,6 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, o
116
116
  return /*#__PURE__*/ _jsx(TableRow, {
117
117
  density: density,
118
118
  children: headerGroup.headers.map((header, i, headers)=>{
119
- var _column_columnDef_meta, _column_columnDef_meta1;
120
119
  const column = header.column;
121
120
  const position = {
122
121
  row: 0,
@@ -129,10 +128,10 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, o
129
128
  sortDirection: typeof isSorted === 'string' ? isSorted : undefined,
130
129
  nextSortDirection: typeof nextSorting === 'string' ? nextSorting : undefined,
131
130
  width: column.getSize() || defaultColumnWidth,
132
- align: (_column_columnDef_meta = column.columnDef.meta) === null || _column_columnDef_meta === void 0 ? void 0 : _column_columnDef_meta.align,
131
+ align: column.columnDef.meta?.align,
133
132
  variant: "head",
134
133
  density: density,
135
- description: (_column_columnDef_meta1 = column.columnDef.meta) === null || _column_columnDef_meta1 === void 0 ? void 0 : _column_columnDef_meta1.headerDescription,
134
+ description: column.columnDef.meta?.headerDescription,
136
135
  focusState: getFocusState(position),
137
136
  onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
138
137
  isFirstColumn: i === 0,
@@ -151,17 +150,16 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, o
151
150
  }
152
151
  return /*#__PURE__*/ _jsx(_Fragment, {
153
152
  children: row.getVisibleCells().map((cell, i, cells)=>{
154
- var _cell_column_columnDef_meta, _cell_column_columnDef_meta1;
155
153
  const position = {
156
154
  // Add 1 to the row index because the header is row 0
157
155
  row: index + 1,
158
156
  column: i
159
157
  };
160
158
  const cellContext = cell.getContext();
161
- const cellConfig = cellConfigs === null || cellConfigs === void 0 ? void 0 : cellConfigs[cellContext.cell.id];
159
+ const cellConfig = cellConfigs?.[cellContext.cell.id];
162
160
  const cellRenderFn = cell.column.columnDef.cell;
163
161
  const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
164
- const cellDescriptionDef = (_cell_column_columnDef_meta = cell.column.columnDef.meta) === null || _cell_column_columnDef_meta === void 0 ? void 0 : _cell_column_columnDef_meta.cellDescription;
162
+ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
165
163
  let description = undefined;
166
164
  if (typeof cellDescriptionDef === 'function') {
167
165
  // If the cell description is a function, set the value using
@@ -173,21 +171,20 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, o
173
171
  // cell content.
174
172
  description = cellContent;
175
173
  }
176
- var _cellConfig_textColor, _cellConfig_backgroundColor;
177
174
  return /*#__PURE__*/ _jsx(TableCell, {
178
175
  "data-testid": cell.id,
179
- title: description || (cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.text) || cellContent,
176
+ title: description || cellConfig?.text || cellContent,
180
177
  width: cell.column.getSize() || defaultColumnWidth,
181
- align: (_cell_column_columnDef_meta1 = cell.column.columnDef.meta) === null || _cell_column_columnDef_meta1 === void 0 ? void 0 : _cell_column_columnDef_meta1.align,
178
+ align: cell.column.columnDef.meta?.align,
182
179
  density: density,
183
180
  focusState: getFocusState(position),
184
181
  onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
185
182
  isFirstColumn: i === 0,
186
183
  isLastColumn: i === cells.length - 1,
187
184
  description: description,
188
- color: (_cellConfig_textColor = cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.textColor) !== null && _cellConfig_textColor !== void 0 ? _cellConfig_textColor : undefined,
189
- backgroundColor: (_cellConfig_backgroundColor = cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.backgroundColor) !== null && _cellConfig_backgroundColor !== void 0 ? _cellConfig_backgroundColor : undefined,
190
- children: (cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.text) || cellContent
185
+ color: cellConfig?.textColor ?? undefined,
186
+ backgroundColor: cellConfig?.backgroundColor ?? undefined,
187
+ children: cellConfig?.text || cellContent
191
188
  }, cell.id);
192
189
  })
193
190
  });