@perses-dev/components 0.53.1 → 0.54.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/FormEditor/FormActions.d.ts +1 -1
- package/dist/FormEditor/FormActions.d.ts.map +1 -1
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.d.ts +1 -1
- package/dist/FormatControls/FormatControls.d.ts.map +1 -1
- package/dist/FormatControls/FormatControls.js +1 -1
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.d.ts +1 -1
- package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
- package/dist/FormatControls/UnitSelector.js +1 -1
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/Legend/Legend.js +1 -1
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +1 -1
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/LinksEditor/LinksEditor.d.ts +1 -1
- package/dist/LinksEditor/LinksEditor.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +26 -6
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +34 -0
- package/dist/Table/TableToolbar.d.ts.map +1 -0
- package/dist/Table/TableToolbar.js +127 -0
- package/dist/Table/TableToolbar.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +3 -1
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +128 -117
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +5 -1
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +12 -0
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
- package/dist/Table/hooks/useFuzzySearch.js +43 -0
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +38 -4
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +2 -3
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +2 -0
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeRangeSelector/utils.d.ts +1 -1
- package/dist/TimeRangeSelector/utils.js +1 -1
- package/dist/TimeRangeSelector/utils.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +2 -2
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
- package/dist/cjs/FormatControls/FormatControls.js +4 -4
- package/dist/cjs/FormatControls/UnitSelector.js +3 -3
- package/dist/cjs/Legend/Legend.js +2 -2
- package/dist/cjs/Table/Table.js +24 -4
- package/dist/cjs/Table/TableToolbar.js +140 -0
- package/dist/cjs/Table/VirtualizedTable.js +126 -115
- package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
- package/dist/cjs/Table/hooks/useFuzzySearch.js +48 -0
- package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +2 -0
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +3 -3
- package/dist/cjs/TimeRangeSelector/utils.js +2 -2
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
- package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
- package/dist/cjs/model/action.js +43 -0
- package/dist/cjs/model/bits.js +113 -0
- package/dist/cjs/model/bytes.js +115 -0
- package/dist/cjs/model/constants.js +23 -0
- package/dist/cjs/model/currency.js +126 -0
- package/dist/cjs/model/date.js +297 -0
- package/dist/cjs/model/decimal.js +72 -0
- package/dist/cjs/model/formatterCache.js +120 -0
- package/dist/cjs/model/index.js +16 -0
- package/dist/cjs/model/legend.js +101 -0
- package/dist/cjs/model/percent.js +82 -0
- package/dist/cjs/model/temperature.js +72 -0
- package/dist/cjs/model/thresholds.js +16 -0
- package/dist/cjs/model/throughput.js +161 -0
- package/dist/cjs/model/time.js +178 -0
- package/dist/cjs/model/timeOption.js +2 -2
- package/dist/cjs/model/transforms.js +29 -0
- package/dist/cjs/model/types.js +16 -0
- package/dist/cjs/model/units.js +186 -0
- package/dist/cjs/model/utils.js +48 -0
- package/dist/cjs/theme/theme.js +44 -29
- package/dist/cjs/theme/typography.js +8 -7
- package/dist/cjs/utils/axis.js +5 -5
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/request-interpolation.js +49 -0
- package/dist/model/action.d.ts +4 -0
- package/dist/model/action.d.ts.map +1 -0
- package/dist/model/action.js +27 -0
- package/dist/model/action.js.map +1 -0
- package/dist/model/bits.d.ts +12 -0
- package/dist/model/bits.d.ts.map +1 -0
- package/dist/model/bits.js +89 -0
- package/dist/model/bits.js.map +1 -0
- package/dist/model/bytes.d.ts +12 -0
- package/dist/model/bytes.d.ts.map +1 -0
- package/dist/model/bytes.js +91 -0
- package/dist/model/bytes.js.map +1 -0
- package/dist/model/constants.d.ts +2 -0
- package/dist/model/constants.d.ts.map +1 -0
- package/dist/model/constants.js +15 -0
- package/dist/model/constants.js.map +1 -0
- package/dist/model/currency.d.ts +11 -0
- package/dist/model/currency.d.ts.map +1 -0
- package/dist/model/currency.js +107 -0
- package/dist/model/currency.js.map +1 -0
- package/dist/model/date.d.ts +28 -0
- package/dist/model/date.d.ts.map +1 -0
- package/dist/model/date.js +278 -0
- package/dist/model/date.js.map +1 -0
- package/dist/model/decimal.d.ts +12 -0
- package/dist/model/decimal.d.ts.map +1 -0
- package/dist/model/decimal.js +53 -0
- package/dist/model/decimal.js.map +1 -0
- package/dist/model/formatterCache.d.ts +11 -0
- package/dist/model/formatterCache.d.ts.map +1 -0
- package/dist/model/formatterCache.js +104 -0
- package/dist/model/formatterCache.js.map +1 -0
- package/dist/model/graph.d.ts +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/index.d.ts +16 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +16 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +19 -0
- package/dist/model/legend.d.ts.map +1 -0
- package/dist/model/legend.js +61 -0
- package/dist/model/legend.js.map +1 -0
- package/dist/model/percent.d.ts +11 -0
- package/dist/model/percent.d.ts.map +1 -0
- package/dist/model/percent.js +63 -0
- package/dist/model/percent.js.map +1 -0
- package/dist/model/temperature.d.ts +11 -0
- package/dist/model/temperature.d.ts.map +1 -0
- package/dist/model/temperature.js +53 -0
- package/dist/model/temperature.js.map +1 -0
- package/dist/model/theme.d.ts +1 -1
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/thresholds.d.ts +16 -0
- package/dist/model/thresholds.d.ts.map +1 -0
- package/dist/model/thresholds.js +15 -0
- package/dist/model/thresholds.js.map +1 -0
- package/dist/model/throughput.d.ts +12 -0
- package/dist/model/throughput.d.ts.map +1 -0
- package/dist/model/throughput.js +142 -0
- package/dist/model/throughput.js.map +1 -0
- package/dist/model/time.d.ts +23 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +158 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/timeOption.d.ts +1 -1
- package/dist/model/timeOption.js +1 -1
- package/dist/model/timeOption.js.map +1 -1
- package/dist/model/transforms.d.ts +43 -0
- package/dist/model/transforms.d.ts.map +1 -0
- package/dist/model/transforms.js +22 -0
- package/dist/model/transforms.js.map +1 -0
- package/dist/model/types.d.ts +56 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +15 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/units.d.ts +105 -0
- package/dist/model/units.d.ts.map +1 -0
- package/dist/model/units.js +132 -0
- package/dist/model/units.js.map +1 -0
- package/dist/model/utils.d.ts +4 -0
- package/dist/model/utils.d.ts.map +1 -0
- package/dist/model/utils.js +32 -0
- package/dist/model/utils.js.map +1 -0
- package/dist/theme/theme.d.ts +3 -1
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +46 -29
- package/dist/theme/theme.js.map +1 -1
- package/dist/theme/typography.d.ts +6 -4
- package/dist/theme/typography.d.ts.map +1 -1
- package/dist/theme/typography.js +8 -7
- package/dist/theme/typography.js.map +1 -1
- package/dist/utils/axis.d.ts +1 -1
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +1 -1
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/chart-actions.d.ts +1 -1
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/request-interpolation.d.ts +6 -0
- package/dist/utils/request-interpolation.d.ts.map +1 -0
- package/dist/utils/request-interpolation.js +33 -0
- package/dist/utils/request-interpolation.js.map +1 -0
- package/dist/utils/variable-interpolation.d.ts +1 -1
- package/dist/utils/variable-interpolation.js.map +1 -1
- package/package.json +6 -2
|
@@ -25,6 +25,7 @@ const _reacttable = require("@tanstack/react-table");
|
|
|
25
25
|
const _material = require("@mui/material");
|
|
26
26
|
const _reactvirtuoso = require("react-virtuoso");
|
|
27
27
|
const _react = require("react");
|
|
28
|
+
const _TableToolbar = require("./TableToolbar");
|
|
28
29
|
const _TableRow = require("./TableRow");
|
|
29
30
|
const _TableBody = require("./TableBody");
|
|
30
31
|
const _InnerTable = require("./InnerTable");
|
|
@@ -34,7 +35,7 @@ const _TableCell = require("./TableCell");
|
|
|
34
35
|
const _VirtualizedTableContainer = require("./VirtualizedTableContainer");
|
|
35
36
|
const _useVirtualizedTableKeyboardNav = require("./hooks/useVirtualizedTableKeyboardNav");
|
|
36
37
|
const _TableFoot = require("./TableFoot");
|
|
37
|
-
function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount }) {
|
|
38
|
+
function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, toolbarConfig }) {
|
|
38
39
|
const virtuosoRef = (0, _react.useRef)(null);
|
|
39
40
|
// Use a ref for these values because they are only needed for keyboard
|
|
40
41
|
// focus interactions and setting them on state will lead to a significant
|
|
@@ -122,129 +123,139 @@ function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultC
|
|
|
122
123
|
pageSize: parseInt(event.target.value, 10)
|
|
123
124
|
});
|
|
124
125
|
};
|
|
125
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
127
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
128
|
+
style: {
|
|
129
|
+
width,
|
|
130
|
+
height,
|
|
131
|
+
display: 'flex',
|
|
132
|
+
flexDirection: 'column'
|
|
133
|
+
},
|
|
134
|
+
children: [
|
|
135
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_TableToolbar.TableToolbar, {
|
|
136
|
+
...toolbarConfig,
|
|
137
|
+
width: width
|
|
138
|
+
}),
|
|
139
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_reactvirtuoso.TableVirtuoso, {
|
|
140
|
+
ref: virtuosoRef,
|
|
141
|
+
totalCount: rows.length,
|
|
142
|
+
components: VirtuosoTableComponents,
|
|
143
|
+
// Note: this value is impacted by overscan. See this issue if overscan
|
|
144
|
+
// is added.
|
|
145
|
+
// https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138
|
|
146
|
+
rangeChanged: setVisibleRange,
|
|
147
|
+
fixedHeaderContent: ()=>{
|
|
148
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
149
|
+
children: headers.map((headerGroup)=>{
|
|
150
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TableRow.TableRow, {
|
|
151
|
+
density: density,
|
|
152
|
+
children: headerGroup.headers.map((header, i, headers)=>{
|
|
153
|
+
const column = header.column;
|
|
154
|
+
const position = {
|
|
155
|
+
row: 0,
|
|
156
|
+
column: i
|
|
157
|
+
};
|
|
158
|
+
const isSorted = column.getIsSorted();
|
|
159
|
+
const nextSorting = column.getNextSortingOrder();
|
|
160
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TableHeaderCell.TableHeaderCell, {
|
|
161
|
+
onSort: column.getCanSort() ? column.getToggleSortingHandler() : undefined,
|
|
162
|
+
sortDirection: typeof isSorted === 'string' ? isSorted : undefined,
|
|
163
|
+
nextSortDirection: typeof nextSorting === 'string' ? nextSorting : undefined,
|
|
164
|
+
width: column.getSize() || defaultColumnWidth,
|
|
165
|
+
defaultColumnHeight: defaultColumnHeight,
|
|
166
|
+
align: column.columnDef.meta?.align,
|
|
167
|
+
variant: "head",
|
|
168
|
+
density: density,
|
|
169
|
+
description: column.columnDef.meta?.headerDescription,
|
|
170
|
+
focusState: getFocusState(position),
|
|
171
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
172
|
+
isFirstColumn: i === 0,
|
|
173
|
+
isLastColumn: i === headers.length - 1,
|
|
174
|
+
children: (0, _reacttable.flexRender)(column.columnDef.header, header.getContext())
|
|
175
|
+
}, header.id);
|
|
176
|
+
})
|
|
177
|
+
}, headerGroup.id);
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TableRow, {
|
|
182
|
+
sx: {
|
|
183
|
+
backgroundColor: (theme)=>theme.palette.background.default
|
|
184
|
+
},
|
|
185
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TablePagination, {
|
|
186
|
+
colSpan: columns.length,
|
|
187
|
+
count: rowCount,
|
|
188
|
+
page: pagination.pageIndex,
|
|
189
|
+
rowsPerPage: pagination.pageSize,
|
|
190
|
+
onPageChange: handleChangePage,
|
|
191
|
+
onRowsPerPageChange: handleChangeRowsPerPage
|
|
192
|
+
})
|
|
193
|
+
}) : undefined,
|
|
194
|
+
itemContent: (index)=>{
|
|
195
|
+
const row = rows[index];
|
|
196
|
+
if (!row) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
200
|
+
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
145
201
|
const position = {
|
|
146
|
-
row:
|
|
202
|
+
row: index + 1,
|
|
147
203
|
column: i
|
|
148
204
|
};
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
205
|
+
const cellContext = cell.getContext();
|
|
206
|
+
const cellConfig = cellConfigs?.[cellContext.cell.id];
|
|
207
|
+
const cellRenderFn = cell.column.columnDef.cell;
|
|
208
|
+
const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
|
|
209
|
+
/*
|
|
210
|
+
IMPORTANT:
|
|
211
|
+
If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)
|
|
212
|
+
Components have no access to any context (Which is intentional and correct)
|
|
213
|
+
We may want to add parameters to a link from neighboring cells in the future as well.
|
|
214
|
+
If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)
|
|
215
|
+
*/ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
|
|
216
|
+
let description = undefined;
|
|
217
|
+
if (typeof cellDescriptionDef === 'function') {
|
|
218
|
+
// If the cell description is a function, set the value using
|
|
219
|
+
// the function.
|
|
220
|
+
description = cellDescriptionDef(cellContext);
|
|
221
|
+
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
222
|
+
// If the cell description is `true` AND the cell content is
|
|
223
|
+
// a string (and thus viable as a `title` attribute), use the
|
|
224
|
+
// cell content.
|
|
225
|
+
description = cellContent;
|
|
226
|
+
}
|
|
227
|
+
/* this has been specifically added for the data link,
|
|
228
|
+
therefore, non string and numeric values should be excluded
|
|
229
|
+
*/ const adjacentCellsValuesMap = Object.entries(row.original)?.filter(([_, value])=>[
|
|
230
|
+
'string',
|
|
231
|
+
'number'
|
|
232
|
+
].includes(typeof value)).reduce((acc, [key, value])=>({
|
|
233
|
+
...acc,
|
|
234
|
+
[key]: String(value)
|
|
235
|
+
}), {});
|
|
236
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TableCell.TableCell, {
|
|
237
|
+
"data-testid": cell.id,
|
|
238
|
+
title: description || cellConfig?.text || cellContent,
|
|
239
|
+
width: cell.column.getSize() || defaultColumnWidth,
|
|
156
240
|
defaultColumnHeight: defaultColumnHeight,
|
|
157
|
-
align: column.columnDef.meta?.align,
|
|
158
|
-
variant: "head",
|
|
241
|
+
align: cell.column.columnDef.meta?.align,
|
|
159
242
|
density: density,
|
|
160
|
-
description: column.columnDef.meta?.headerDescription,
|
|
161
243
|
focusState: getFocusState(position),
|
|
162
244
|
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
163
245
|
isFirstColumn: i === 0,
|
|
164
|
-
isLastColumn: i ===
|
|
165
|
-
|
|
166
|
-
|
|
246
|
+
isLastColumn: i === cells.length - 1,
|
|
247
|
+
description: description,
|
|
248
|
+
color: cellConfig?.textColor ?? undefined,
|
|
249
|
+
backgroundColor: cellConfig?.backgroundColor ?? undefined,
|
|
250
|
+
dataLink: cell.column.columnDef.meta?.dataLink,
|
|
251
|
+
adjacentCellsValuesMap: adjacentCellsValuesMap,
|
|
252
|
+
children: cellConfig?.text || cellContent
|
|
253
|
+
}, cell.id);
|
|
167
254
|
})
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TableRow, {
|
|
173
|
-
sx: {
|
|
174
|
-
backgroundColor: (theme)=>theme.palette.background.default
|
|
175
|
-
},
|
|
176
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TablePagination, {
|
|
177
|
-
colSpan: columns.length,
|
|
178
|
-
count: rowCount,
|
|
179
|
-
page: pagination.pageIndex,
|
|
180
|
-
rowsPerPage: pagination.pageSize,
|
|
181
|
-
onPageChange: handleChangePage,
|
|
182
|
-
onRowsPerPageChange: handleChangeRowsPerPage
|
|
183
|
-
})
|
|
184
|
-
}) : undefined,
|
|
185
|
-
itemContent: (index)=>{
|
|
186
|
-
const row = rows[index];
|
|
187
|
-
if (!row) {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
191
|
-
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
192
|
-
const position = {
|
|
193
|
-
row: index + 1,
|
|
194
|
-
column: i
|
|
195
|
-
};
|
|
196
|
-
const cellContext = cell.getContext();
|
|
197
|
-
const cellConfig = cellConfigs?.[cellContext.cell.id];
|
|
198
|
-
const cellRenderFn = cell.column.columnDef.cell;
|
|
199
|
-
const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
|
|
200
|
-
/*
|
|
201
|
-
IMPORTANT:
|
|
202
|
-
If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)
|
|
203
|
-
Components have no access to any context (Which is intentional and correct)
|
|
204
|
-
We may want to add parameters to a link from neighboring cells in the future as well.
|
|
205
|
-
If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)
|
|
206
|
-
*/ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
|
|
207
|
-
let description = undefined;
|
|
208
|
-
if (typeof cellDescriptionDef === 'function') {
|
|
209
|
-
// If the cell description is a function, set the value using
|
|
210
|
-
// the function.
|
|
211
|
-
description = cellDescriptionDef(cellContext);
|
|
212
|
-
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
213
|
-
// If the cell description is `true` AND the cell content is
|
|
214
|
-
// a string (and thus viable as a `title` attribute), use the
|
|
215
|
-
// cell content.
|
|
216
|
-
description = cellContent;
|
|
217
|
-
}
|
|
218
|
-
/* this has been specifically added for the data link,
|
|
219
|
-
therefore, non string and numeric values should be excluded
|
|
220
|
-
*/ const adjacentCellsValuesMap = Object.entries(row.original)?.filter(([_, value])=>[
|
|
221
|
-
'string',
|
|
222
|
-
'number'
|
|
223
|
-
].includes(typeof value)).reduce((acc, [key, value])=>({
|
|
224
|
-
...acc,
|
|
225
|
-
[key]: String(value)
|
|
226
|
-
}), {});
|
|
227
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TableCell.TableCell, {
|
|
228
|
-
"data-testid": cell.id,
|
|
229
|
-
title: description || cellConfig?.text || cellContent,
|
|
230
|
-
width: cell.column.getSize() || defaultColumnWidth,
|
|
231
|
-
defaultColumnHeight: defaultColumnHeight,
|
|
232
|
-
align: cell.column.columnDef.meta?.align,
|
|
233
|
-
density: density,
|
|
234
|
-
focusState: getFocusState(position),
|
|
235
|
-
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
236
|
-
isFirstColumn: i === 0,
|
|
237
|
-
isLastColumn: i === cells.length - 1,
|
|
238
|
-
description: description,
|
|
239
|
-
color: cellConfig?.textColor ?? undefined,
|
|
240
|
-
backgroundColor: cellConfig?.backgroundColor ?? undefined,
|
|
241
|
-
dataLink: cell.column.columnDef.meta?.dataLink,
|
|
242
|
-
adjacentCellsValuesMap: adjacentCellsValuesMap,
|
|
243
|
-
children: cellConfig?.text || cellContent
|
|
244
|
-
}, cell.id);
|
|
245
|
-
})
|
|
246
|
-
});
|
|
247
|
-
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
]
|
|
248
259
|
})
|
|
249
260
|
});
|
|
250
261
|
}
|
|
@@ -23,10 +23,14 @@ Object.defineProperty(exports, "VirtualizedTableContainer", {
|
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
25
|
const _react = require("react");
|
|
26
|
+
const _combinesx = require("../utils/combine-sx");
|
|
26
27
|
const VirtualizedTableContainer = /*#__PURE__*/ (0, _react.forwardRef)(function VirtualizedTableContainer(props, ref) {
|
|
27
28
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TableContainer, {
|
|
28
29
|
...props,
|
|
29
30
|
tabIndex: -1,
|
|
30
|
-
ref: ref
|
|
31
|
+
ref: ref,
|
|
32
|
+
sx: (0, _combinesx.combineSx)({
|
|
33
|
+
flexGrow: 1
|
|
34
|
+
}, props.sx)
|
|
31
35
|
});
|
|
32
36
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useFuzzySearch", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return useFuzzySearch;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _reacttable = require("@tanstack/react-table");
|
|
24
|
+
const _matchsorterutils = require("@tanstack/match-sorter-utils");
|
|
25
|
+
const _react = require("react");
|
|
26
|
+
const fuzzyFilter = (row, columnId, value, addMeta)=>{
|
|
27
|
+
const itemRank = (0, _matchsorterutils.rankItem)(row.getValue(columnId), value);
|
|
28
|
+
addMeta({
|
|
29
|
+
itemRank
|
|
30
|
+
});
|
|
31
|
+
return itemRank.passed;
|
|
32
|
+
};
|
|
33
|
+
function useFuzzySearch(isSearchEnabled) {
|
|
34
|
+
const [globalFilter, setGlobalFilter] = (0, _react.useState)('');
|
|
35
|
+
return {
|
|
36
|
+
globalFilter,
|
|
37
|
+
setGlobalFilter,
|
|
38
|
+
fuzzySearchOptions: {
|
|
39
|
+
filterFns: {
|
|
40
|
+
fuzzy: fuzzyFilter
|
|
41
|
+
},
|
|
42
|
+
globalFilterFn: isSearchEnabled ? 'fuzzy' : undefined,
|
|
43
|
+
getFilteredRowModel: isSearchEnabled ? (0, _reacttable.getFilteredRowModel)() : undefined,
|
|
44
|
+
filterFromLeafRows: isSearchEnabled,
|
|
45
|
+
onGlobalFilterChange: setGlobalFilter
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -146,6 +146,7 @@ const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel, timeZone })
|
|
|
146
146
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_ErrorBoundary.ErrorBoundary, {
|
|
147
147
|
FallbackComponent: _ErrorAlert.ErrorAlert,
|
|
148
148
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_xdatepickers.DateTimeField, {
|
|
149
|
+
"data-testid": "start_time_input",
|
|
149
150
|
timezone: stdTimeZone,
|
|
150
151
|
label: "Start Time",
|
|
151
152
|
value: new _tz.TZDate(timeRange.start, stdTimeZone),
|
|
@@ -161,6 +162,7 @@ const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel, timeZone })
|
|
|
161
162
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_ErrorBoundary.ErrorBoundary, {
|
|
162
163
|
FallbackComponent: _ErrorAlert.ErrorAlert,
|
|
163
164
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_xdatepickers.DateTimeField, {
|
|
165
|
+
"data-testid": "end_time_input",
|
|
164
166
|
timezone: stdTimeZone,
|
|
165
167
|
label: "End Time",
|
|
166
168
|
value: new _tz.TZDate(timeRange.end, stdTimeZone),
|
|
@@ -24,7 +24,7 @@ const _jsxruntime = require("react/jsx-runtime");
|
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
25
|
const _Calendar = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Calendar"));
|
|
26
26
|
const _Earth = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Earth"));
|
|
27
|
-
const
|
|
27
|
+
const _spec = require("@perses-dev/spec");
|
|
28
28
|
const _react = require("react");
|
|
29
29
|
const _context = require("../context");
|
|
30
30
|
const _timeZoneOption = require("../model/timeZoneOption");
|
|
@@ -42,11 +42,11 @@ function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTim
|
|
|
42
42
|
const anchorEl = (0, _react.useRef)();
|
|
43
43
|
const [showCustomDateSelector, setShowCustomDateSelector] = (0, _react.useState)(false);
|
|
44
44
|
const convertedTimeRange = (0, _react.useMemo)(()=>{
|
|
45
|
-
return (0,
|
|
45
|
+
return (0, _spec.isRelativeTimeRange)(value) ? (0, _spec.toAbsoluteTimeRange)(value) : value;
|
|
46
46
|
}, [
|
|
47
47
|
value
|
|
48
48
|
]);
|
|
49
|
-
const lastOption = (0, _react.useMemo)(()=>(0, _utils.buildCustomTimeOption)((0,
|
|
49
|
+
const lastOption = (0, _react.useMemo)(()=>(0, _utils.buildCustomTimeOption)((0, _spec.isRelativeTimeRange)(value) ? undefined : value, timeZone), [
|
|
50
50
|
value,
|
|
51
51
|
timeZone
|
|
52
52
|
]);
|
|
@@ -38,7 +38,7 @@ _export(exports, {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
const _datefns = require("date-fns");
|
|
41
|
-
const
|
|
41
|
+
const _spec = require("@perses-dev/spec");
|
|
42
42
|
const _utils = require("../utils");
|
|
43
43
|
const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
|
44
44
|
function buildCustomTimeOption(value, timeZone) {
|
|
@@ -68,5 +68,5 @@ function formatTimeRange(value, timeZone) {
|
|
|
68
68
|
if (!value) {
|
|
69
69
|
return 'Custom Time Range';
|
|
70
70
|
}
|
|
71
|
-
return !(0,
|
|
71
|
+
return !(0, _spec.isRelativeTimeRange)(value) ? formatAbsoluteRange(value, DATE_TIME_FORMAT, timeZone) : value.pastDuration;
|
|
72
72
|
}
|
|
@@ -46,7 +46,6 @@ _export(exports, {
|
|
|
46
46
|
return legacyCheckforNearbySeries;
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
const _core = require("@perses-dev/core");
|
|
50
49
|
const _model = require("../model");
|
|
51
50
|
const _utils = require("../utils");
|
|
52
51
|
const _tooltipmodel = require("./tooltip-model");
|
|
@@ -197,7 +196,7 @@ cursorPixelY) {
|
|
|
197
196
|
seriesIndex: seriesIdx
|
|
198
197
|
});
|
|
199
198
|
}
|
|
200
|
-
const formattedY = (0,
|
|
199
|
+
const formattedY = (0, _model.formatValue)(yValue, seriesFormat);
|
|
201
200
|
currentNearbySeriesData.push({
|
|
202
201
|
seriesIdx: seriesIdx,
|
|
203
202
|
datumIdx: datumIdx,
|
|
@@ -266,7 +265,7 @@ function legacyCheckforNearbySeries(data, pointInGrid, yBuffer, chart, format) {
|
|
|
266
265
|
}
|
|
267
266
|
// determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
|
|
268
267
|
const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
|
|
269
|
-
const formattedY = (0,
|
|
268
|
+
const formattedY = (0, _model.formatValue)(yValue, format);
|
|
270
269
|
currentNearbySeriesData.push({
|
|
271
270
|
seriesIdx: seriesIdx,
|
|
272
271
|
datumIdx: datumIdx,
|
|
@@ -27,7 +27,7 @@ const _ChevronDown = /*#__PURE__*/ _interop_require_default(require("mdi-materia
|
|
|
27
27
|
const _EyeOffOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/EyeOffOutline"));
|
|
28
28
|
const _EyeOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/EyeOutline"));
|
|
29
29
|
const _DeleteOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/DeleteOutline"));
|
|
30
|
-
const
|
|
30
|
+
const _model = require("../model");
|
|
31
31
|
const _TransformEditor = require("./TransformEditor");
|
|
32
32
|
function _interop_require_default(obj) {
|
|
33
33
|
return obj && obj.__esModule ? obj : {
|
|
@@ -73,7 +73,7 @@ function TransformEditorContainer({ index, value, isCollapsed, onChange, onColla
|
|
|
73
73
|
},
|
|
74
74
|
children: value.kind ? /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
75
75
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
76
|
-
children:
|
|
76
|
+
children: _model.TRANSFORM_TEXT[value.kind]
|
|
77
77
|
})
|
|
78
78
|
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)("strong", {
|
|
79
79
|
children: "Select a transformation kind"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get getSubmitText () {
|
|
25
|
+
return getSubmitText;
|
|
26
|
+
},
|
|
27
|
+
get getTitleAction () {
|
|
28
|
+
return getTitleAction;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
function getTitleAction(action, isDraft) {
|
|
32
|
+
if (action === 'read') return 'View';
|
|
33
|
+
if (isDraft && action === 'create') return 'Add';
|
|
34
|
+
if (!isDraft && action === 'create') return 'Create';
|
|
35
|
+
if (action === 'update') return 'Edit';
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
function getSubmitText(action, isDraft) {
|
|
39
|
+
if (isDraft && action === 'create') return 'Add';
|
|
40
|
+
if (isDraft && action === 'update') return 'Apply';
|
|
41
|
+
if (!isDraft) return 'Save';
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get BITS_GROUP_CONFIG () {
|
|
25
|
+
return BITS_GROUP_CONFIG;
|
|
26
|
+
},
|
|
27
|
+
get BITS_UNIT_CONFIG () {
|
|
28
|
+
return BITS_UNIT_CONFIG;
|
|
29
|
+
},
|
|
30
|
+
get formatBits () {
|
|
31
|
+
return formatBits;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
|
|
35
|
+
const _constants = require("./constants");
|
|
36
|
+
const _utils = require("./utils");
|
|
37
|
+
const _formatterCache = require("./formatterCache");
|
|
38
|
+
function _interop_require_default(obj) {
|
|
39
|
+
return obj && obj.__esModule ? obj : {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* We support both SI (decimal) and IEC (binary) units for bits:
|
|
45
|
+
*
|
|
46
|
+
* SI/decimal (unit: 'decbits'):
|
|
47
|
+
* 1 Kb = 1000 bits (1000^1 bits)
|
|
48
|
+
* 1 Mb = 1,000,000 bits (1000^2 bits)
|
|
49
|
+
* etc.
|
|
50
|
+
*
|
|
51
|
+
* IEC/binary (unit: 'bits'):
|
|
52
|
+
* 1 Kib = 1024 bits (1024^1 bits)
|
|
53
|
+
* 1 Mib = 1,048,576 bits (1024^2 bits)
|
|
54
|
+
* etc.
|
|
55
|
+
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
56
|
+
const BITS_GROUP_CONFIG = {
|
|
57
|
+
label: 'Bits',
|
|
58
|
+
decimalPlaces: true,
|
|
59
|
+
shortValues: true
|
|
60
|
+
};
|
|
61
|
+
const BITS_UNIT_CONFIG = {
|
|
62
|
+
bits: {
|
|
63
|
+
group: 'Bits',
|
|
64
|
+
label: 'Bits (IEC)'
|
|
65
|
+
},
|
|
66
|
+
decbits: {
|
|
67
|
+
group: 'Bits',
|
|
68
|
+
label: 'Bits (SI)'
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces }) {
|
|
72
|
+
const isDecimal = unit === 'decbits';
|
|
73
|
+
const threshold = isDecimal ? 1000 : 1024;
|
|
74
|
+
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
75
|
+
if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bits) < threshold) {
|
|
76
|
+
const formatterOptions = {
|
|
77
|
+
style: 'decimal',
|
|
78
|
+
useGrouping: true
|
|
79
|
+
};
|
|
80
|
+
if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
|
|
81
|
+
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
82
|
+
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
83
|
+
} else {
|
|
84
|
+
// This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)
|
|
85
|
+
if ((0, _utils.shouldShortenValues)(shortValues)) {
|
|
86
|
+
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const key = [
|
|
90
|
+
formatterOptions.style,
|
|
91
|
+
formatterOptions.useGrouping,
|
|
92
|
+
formatterOptions.maximumSignificantDigits,
|
|
93
|
+
decimalPlaces,
|
|
94
|
+
shortValues,
|
|
95
|
+
unit
|
|
96
|
+
];
|
|
97
|
+
return `${(0, _formatterCache.getFormatterFromCache)(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
|
|
98
|
+
}
|
|
99
|
+
// If we're showing the shorten value, we use numbro.
|
|
100
|
+
// numbro is able to add units like Kb, Mb, Gb, etc. correctly.
|
|
101
|
+
const formatted = (0, _numbro.default)(bits).format({
|
|
102
|
+
output: 'byte',
|
|
103
|
+
base: isDecimal ? 'decimal' : 'binary',
|
|
104
|
+
spaceSeparated: true,
|
|
105
|
+
mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
106
|
+
// trimMantissa trims trailing 0s
|
|
107
|
+
trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
|
|
108
|
+
// optionalMantissa excludes all the decimal places if they're all zeros
|
|
109
|
+
optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces)
|
|
110
|
+
});
|
|
111
|
+
// Replace byte units with bit units
|
|
112
|
+
return formatted.replace(/KB/g, 'Kb').replace(/MB/g, 'Mb').replace(/GB/g, 'Gb').replace(/TB/g, 'Tb').replace(/PB/g, 'Pb').replace(/EB/g, 'Eb').replace(/KiB/g, 'Kib').replace(/MiB/g, 'Mib').replace(/GiB/g, 'Gib').replace(/TiB/g, 'Tib').replace(/PiB/g, 'Pib').replace(/EiB/g, 'Eib');
|
|
113
|
+
}
|