@bundle-stats/ui 4.8.3 → 4.8.4

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 (126) hide show
  1. package/lib/components/bundle-assets/bundle-assets.js +28 -27
  2. package/lib/components/bundle-assets/bundle-assets.js.map +1 -1
  3. package/lib/components/bundle-modules/bundle-modules.i18n.js +12 -0
  4. package/lib/components/bundle-modules/bundle-modules.i18n.js.map +1 -0
  5. package/lib/components/bundle-modules/bundle-modules.js +12 -99
  6. package/lib/components/bundle-modules/bundle-modules.js.map +1 -1
  7. package/lib/components/bundle-modules/bundle-modules.utils.js +108 -1
  8. package/lib/components/bundle-modules/bundle-modules.utils.js.map +1 -1
  9. package/lib/components/bundle-modules/index.js +6 -45
  10. package/lib/components/bundle-modules/index.js.map +1 -1
  11. package/lib/components/entry-info/entry-info.i18n.js +7 -0
  12. package/lib/components/entry-info/entry-info.i18n.js.map +1 -0
  13. package/lib/components/entry-info/entry-info.js +27 -3
  14. package/lib/components/entry-info/entry-info.js.map +1 -1
  15. package/lib/components/job-name/job-name.js +1 -1
  16. package/lib/components/job-name/job-name.js.map +1 -1
  17. package/lib/components/metric-run-info/metric-run-info.js +10 -5
  18. package/lib/components/metric-run-info/metric-run-info.js.map +1 -1
  19. package/lib/components/metrics-table/index.js +1 -1
  20. package/lib/components/metrics-table/index.js.map +1 -1
  21. package/lib/components/metrics-table/metrics-table.i18n.js +12 -0
  22. package/lib/components/metrics-table/metrics-table.i18n.js.map +1 -0
  23. package/lib/components/metrics-table/metrics-table.js +50 -69
  24. package/lib/components/metrics-table/metrics-table.js.map +1 -1
  25. package/lib/components/metrics-table/metrics-table.module.css +2 -2
  26. package/lib/components/sort-button/sort-button.js +10 -4
  27. package/lib/components/sort-button/sort-button.js.map +1 -1
  28. package/lib/components/sort-button/sort-button.module.css +9 -9
  29. package/lib/hooks/rows-sort.js +1 -1
  30. package/lib/hooks/rows-sort.js.map +1 -1
  31. package/lib/ui/filters/filters.i18n.js +6 -0
  32. package/lib/ui/filters/filters.i18n.js.map +1 -0
  33. package/lib/ui/filters/filters.js +16 -54
  34. package/lib/ui/filters/filters.js.map +1 -1
  35. package/lib/ui/filters/filters.utils.js +27 -11
  36. package/lib/ui/filters/filters.utils.js.map +1 -1
  37. package/lib/ui/filters/index.js +0 -8
  38. package/lib/ui/filters/index.js.map +1 -1
  39. package/lib-esm/components/bundle-assets/bundle-assets.js +28 -27
  40. package/lib-esm/components/bundle-assets/bundle-assets.js.map +1 -1
  41. package/lib-esm/components/bundle-modules/bundle-modules.i18n.js +9 -0
  42. package/lib-esm/components/bundle-modules/bundle-modules.i18n.js.map +1 -0
  43. package/lib-esm/components/bundle-modules/bundle-modules.js +13 -101
  44. package/lib-esm/components/bundle-modules/bundle-modules.js.map +1 -1
  45. package/lib-esm/components/bundle-modules/bundle-modules.utils.js +83 -1
  46. package/lib-esm/components/bundle-modules/bundle-modules.utils.js.map +1 -1
  47. package/lib-esm/components/bundle-modules/index.js +9 -45
  48. package/lib-esm/components/bundle-modules/index.js.map +1 -1
  49. package/lib-esm/components/entry-info/entry-info.i18n.js +4 -0
  50. package/lib-esm/components/entry-info/entry-info.i18n.js.map +1 -0
  51. package/lib-esm/components/entry-info/entry-info.js +4 -3
  52. package/lib-esm/components/entry-info/entry-info.js.map +1 -1
  53. package/lib-esm/components/job-name/job-name.js +1 -1
  54. package/lib-esm/components/job-name/job-name.js.map +1 -1
  55. package/lib-esm/components/metric-run-info/metric-run-info.js +10 -5
  56. package/lib-esm/components/metric-run-info/metric-run-info.js.map +1 -1
  57. package/lib-esm/components/metrics-table/index.js +1 -1
  58. package/lib-esm/components/metrics-table/index.js.map +1 -1
  59. package/lib-esm/components/metrics-table/metrics-table.i18n.js +9 -0
  60. package/lib-esm/components/metrics-table/metrics-table.i18n.js.map +1 -0
  61. package/lib-esm/components/metrics-table/metrics-table.js +37 -79
  62. package/lib-esm/components/metrics-table/metrics-table.js.map +1 -1
  63. package/lib-esm/components/metrics-table/metrics-table.module.css +2 -2
  64. package/lib-esm/components/sort-button/sort-button.js +10 -4
  65. package/lib-esm/components/sort-button/sort-button.js.map +1 -1
  66. package/lib-esm/components/sort-button/sort-button.module.css +9 -9
  67. package/lib-esm/hooks/rows-sort.js +1 -1
  68. package/lib-esm/hooks/rows-sort.js.map +1 -1
  69. package/lib-esm/ui/filters/filters.i18n.js +3 -0
  70. package/lib-esm/ui/filters/filters.i18n.js.map +1 -0
  71. package/lib-esm/ui/filters/filters.js +16 -54
  72. package/lib-esm/ui/filters/filters.js.map +1 -1
  73. package/lib-esm/ui/filters/filters.utils.js +27 -11
  74. package/lib-esm/ui/filters/filters.utils.js.map +1 -1
  75. package/lib-esm/ui/filters/index.js +0 -8
  76. package/lib-esm/ui/filters/index.js.map +1 -1
  77. package/package.json +10 -10
  78. package/src/components/bundle-assets/bundle-assets.jsx +28 -30
  79. package/src/components/bundle-modules/bundle-modules.i18n.ts +8 -0
  80. package/src/components/bundle-modules/bundle-modules.tsx +200 -0
  81. package/src/components/bundle-modules/bundle-modules.types.d.ts +24 -0
  82. package/src/components/bundle-modules/bundle-modules.utils.ts +208 -0
  83. package/src/components/bundle-modules/index.tsx +102 -0
  84. package/src/components/entry-info/entry-info.i18n.ts +3 -0
  85. package/src/components/entry-info/entry-info.tsx +10 -4
  86. package/src/components/job-name/job-name.jsx +7 -1
  87. package/src/components/metric-run-info/metric-run-info.tsx +12 -5
  88. package/src/components/metrics-table/index.tsx +14 -0
  89. package/src/components/metrics-table/metrics-table.i18n.ts +10 -0
  90. package/src/components/metrics-table/metrics-table.module.css +2 -2
  91. package/src/components/metrics-table/metrics-table.stories.tsx +225 -0
  92. package/src/components/metrics-table/metrics-table.tsx +301 -0
  93. package/src/components/sort-button/sort-button.module.css +9 -9
  94. package/src/components/sort-button/sort-button.tsx +14 -6
  95. package/src/hooks/rows-sort.ts +9 -9
  96. package/src/types.d.ts +11 -0
  97. package/src/ui/filters/__tests__/filters.utils.ts +98 -0
  98. package/src/ui/filters/filters.i18n.ts +2 -0
  99. package/src/ui/filters/{filters.jsx → filters.tsx} +63 -72
  100. package/src/ui/filters/{filters.utils.js → filters.utils.ts} +38 -21
  101. package/src/ui/filters/{index.jsx → index.tsx} +14 -17
  102. package/types/components/bundle-modules/bundle-modules.d.ts +21 -62
  103. package/types/components/bundle-modules/bundle-modules.i18n.d.ts +8 -0
  104. package/types/components/bundle-modules/bundle-modules.utils.d.ts +28 -5
  105. package/types/components/bundle-modules/index.d.ts +13 -22
  106. package/types/components/entry-info/entry-info.i18n.d.ts +3 -0
  107. package/types/components/job-name/job-name.d.ts +1 -1
  108. package/types/components/metrics-table/index.d.ts +4 -1
  109. package/types/components/metrics-table/metrics-table.d.ts +25 -47
  110. package/types/components/metrics-table/metrics-table.i18n.d.ts +8 -0
  111. package/types/components/sort-button/sort-button.d.ts +2 -2
  112. package/types/hooks/rows-sort.d.ts +4 -4
  113. package/types/layout/box/box.d.ts +1 -1
  114. package/types/layout/flex-stack/flex-stack.d.ts +1 -1
  115. package/types/ui/filters/filters.d.ts +24 -14
  116. package/types/ui/filters/filters.i18n.d.ts +2 -0
  117. package/types/ui/filters/filters.utils.d.ts +7 -6
  118. package/types/ui/filters/index.d.ts +8 -12
  119. package/types/ui/table/table.d.ts +5 -5
  120. package/types/ui/tooltip/tooltip.d.ts +1 -1
  121. package/src/components/bundle-modules/bundle-modules.jsx +0 -291
  122. package/src/components/bundle-modules/bundle-modules.utils.js +0 -82
  123. package/src/components/bundle-modules/index.jsx +0 -113
  124. package/src/components/metrics-table/index.jsx +0 -11
  125. package/src/components/metrics-table/metrics-table.jsx +0 -309
  126. package/src/ui/filters/__tests__/filters-dropdown.utils.js +0 -74
@@ -0,0 +1,225 @@
1
+ import React from 'react';
2
+
3
+ import { MetricRunInfoDeltaType } from '@bundle-stats/utils';
4
+ import { getWrapperDecorator } from '../../stories';
5
+ import { MetricsTable } from '.';
6
+
7
+ const RUNS = [
8
+ {
9
+ internalBuildNumber: 2,
10
+ label: 'Job #2',
11
+ },
12
+ {
13
+ internalBuildNumber: 1,
14
+ label: <a href="#noop">Job #1</a>,
15
+ },
16
+ ];
17
+
18
+ const ITEMS_SINGLE_RUN = [
19
+ {
20
+ key: 'webpack.assets.totalSizeByTypeALL',
21
+ label: 'Total Size',
22
+ biggerIsBetter: false,
23
+ changed: false,
24
+ runs: [
25
+ {
26
+ value: 873421,
27
+ displayValue: '852.95KB',
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ key: 'lighthouse.timeToFirstByte',
33
+ label: 'Time To First Byte',
34
+ biggerIsBetter: false,
35
+ changed: false,
36
+ runs: [
37
+ {
38
+ value: 1231,
39
+ displayValue: '1.231s',
40
+ },
41
+ ],
42
+ },
43
+ {
44
+ key: 'lighthouse.score',
45
+ label: 'Score',
46
+ biggerIsBetter: true,
47
+ changed: false,
48
+ runs: [
49
+ {
50
+ value: 80,
51
+ displayValue: '80',
52
+ },
53
+ ],
54
+ },
55
+ {
56
+ key: 'webpack.assets.totalSizeByTypeJS',
57
+ label: 'JS',
58
+ biggerIsBetter: false,
59
+ changed: false,
60
+ runs: [
61
+ {
62
+ value: 344232,
63
+ displayValue: '336.16KB',
64
+ },
65
+ ],
66
+ },
67
+ {
68
+ key: 'lighthouse.domSize',
69
+ label: 'DOM Size',
70
+ biggerIsBetter: false,
71
+ changed: false,
72
+ runs: [
73
+ {
74
+ value: 80,
75
+ displayValue: '80',
76
+ },
77
+ ],
78
+ },
79
+ ];
80
+
81
+ const ITEMS_MULTIPLE_RUNS = [
82
+ {
83
+ key: 'webpack.assets.totalSizeByTypeALL',
84
+ label: 'Total Size',
85
+ biggerIsBetter: false,
86
+ changed: true,
87
+ runs: [
88
+ {
89
+ value: 873421,
90
+ displayValue: '852.95KB',
91
+ delta: 751090,
92
+ displayDelta: '+700KB',
93
+ deltaPercentage: 613.98,
94
+ displayDeltaPercentage: '+613.98%',
95
+ deltaType: 'HIGH_NEGATIVE' as MetricRunInfoDeltaType,
96
+ },
97
+ {
98
+ value: 122331,
99
+ displayValue: '119.46KB',
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ key: 'lighthouse.timeToFirstByte',
105
+ label: 'Time To First Byte',
106
+ biggerIsBetter: false,
107
+ changed: true,
108
+ runs: [
109
+ {
110
+ value: 1000,
111
+ displayValue: '1s',
112
+ delta: 20,
113
+ displayDelta: '+20ms',
114
+ deltaPercentage: 2.0408163,
115
+ displayDeltaPercentage: '+2.04%',
116
+ deltaType: 'LOW_NEGATIVE' as MetricRunInfoDeltaType,
117
+ },
118
+ {
119
+ value: 980,
120
+ displayValue: '980ms',
121
+ },
122
+ ],
123
+ },
124
+ {
125
+ key: 'lighthouse.score',
126
+ label: 'Score',
127
+ biggerIsBetter: true,
128
+ changed: true,
129
+ runs: [
130
+ {
131
+ value: 80,
132
+ displayValue: '80',
133
+ delta: 10,
134
+ displayDelta: '+10',
135
+ deltaPercentage: 14.2857143,
136
+ displayDeltaPercentage: '+14.29%',
137
+ deltaType: 'POSITIVE' as MetricRunInfoDeltaType,
138
+ },
139
+ {
140
+ value: 70,
141
+ displayValue: '70',
142
+ },
143
+ ],
144
+ },
145
+ {
146
+ key: 'lighthouse.accessibilityScore',
147
+ label: 'Accessibility score',
148
+ biggerIsBetter: true,
149
+ changed: true,
150
+ runs: [
151
+ {
152
+ value: 80,
153
+ displayValue: '80',
154
+ delta: 2,
155
+ displayDelta: '+2',
156
+ deltaPercentage: 2.5641026,
157
+ displayDeltaPercentage: '+2.56%',
158
+ deltaType: 'LOW_POSITIVE' as MetricRunInfoDeltaType,
159
+ },
160
+ {
161
+ value: 78,
162
+ displayValue: '78',
163
+ },
164
+ ],
165
+ },
166
+ {
167
+ key: 'webpack.assets.totalSizeByTypeJS',
168
+ label: 'JS',
169
+ biggerIsBetter: false,
170
+ changed: true,
171
+ runs: [
172
+ {
173
+ value: 344232,
174
+ displayValue: '336.16KB',
175
+ delta: 344232,
176
+ displayDelta: '+100%',
177
+ deltaPercentage: 100,
178
+ displayDeltaPercentage: '+100%',
179
+ deltaType: 'HIGH_NEGATIVE' as MetricRunInfoDeltaType,
180
+ },
181
+ null,
182
+ ],
183
+ },
184
+ {
185
+ key: 'lighthouse.domSize',
186
+ label: 'DOM Size',
187
+ biggerIsBetter: false,
188
+ changed: false,
189
+ runs: [
190
+ {
191
+ value: 80,
192
+ displayValue: '80',
193
+ delta: 0,
194
+ displayDelta: '0',
195
+ deltaPercentage: 0,
196
+ displayDeltaPercentage: '0%',
197
+ deltaType: 'NO_CHANGE' as MetricRunInfoDeltaType,
198
+ },
199
+ {
200
+ value: 80,
201
+ displayValue: '80',
202
+ },
203
+ ],
204
+ },
205
+ ];
206
+
207
+ export default {
208
+ title: 'Components/MetricsTable',
209
+ component: MetricsTable,
210
+ decorators: [getWrapperDecorator()],
211
+ };
212
+
213
+ export const Default = () => <MetricsTable runs={RUNS.slice(0, 1)} items={ITEMS_SINGLE_RUN} />;
214
+
215
+ export const MultipleRuns = () => <MetricsTable runs={RUNS} items={ITEMS_MULTIPLE_RUNS} />;
216
+
217
+ export const WithHeaderSum = () => (
218
+ <MetricsTable
219
+ runs={RUNS}
220
+ items={[ITEMS_MULTIPLE_RUNS[0], ITEMS_MULTIPLE_RUNS[4]]}
221
+ showHeaderSum
222
+ />
223
+ );
224
+
225
+ export const Empty = () => <MetricsTable runs={RUNS} items={[]} />;
@@ -0,0 +1,301 @@
1
+ import React from 'react';
2
+ import cx from 'classnames';
3
+ import isEmpty from 'lodash/isEmpty';
4
+ import sum from 'lodash/sum';
5
+ import {
6
+ METRIC_TYPE_CONFIGS,
7
+ type MetricRunInfo,
8
+ MetricTypes,
9
+ getMetricRunInfo,
10
+ } from '@bundle-stats/utils';
11
+
12
+ import { Icon } from '../../ui/icon';
13
+ import { Table } from '../../ui/table';
14
+ import { Stack } from '../../layout/stack';
15
+ import { Metric } from '../metric';
16
+ import { Delta } from '../delta';
17
+ import { JobName } from '../job-name';
18
+ import { SortButton } from '../sort-button';
19
+ import * as I18N from './metrics-table.i18n';
20
+ import css from './metrics-table.module.css';
21
+
22
+ const METRIC_TYPE = METRIC_TYPE_CONFIGS[MetricTypes.FileSize];
23
+ const VISIBLE_COUNT = 500;
24
+ const BASELINE_COLUMN_SPAN = 1;
25
+ const CURRENT_COLUMN_SPAN = 3;
26
+
27
+ interface Run {
28
+ /**
29
+ * Run job label
30
+ */
31
+ label?: React.ReactNode;
32
+ /**
33
+ * Job internal build number
34
+ */
35
+ internalBuildNumber: number;
36
+ }
37
+
38
+ interface Item {
39
+ key: string;
40
+ label?: string;
41
+ changed: boolean;
42
+ biggerIsBetter: boolean;
43
+ runs: Array<MetricRunInfo | null>;
44
+ }
45
+
46
+ const getRowsRunTotal = (rows: Array<Item>, runIndex: number): number =>
47
+ sum(rows.map((row) => row?.runs?.[runIndex]?.value || 0));
48
+
49
+ interface JobColumnProps {
50
+ run: Run;
51
+ isBaseline: boolean;
52
+ }
53
+
54
+ const JobColumn = ({ run, isBaseline }: JobColumnProps) => {
55
+ const colSpan = isBaseline ? BASELINE_COLUMN_SPAN : CURRENT_COLUMN_SPAN;
56
+ const { label, internalBuildNumber } = run;
57
+
58
+ if (!run) {
59
+ return <Table.Th colSpan={colSpan}>-</Table.Th>;
60
+ }
61
+
62
+ return (
63
+ <Table.Th className={css.jobCol} colSpan={colSpan}>
64
+ <JobName
65
+ title={isBaseline ? I18N.BASELINE_TITLE : I18N.CURRENT_TITLE}
66
+ internalBuildNumber={internalBuildNumber}
67
+ className={css.jobName}
68
+ >
69
+ {label}
70
+ </JobName>
71
+ </Table.Th>
72
+ );
73
+ };
74
+
75
+ interface ColumnSumProps {
76
+ rows: Array<Item>;
77
+ isBaseline: boolean;
78
+ runIndex: number;
79
+ sort?: any;
80
+ updateSort?: (val: any) => void;
81
+ }
82
+
83
+ const SumColumn = ({ rows, isBaseline, runIndex, updateSort, sort }: ColumnSumProps) => {
84
+ const currentRunTotal = getRowsRunTotal(rows, runIndex);
85
+ const baselineRunTotal = !isBaseline ? getRowsRunTotal(rows, runIndex + 1) : 0;
86
+ const total = getMetricRunInfo(METRIC_TYPE, currentRunTotal, baselineRunTotal);
87
+ const fieldPath = `runs[${runIndex}]`;
88
+
89
+ return (
90
+ <>
91
+ <Table.Th className={cx(css.value, css.sum)}>
92
+ <SortButton
93
+ fieldPath={fieldPath}
94
+ fieldName="value"
95
+ label={I18N.SORT_VALUE}
96
+ updateSort={updateSort}
97
+ sort={sort}
98
+ >
99
+ <Metric value={total.displayValue} />
100
+ </SortButton>
101
+ </Table.Th>
102
+ {!isBaseline && (
103
+ <>
104
+ <Table.Th className={cx(css.delta, css.sum)}>
105
+ <SortButton
106
+ fieldPath={fieldPath}
107
+ fieldName="delta"
108
+ label={I18N.SORT_CHANGE}
109
+ updateSort={updateSort}
110
+ sort={sort}
111
+ >
112
+ {'delta' in total && (
113
+ <Delta displayValue={total.displayDelta} deltaType={total.deltaType} />
114
+ )}
115
+ </SortButton>
116
+ </Table.Th>
117
+ <Table.Th className={cx(css.delta, css.deltaPercentage, css.sum)}>
118
+ <SortButton
119
+ fieldPath={fieldPath}
120
+ fieldName="deltaPercentage"
121
+ label={I18N.SORT_PERCENTUAL_CHANGE}
122
+ updateSort={updateSort}
123
+ sort={sort}
124
+ >
125
+ {'delta' in total && (
126
+ <Delta displayValue={total.displayDeltaPercentage} deltaType={total.deltaType} />
127
+ )}
128
+ </SortButton>
129
+ </Table.Th>
130
+ </>
131
+ )}
132
+ </>
133
+ );
134
+ };
135
+
136
+ interface RowProps extends React.ComponentProps<typeof Table.Tr> {
137
+ item: Item;
138
+ renderHeader: (item: Item) => React.ReactNode;
139
+ }
140
+
141
+ const Row = ({ className = '', item, renderHeader, ...restProps }: RowProps) => (
142
+ <Table.Tr className={cx(!item.changed && css.unchanged, className)} {...restProps}>
143
+ <Table.Th className={css.metricName}>{renderHeader(item)}</Table.Th>
144
+
145
+ {item.runs.map((run, index) => {
146
+ const isBaseline = index === item.runs.length - 1;
147
+ const valueClassName = cx(css.value, !isBaseline && css.current);
148
+
149
+ // Empty cells if no value
150
+ if (!run || typeof run.value === 'undefined') {
151
+ return (
152
+ <>
153
+ <Table.Td className={valueClassName}>-</Table.Td>
154
+ {!isBaseline && <Table.Td className={css.delta} />}
155
+ {!isBaseline && <Table.Td className={cx(css.delta, css.deltaPercentage)} />}
156
+ </>
157
+ );
158
+ }
159
+
160
+ return (
161
+ <>
162
+ <Table.Td className={valueClassName}>
163
+ <Metric value={run.displayValue} />
164
+ </Table.Td>
165
+ {!isBaseline && (
166
+ <>
167
+ <Table.Td className={css.delta}>
168
+ {'delta' in run && (
169
+ <Delta displayValue={run.displayDelta} deltaType={run.deltaType} />
170
+ )}
171
+ </Table.Td>
172
+ <Table.Td className={cx(css.delta, css.deltaPercentage)}>
173
+ {'delta' in run && (
174
+ <Delta displayValue={run.displayDeltaPercentage} deltaType={run.deltaType} />
175
+ )}
176
+ </Table.Td>
177
+ </>
178
+ )}
179
+ </>
180
+ );
181
+ })}
182
+ </Table.Tr>
183
+ );
184
+
185
+ interface MetricsTableProps extends Omit<React.ComponentProps<typeof Table>, 'title'> {
186
+ runs: Array<{
187
+ internalBuildNumber: number;
188
+ }>;
189
+ items: Array<Item>;
190
+ title?: React.ReactNode;
191
+ showHeaderSum?: boolean;
192
+ sort?: any;
193
+ updateSort?: (val: any) => void;
194
+ renderRowHeader?: (item: Item) => React.ReactNode;
195
+ emptyMessage?: React.ReactNode;
196
+ showAllItems: boolean;
197
+ setShowAllItems: (value: boolean) => void;
198
+ }
199
+
200
+ export const MetricsTable = ({
201
+ className = '',
202
+ runs,
203
+ items,
204
+ showHeaderSum = false,
205
+ title = '',
206
+ sort,
207
+ updateSort,
208
+ renderRowHeader = (item: any) => item.label,
209
+ emptyMessage = I18N.EMPTY_MESSAGE,
210
+ showAllItems,
211
+ setShowAllItems,
212
+ ...restProps
213
+ }: MetricsTableProps) => {
214
+ const columnCount = (runs.length - 1) * CURRENT_COLUMN_SPAN + BASELINE_COLUMN_SPAN + 1;
215
+
216
+ const rootClassName = cx(
217
+ css.root,
218
+ className,
219
+ runs.length > 1 && css.multipleRuns,
220
+ showHeaderSum && css.showHeaderSum,
221
+ );
222
+
223
+ const showEmpty = isEmpty(items);
224
+ const showItems = !showEmpty;
225
+ const hasHiddenItems = items?.length > VISIBLE_COUNT;
226
+ const visibleItems = !hasHiddenItems || showAllItems ? items : items?.slice(0, VISIBLE_COUNT);
227
+
228
+ return (
229
+ <Table className={rootClassName} compact {...restProps}>
230
+ <Table.THead>
231
+ <Table.Tr className={css.headerRow}>
232
+ <Table.Th className={css.metricName} rowSpan={showHeaderSum ? 2 : 1}>
233
+ {title || ' '}
234
+ </Table.Th>
235
+ {runs.map((run, runIndex) => (
236
+ <JobColumn run={run} isBaseline={runIndex === runs.length - 1} />
237
+ ))}
238
+ </Table.Tr>
239
+ {showHeaderSum && (
240
+ <Table.Tr className={css.headerRow}>
241
+ {runs.map((_, runIndex) => (
242
+ <SumColumn
243
+ rows={items}
244
+ isBaseline={runIndex === runs.length - 1}
245
+ runIndex={runIndex}
246
+ updateSort={updateSort}
247
+ sort={sort}
248
+ />
249
+ ))}
250
+ </Table.Tr>
251
+ )}
252
+ </Table.THead>
253
+ <Table.TBody>
254
+ {showEmpty && (
255
+ <Table.Tr>
256
+ <Table.Td className={css.empty} colSpan={columnCount}>
257
+ <Stack space="xxsmall">
258
+ <div>
259
+ <Icon glyph={Icon.ICONS.INFO} className={css.emptyIcon} size="large" />
260
+ </div>
261
+ {emptyMessage}
262
+ </Stack>
263
+ </Table.Td>
264
+ </Table.Tr>
265
+ )}
266
+
267
+ {showItems && (
268
+ <>
269
+ {visibleItems.map((item) => (
270
+ <Row key={item.key} item={item} renderHeader={renderRowHeader} />
271
+ ))}
272
+
273
+ {hasHiddenItems && (
274
+ <Table.Tr>
275
+ <Table.Td className={css.showAllItems} colSpan={columnCount}>
276
+ {showAllItems ? (
277
+ <button
278
+ onClick={() => setShowAllItems(false)}
279
+ type="button"
280
+ className={css.showAllItemsButton}
281
+ >
282
+ {I18N.SHOW_LESS}
283
+ </button>
284
+ ) : (
285
+ <button
286
+ onClick={() => setShowAllItems(true)}
287
+ type="button"
288
+ className={css.showAllItemsButton}
289
+ >
290
+ {I18N.SHOW_ALL}
291
+ </button>
292
+ )}
293
+ </Table.Td>
294
+ </Table.Tr>
295
+ )}
296
+ </>
297
+ )}
298
+ </Table.TBody>
299
+ </Table>
300
+ );
301
+ };
@@ -1,5 +1,5 @@
1
1
  .root {
2
- --icon-dimension: 15px;
2
+ --icon-dimension: 13px;
3
3
  display: inline-block;
4
4
  margin: calc(0px - var(--space-xxxsmall));
5
5
  margin-right: calc(0px - 1px - var(--icon-dimension));
@@ -18,13 +18,13 @@
18
18
  }
19
19
 
20
20
  .toggle {
21
- padding: var(--space-xxxsmall);
21
+ padding: 1px var(--space-xxxsmall);
22
22
  padding-right: calc(1px + var(--icon-dimension));
23
23
  }
24
24
 
25
25
  .direction {
26
26
  position: absolute;
27
- padding: 2px;
27
+ padding: 1px;
28
28
  display: block;
29
29
  overflow: hidden;
30
30
  right: -2px; /* compensate for the button padding */
@@ -68,9 +68,9 @@
68
68
  transform: translateY(-5px);
69
69
  }
70
70
 
71
- .root:hover,
72
- .root:active,
73
- .root:focus {
71
+ .interactive:hover,
72
+ .interactive:active,
73
+ .interactive:focus {
74
74
  background: var(--color-outline);
75
75
  }
76
76
 
@@ -80,9 +80,9 @@
80
80
  }
81
81
 
82
82
  .active .direction,
83
- .root:hover .direction,
84
- .root:active .direction,
85
- .root:focus .direction {
83
+ .interactive:hover .direction,
84
+ .interactive:hover:active .direction,
85
+ .interactive:hover:focus .direction {
86
86
  pointer-events: auto;
87
87
  opacity: 1;
88
88
  transition: var(--transition-in);
@@ -12,7 +12,7 @@ interface SortInfo {
12
12
  title: string;
13
13
  }
14
14
 
15
- const getToggleAction = (sort: SortAction, field: string, label: string): SortInfo => {
15
+ const getToggleAction = (field: string, label: string, sort?: SortAction): SortInfo => {
16
16
  // Sort the column desc if not currently sorted
17
17
  if (sort?.field !== field) {
18
18
  return { direction: SORT.DESC, title: `Order ${label} descending` };
@@ -39,21 +39,25 @@ interface SortButtonProps {
39
39
  fieldPath: string;
40
40
  fieldName: string;
41
41
  label: string;
42
- sort: SortAction;
43
- updateSort: (params: SortAction) => void;
42
+ sort?: SortAction;
43
+ updateSort?: (params: SortAction) => void;
44
44
  }
45
45
 
46
46
  export const SortButton = (props: SortButtonProps & React.ComponentProps<'div'>) => {
47
47
  const { className = '', children, fieldPath, fieldName, label, sort, updateSort } = props;
48
48
 
49
49
  const field = `${fieldPath}.${fieldName}`;
50
- const toggleAction = getToggleAction(sort, field, label);
50
+ const toggleAction = getToggleAction(field, label, sort);
51
51
  const ascAction = getAscAction(label);
52
52
  const descAction = getDescAction(label);
53
- const isSorted = sort.field === field;
53
+ const isSorted = sort?.field === field;
54
54
 
55
55
  const getOrderOnClick = useCallback(
56
56
  (action: SortInfo) => () => {
57
+ if (!updateSort) {
58
+ return;
59
+ }
60
+
57
61
  if (action.direction) {
58
62
  updateSort({ field, direction: action.direction as SortAction['direction'] });
59
63
  return;
@@ -64,8 +68,12 @@ export const SortButton = (props: SortButtonProps & React.ComponentProps<'div'>)
64
68
  [field, updateSort, toggleAction],
65
69
  );
66
70
 
71
+ if (!updateSort) {
72
+ return <div className={cx(css.root, className)}>{children}</div>;
73
+ }
74
+
67
75
  return (
68
- <div className={cx(css.root, className, isSorted && css.active)}>
76
+ <div className={cx(css.root, css.interactive, className, isSorted && css.active)}>
69
77
  <Tooltip
70
78
  title={toggleAction.title}
71
79
  as="button"
@@ -7,9 +7,9 @@ import { SORT } from '../constants';
7
7
 
8
8
  interface UseRowsSortParams {
9
9
  rows: Array<unknown>;
10
- initialField: string;
11
- initialDirection: SortAction['direction'];
12
- getCustomSort: (item: unknown) => Array<string | number | boolean>;
10
+ initialField?: string;
11
+ initialDirection?: SortAction['direction'];
12
+ getCustomSort: (item: any) => Array<string | number | boolean>;
13
13
  }
14
14
 
15
15
  export const getSortFn =
@@ -18,7 +18,7 @@ export const getSortFn =
18
18
  return getCustomSort(item);
19
19
  }
20
20
 
21
- return Math.abs(get(item, fieldPath) || 0);
21
+ return get(item, fieldPath) || 0;
22
22
  };
23
23
 
24
24
  export const useRowsSort = ({
@@ -32,11 +32,11 @@ export const useRowsSort = ({
32
32
  const orderedRows = useMemo(
33
33
  () =>
34
34
  orderBy(
35
- rows,
36
- getSortFn(sort.field, getCustomSort),
37
- // if direction is empty (reset), sort asc
38
- sort.direction !== '' ? sort.direction : (SORT.ASC as any),
39
- ),
35
+ rows,
36
+ getSortFn(sort.field, getCustomSort),
37
+ // if direction is empty (reset), sort asc
38
+ sort.direction !== '' ? sort.direction : (SORT.ASC as any),
39
+ ),
40
40
  [rows, sort],
41
41
  );
42
42
 
package/src/types.d.ts CHANGED
@@ -2,3 +2,14 @@ export interface SortAction {
2
2
  field: string;
3
3
  direction: 'asc' | 'desc' | '';
4
4
  }
5
+
6
+ interface FilterFieldData {
7
+ label: string;
8
+ defaultValue: boolean;
9
+ disabled?: boolean;
10
+ }
11
+ type FilterGroupFieldData = {
12
+ label: string;
13
+ children: Array<{ key: string } & FilterFieldData>;
14
+ };
15
+ type FilterFieldsData = Record<string, FilterFieldData | FilterGroupFieldData>;