@orchestrator-ui/orchestrator-ui-components 1.38.2 → 2.0.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.
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-lint.log +5 -2
- package/.turbo/turbo-test.log +12 -12
- package/CHANGELOG.md +18 -0
- package/dist/index.d.ts +246 -170
- package/dist/index.js +4350 -3504
- package/package.json +1 -1
- package/src/components/WfoForms/formFields/SubscriptionSummaryField.tsx +6 -5
- package/src/components/WfoPageTemplate/WfoPageHeader/WfoPageHeader.tsx +3 -1
- package/src/components/WfoPageTemplate/WfoSidebar/WfoCopyright.tsx +1 -1
- package/src/components/WfoProcessList/WfoProcessesList.tsx +52 -51
- package/src/components/WfoRadioDropdown/WfoRadioDropdown.tsx +88 -0
- package/src/components/WfoRadioDropdown/index.ts +1 -0
- package/src/components/WfoSubscription/WfoInSyncField.tsx +13 -9
- package/src/components/WfoSubscription/WfoInUseByRelations.tsx +4 -2
- package/src/components/WfoSubscription/WfoProcessesTimeline.tsx +76 -29
- package/src/components/WfoSubscription/WfoRelatedSubscriptions.tsx +50 -56
- package/src/components/WfoSubscription/WfoSubscriptionDetailTree.tsx +17 -9
- package/src/components/WfoSubscription/WfoSubscriptionGeneral.tsx +18 -156
- package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionDetailSection.tsx +113 -0
- package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionFixedInputSection.tsx +28 -0
- package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionMetadataSection.tsx +29 -0
- package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionProductInfoSection.tsx +55 -0
- package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/index.ts +4 -0
- package/src/components/WfoSubscription/index.ts +3 -0
- package/src/components/WfoSubscription/overrides/index.ts +1 -0
- package/src/components/WfoSubscription/styles.ts +4 -1
- package/src/components/WfoSubscription/utils/utils.spec.ts +0 -13
- package/src/components/WfoSubscription/utils/utils.ts +18 -5
- package/src/components/WfoSubscriptionsList/WfoSubscriptionsList.tsx +105 -100
- package/src/components/WfoTable/{WfoTableWithFilter/WfoTableWithFilter.tsx → WfoAdvancedTable/WfoAdvancedTable.tsx} +65 -123
- package/src/components/WfoTable/WfoAdvancedTable/getRowDetailData.tsx +55 -0
- package/src/components/WfoTable/WfoAdvancedTable/index.ts +4 -0
- package/src/components/WfoTable/WfoAdvancedTable/toSortedTableColumnConfig.ts +12 -0
- package/src/components/WfoTable/WfoAdvancedTable/types.ts +23 -0
- package/src/components/WfoTable/WfoStatusColorField/WfoStatusColorField.tsx +16 -0
- package/src/components/WfoTable/WfoStatusColorField/index.ts +1 -0
- package/src/components/WfoTable/WfoStatusColorField/styles.ts +20 -0
- package/src/components/WfoTable/WfoTable/WfoExpandedRow.tsx +33 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoExpandableRow.tsx +48 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoExpandedGroupRow.tsx +71 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoGroupedTable.tsx +100 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoGroupedTableGroups.tsx +74 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/styles.ts +39 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/useGroupedTableConfig.tsx +184 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/utils.spec.ts +133 -0
- package/src/components/WfoTable/WfoTable/WfoGroupedTable/utils.ts +41 -0
- package/src/components/WfoTable/WfoTable/WfoMultilineCell.tsx +13 -0
- package/src/components/WfoTable/WfoTable/WfoTable.tsx +201 -0
- package/src/components/WfoTable/WfoTable/WfoTableDataRows.tsx +112 -0
- package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/WfoSortDirectionIcon.tsx +3 -3
- package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/WfoTableHeaderCell.tsx +4 -3
- package/src/components/WfoTable/WfoTable/WfoTableHeaderCell/index.ts +2 -0
- package/src/components/WfoTable/WfoTable/WfoTableHeaderRow.tsx +114 -0
- package/src/components/WfoTable/WfoTable/WfoTruncateCell.tsx +23 -0
- package/src/components/WfoTable/WfoTable/constants.ts +1 -0
- package/src/components/WfoTable/WfoTable/index.ts +14 -0
- package/src/components/WfoTable/WfoTable/styles.ts +117 -0
- package/src/components/WfoTable/WfoTable/utils.spec.ts +79 -0
- package/src/components/WfoTable/WfoTable/utils.ts +78 -0
- package/src/components/WfoTable/WfoTableSettingsModal/WfoTableSettingsModal.tsx +13 -12
- package/src/components/WfoTable/WfoTableWithFilter/index.ts +1 -1
- package/src/components/WfoTable/index.ts +4 -5
- package/src/components/WfoTable/utils/columns.ts +1 -48
- package/src/components/WfoTable/utils/tableUtils.ts +13 -10
- package/src/components/WfoTree/WfoTreeBranch.tsx +10 -1
- package/src/components/WfoTree/WfoTreeNode.tsx +8 -57
- package/src/components/WfoTree/WfoTreeNodeListItem.tsx +65 -0
- package/src/components/WfoTree/styles.ts +28 -4
- package/src/components/index.ts +1 -0
- package/src/configuration/policy-resources.ts +1 -0
- package/src/configuration/version.ts +1 -1
- package/src/icons/WfoXMarkSmall.tsx +29 -0
- package/src/messages/en-GB.json +4 -0
- package/src/messages/nl-NL.json +4 -0
- package/src/pages/metadata/WfoProductBlocksPage.tsx +42 -59
- package/src/pages/metadata/WfoProductsPage.tsx +41 -47
- package/src/pages/metadata/WfoResourceTypesPage.tsx +26 -35
- package/src/pages/metadata/WfoTasksPage.tsx +35 -33
- package/src/pages/metadata/WfoWorkflowsPage.tsx +33 -29
- package/src/pages/tasks/WfoTasksListPage.tsx +25 -19
- package/src/utils/getObjectKeys.ts +3 -0
- package/src/utils/index.ts +5 -3
- package/src/components/WfoTable/WfoBasicTable/WfoBasicTable.tsx +0 -194
- package/src/components/WfoTable/WfoBasicTable/WfoStatusColorField.tsx +0 -21
- package/src/components/WfoTable/WfoBasicTable/index.ts +0 -5
- package/src/components/WfoTable/WfoDataGridTable/WfoDataGridTable.stories.tsx +0 -136
- package/src/components/WfoTable/WfoDataGridTable/WfoDataGridTable.tsx +0 -146
- package/src/components/WfoTable/WfoDataGridTable/WfodataGridColumns.spec.ts +0 -113
- package/src/components/WfoTable/WfoDataGridTable/WfodataGridColumns.ts +0 -81
- package/src/components/WfoTable/utils/mapSortableAndFilterableValuesToTableColumnConfig.spec.ts +0 -52
- package/src/components/WfoTable/utils/mapSortableAndFilterableValuesToTableColumnConfig.ts +0 -23
- /package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/styles.ts +0 -0
package/src/utils/index.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export * from './csvDownload';
|
|
2
2
|
export * from './date';
|
|
3
3
|
export * from './environmentVariables';
|
|
4
|
+
export * from './filterData';
|
|
5
|
+
export * from './getDefaultTableConfig';
|
|
4
6
|
export * from './getEnvironmentVariables';
|
|
7
|
+
export * from './getObjectKeys';
|
|
5
8
|
export * from './getProductNamesFromProcess';
|
|
6
9
|
export * from './getQueryVariablesForExport';
|
|
7
10
|
export * from './getStatusBadgeColor';
|
|
8
11
|
export * from './getTypedFieldFromObject';
|
|
9
12
|
export * from './onlyUnique';
|
|
10
|
-
export * from './
|
|
13
|
+
export * from './optionalArray';
|
|
11
14
|
export * from './resultFlattener';
|
|
12
15
|
export * from './strings';
|
|
13
|
-
export * from './optionalArray';
|
|
14
|
-
export * from './filterData';
|
|
15
16
|
export * from './toObjectWithSortedKeys';
|
|
17
|
+
export * from './uuid';
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useTranslations } from 'next-intl';
|
|
4
|
-
|
|
5
|
-
import { EuiBasicTable, EuiBasicTableColumn, Pagination } from '@elastic/eui';
|
|
6
|
-
import { Criteria } from '@elastic/eui/src/components/basic_table/basic_table';
|
|
7
|
-
import { SerializedStyles } from '@emotion/react';
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
TableColumnKeys,
|
|
11
|
-
WfoDataSearch,
|
|
12
|
-
WfoDataSorting,
|
|
13
|
-
} from '@/components';
|
|
14
|
-
import {
|
|
15
|
-
WFO_STATUS_COLOR_FIELD,
|
|
16
|
-
WfoTableControlColumnConfig,
|
|
17
|
-
WfoTableDataColumnConfig,
|
|
18
|
-
} from '@/components';
|
|
19
|
-
import { WfoStatusColorField } from '@/components';
|
|
20
|
-
import { WfoTableHeaderCell } from '@/components';
|
|
21
|
-
import { useOrchestratorTheme, useWithOrchestratorTheme } from '@/hooks';
|
|
22
|
-
import { SortOrder } from '@/types';
|
|
23
|
-
|
|
24
|
-
import { getWfoBasicTableStyles } from './styles';
|
|
25
|
-
|
|
26
|
-
export type WfoBasicTableColumns<T extends object> = {
|
|
27
|
-
[Property in keyof T]: WfoTableDataColumnConfig<T, Property> & {
|
|
28
|
-
render?: (cellValue: T[Property], row: T) => ReactNode;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type WfoBasicTableColumnsWithControlColumns<T extends object> =
|
|
33
|
-
WfoBasicTableColumns<T> & WfoTableControlColumnConfig<T>;
|
|
34
|
-
|
|
35
|
-
export type WfoBasicTableProps<T extends object> = {
|
|
36
|
-
data: T[];
|
|
37
|
-
columns:
|
|
38
|
-
| WfoBasicTableColumnsWithControlColumns<T>
|
|
39
|
-
| WfoBasicTableColumns<T>;
|
|
40
|
-
hiddenColumns?: TableColumnKeys<T>;
|
|
41
|
-
dataSorting?: WfoDataSorting<T>;
|
|
42
|
-
pagination?: Pagination;
|
|
43
|
-
isLoading?: boolean;
|
|
44
|
-
onCriteriaChange?: (criteria: Criteria<T>) => void;
|
|
45
|
-
onUpdateDataSorting?: (updatedDataSorting: WfoDataSorting<T>) => void;
|
|
46
|
-
onDataSearch?: (updatedDataSearch: WfoDataSearch<T>) => void;
|
|
47
|
-
getStatusColorForRow?: (row: T) => string;
|
|
48
|
-
isExpandable?: boolean;
|
|
49
|
-
itemIdToExpandedRowMap?: Record<string, ReactNode>;
|
|
50
|
-
itemId?: string;
|
|
51
|
-
customTableStyle?: SerializedStyles;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const WfoBasicTable = <T extends object>({
|
|
55
|
-
data,
|
|
56
|
-
columns,
|
|
57
|
-
hiddenColumns,
|
|
58
|
-
dataSorting,
|
|
59
|
-
pagination,
|
|
60
|
-
isLoading,
|
|
61
|
-
onCriteriaChange,
|
|
62
|
-
onUpdateDataSorting,
|
|
63
|
-
onDataSearch,
|
|
64
|
-
getStatusColorForRow,
|
|
65
|
-
isExpandable,
|
|
66
|
-
itemIdToExpandedRowMap,
|
|
67
|
-
itemId,
|
|
68
|
-
customTableStyle,
|
|
69
|
-
}: WfoBasicTableProps<T>) => {
|
|
70
|
-
const { theme } = useOrchestratorTheme();
|
|
71
|
-
const { basicTableStyle } = useWithOrchestratorTheme(
|
|
72
|
-
getWfoBasicTableStyles,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const t = useTranslations('common');
|
|
76
|
-
|
|
77
|
-
const statusColorColumn: WfoTableControlColumnConfig<T> = {
|
|
78
|
-
statusColorField: {
|
|
79
|
-
field: WFO_STATUS_COLOR_FIELD,
|
|
80
|
-
name: '',
|
|
81
|
-
width: theme.size.xs,
|
|
82
|
-
render: (_, row) =>
|
|
83
|
-
getStatusColorForRow ? (
|
|
84
|
-
<WfoStatusColorField color={getStatusColorForRow(row)} />
|
|
85
|
-
) : (
|
|
86
|
-
<></>
|
|
87
|
-
),
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const allTableColumns:
|
|
92
|
-
| WfoBasicTableColumnsWithControlColumns<T>
|
|
93
|
-
| WfoBasicTableColumns<T> = getStatusColorForRow
|
|
94
|
-
? { ...statusColorColumn, ...columns }
|
|
95
|
-
: { ...columns };
|
|
96
|
-
|
|
97
|
-
const tableStyling = customTableStyle ?? basicTableStyle;
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<EuiBasicTable
|
|
101
|
-
css={tableStyling}
|
|
102
|
-
items={data}
|
|
103
|
-
noItemsMessage={isLoading ? t('loading') : t('noItemsFound')}
|
|
104
|
-
columns={mapWfoTableColumnsToEuiColumns(
|
|
105
|
-
allTableColumns,
|
|
106
|
-
hiddenColumns,
|
|
107
|
-
dataSorting,
|
|
108
|
-
onUpdateDataSorting,
|
|
109
|
-
onDataSearch,
|
|
110
|
-
)}
|
|
111
|
-
pagination={pagination}
|
|
112
|
-
onChange={onCriteriaChange}
|
|
113
|
-
loading={isLoading}
|
|
114
|
-
{...(isExpandable && {
|
|
115
|
-
isExpandable,
|
|
116
|
-
itemIdToExpandedRowMap,
|
|
117
|
-
itemId,
|
|
118
|
-
})}
|
|
119
|
-
/>
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
function mapWfoTableColumnsToEuiColumns<T extends object>(
|
|
124
|
-
tableColumns: WfoBasicTableColumns<T>,
|
|
125
|
-
hiddenColumns?: TableColumnKeys<T>,
|
|
126
|
-
dataSorting?: WfoDataSorting<T>,
|
|
127
|
-
onDataSort?: (updatedDataSorting: WfoDataSorting<T>) => void,
|
|
128
|
-
onDataSearch?: (updatedDataSearch: WfoDataSearch<T>) => void,
|
|
129
|
-
): EuiBasicTableColumn<T>[] {
|
|
130
|
-
function isVisibleColumn(columnKey: string) {
|
|
131
|
-
return !hiddenColumns?.includes(columnKey as keyof T);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function mapColumnKeyToEuiColumn(colKey: string): EuiBasicTableColumn<T> {
|
|
135
|
-
const typedColumnKey = colKey as keyof T;
|
|
136
|
-
const column: WfoBasicTableColumns<T>[keyof T] =
|
|
137
|
-
tableColumns[typedColumnKey];
|
|
138
|
-
const {
|
|
139
|
-
name,
|
|
140
|
-
render,
|
|
141
|
-
width,
|
|
142
|
-
description,
|
|
143
|
-
sortable,
|
|
144
|
-
filterable,
|
|
145
|
-
truncateText,
|
|
146
|
-
} = column;
|
|
147
|
-
|
|
148
|
-
// In most cases columns are sortable and filterable, making them optional saves some lines in configuring the table
|
|
149
|
-
const isSortable = sortable ?? true;
|
|
150
|
-
const isFilterable = filterable ?? true;
|
|
151
|
-
|
|
152
|
-
const sortOrder =
|
|
153
|
-
dataSorting?.field === colKey ? dataSorting.sortOrder : undefined;
|
|
154
|
-
|
|
155
|
-
const handleOnSetSortOrder = (updatedSortOrder: SortOrder) =>
|
|
156
|
-
onDataSort?.({
|
|
157
|
-
field: typedColumnKey,
|
|
158
|
-
sortOrder: updatedSortOrder,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const handleOnSearch = (searchText: string) =>
|
|
162
|
-
onDataSearch?.({
|
|
163
|
-
field: typedColumnKey,
|
|
164
|
-
searchText,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Not spreading the column object here as it might contain additional props.
|
|
168
|
-
// EUI does not handle extra props well.
|
|
169
|
-
return {
|
|
170
|
-
render,
|
|
171
|
-
width,
|
|
172
|
-
description,
|
|
173
|
-
field: typedColumnKey,
|
|
174
|
-
name: name && (
|
|
175
|
-
<WfoTableHeaderCell
|
|
176
|
-
fieldName={typedColumnKey.toString()}
|
|
177
|
-
sortOrder={sortOrder}
|
|
178
|
-
onSetSortOrder={
|
|
179
|
-
isSortable ? handleOnSetSortOrder : undefined
|
|
180
|
-
}
|
|
181
|
-
onSearch={isFilterable ? handleOnSearch : undefined}
|
|
182
|
-
>
|
|
183
|
-
{name}
|
|
184
|
-
</WfoTableHeaderCell>
|
|
185
|
-
),
|
|
186
|
-
truncateText: truncateText ?? true,
|
|
187
|
-
textOnly: true,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return Object.keys(tableColumns)
|
|
192
|
-
.filter(isVisibleColumn)
|
|
193
|
-
.map(mapColumnKeyToEuiColumn);
|
|
194
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { EuiFlexItem, tint } from '@elastic/eui';
|
|
4
|
-
|
|
5
|
-
export type WfoStatusColorFieldProps = {
|
|
6
|
-
color: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const toStatusColorFieldColor = (color: string) => tint(color, 0.3);
|
|
10
|
-
|
|
11
|
-
export const WfoStatusColorField = ({ color }: WfoStatusColorFieldProps) => {
|
|
12
|
-
return (
|
|
13
|
-
<EuiFlexItem
|
|
14
|
-
css={{
|
|
15
|
-
backgroundColor: toStatusColorFieldColor(color),
|
|
16
|
-
height: '100%',
|
|
17
|
-
width: '100%',
|
|
18
|
-
}}
|
|
19
|
-
></EuiFlexItem>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { Meta } from '@storybook/react';
|
|
4
|
-
|
|
5
|
-
import { SortOrder } from '../../../types';
|
|
6
|
-
import { WfoDataSorting } from '../utils/columns';
|
|
7
|
-
import { WfoDataGridTable } from './WfoDataGridTable';
|
|
8
|
-
|
|
9
|
-
const extractedArr = (arr, start, howMany) =>
|
|
10
|
-
arr.filter((_, index) => index >= start && index < howMany + start);
|
|
11
|
-
|
|
12
|
-
const TableWithEvents = (args) => {
|
|
13
|
-
const [data, setData] = useState(
|
|
14
|
-
extractedArr(
|
|
15
|
-
args.data,
|
|
16
|
-
args.pagination.pageIndex,
|
|
17
|
-
args.pagination.pageSize,
|
|
18
|
-
),
|
|
19
|
-
);
|
|
20
|
-
const [pageSize, setPageSize] = useState(args.pagination.pageSize);
|
|
21
|
-
const [pageIndex, setPageIndex] = useState(args.pagination.pageIndex);
|
|
22
|
-
const [sorting, setSorting] = useState(args.sorting);
|
|
23
|
-
|
|
24
|
-
const onChangePage = (updatedPageIndex: number) => {
|
|
25
|
-
const pageI = updatedPageIndex * pageSize;
|
|
26
|
-
setData(extractedArr(args.data, pageI, pageI + pageSize));
|
|
27
|
-
setPageIndex(updatedPageIndex);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const onChangeItemsPerPage = (updatedPageSize: number) => {
|
|
31
|
-
setData(
|
|
32
|
-
extractedArr(args.data, pageIndex, pageIndex + updatedPageSize),
|
|
33
|
-
);
|
|
34
|
-
setPageSize(updatedPageSize);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const updateDataSorting = (dataSorting: WfoDataSorting<unknown>) => {
|
|
38
|
-
setSorting(dataSorting);
|
|
39
|
-
|
|
40
|
-
const sortData = args.data.sort((a, b) => {
|
|
41
|
-
const aColumn = a[dataSorting.columnId];
|
|
42
|
-
const bColumn = b[dataSorting.columnId];
|
|
43
|
-
if (dataSorting.sortDirection === SortOrder.Asc) {
|
|
44
|
-
return aColumn > bColumn ? 1 : bColumn > aColumn ? -1 : 0;
|
|
45
|
-
}
|
|
46
|
-
return bColumn > aColumn ? 1 : aColumn > bColumn ? -1 : 0;
|
|
47
|
-
});
|
|
48
|
-
setData(extractedArr(sortData, pageIndex, pageIndex + pageSize));
|
|
49
|
-
};
|
|
50
|
-
return (
|
|
51
|
-
<WfoDataGridTable
|
|
52
|
-
{...args}
|
|
53
|
-
data={data}
|
|
54
|
-
pagination={{
|
|
55
|
-
...args.pagination,
|
|
56
|
-
pageIndex,
|
|
57
|
-
pageSize,
|
|
58
|
-
onChangeItemsPerPage,
|
|
59
|
-
onChangePage,
|
|
60
|
-
}}
|
|
61
|
-
dataSorting={sorting}
|
|
62
|
-
updateDataSorting={updateDataSorting}
|
|
63
|
-
/>
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const Story: Meta<typeof WfoDataGridTable> = {
|
|
68
|
-
component: TableWithEvents,
|
|
69
|
-
title: 'Tables/WfoDataGridTable',
|
|
70
|
-
parameters: { actions: { argTypesRegex: '^on*' } },
|
|
71
|
-
};
|
|
72
|
-
export default Story;
|
|
73
|
-
|
|
74
|
-
const columns = {
|
|
75
|
-
id: {
|
|
76
|
-
displayAsText: 'id',
|
|
77
|
-
initialWidth: 100,
|
|
78
|
-
},
|
|
79
|
-
title: {
|
|
80
|
-
displayAsText: 'title',
|
|
81
|
-
initialWidth: 200,
|
|
82
|
-
},
|
|
83
|
-
date: {
|
|
84
|
-
displayAsText: 'date',
|
|
85
|
-
initialWidth: 200,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const initialColumnOrder = ['id', 'title', 'date'];
|
|
90
|
-
|
|
91
|
-
const date = new Date('2023-01-01');
|
|
92
|
-
const data = [
|
|
93
|
-
{ id: 1, title: 'test 1', date: date.toISOString().split('T')[0] },
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
for (let i = 2; i <= 110; i++) {
|
|
97
|
-
date.setDate(date.getDate() + 1);
|
|
98
|
-
data.push({
|
|
99
|
-
id: i,
|
|
100
|
-
title: `test ${i}`,
|
|
101
|
-
date: date.toISOString().split('T')[0],
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const pagination = {
|
|
106
|
-
pageSize: 10,
|
|
107
|
-
pageIndex: 0,
|
|
108
|
-
pageSizeOptions: [5, 10, 15, 20, 25, 100],
|
|
109
|
-
totalRecords: data.length,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const Primary = {
|
|
113
|
-
args: {
|
|
114
|
-
data,
|
|
115
|
-
columns,
|
|
116
|
-
initialColumnOrder,
|
|
117
|
-
pagination,
|
|
118
|
-
sorting: {
|
|
119
|
-
columnId: 'id',
|
|
120
|
-
sortDirection: 'ASC',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const Secondary = {
|
|
126
|
-
args: {
|
|
127
|
-
data,
|
|
128
|
-
columns,
|
|
129
|
-
initialColumnOrder,
|
|
130
|
-
pagination,
|
|
131
|
-
sorting: {
|
|
132
|
-
columnId: 'id',
|
|
133
|
-
sortDirection: 'ASC',
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
EuiDataGrid,
|
|
6
|
-
EuiDataGridCellValueElementProps,
|
|
7
|
-
EuiDataGridStyle,
|
|
8
|
-
} from '@elastic/eui';
|
|
9
|
-
import {
|
|
10
|
-
EuiDataGridControlColumn,
|
|
11
|
-
EuiDataGridPaginationProps,
|
|
12
|
-
} from '@elastic/eui/src/components/datagrid/data_grid_types';
|
|
13
|
-
|
|
14
|
-
import { TableColumnKeys, WfoDataSorting } from '../utils/columns';
|
|
15
|
-
import { DEFAULT_PAGE_SIZE } from '../utils/constants';
|
|
16
|
-
import {
|
|
17
|
-
WfoControlColumn,
|
|
18
|
-
WfoDataGridTableColumns,
|
|
19
|
-
getInitialColumnOrder,
|
|
20
|
-
mapColumnSortToEuiDataGridSorting,
|
|
21
|
-
} from './WfodataGridColumns';
|
|
22
|
-
|
|
23
|
-
// Total height of grid button bar, table header and pagination bar
|
|
24
|
-
const EUI_DATA_GRID_HEIGHT_OFFSET = 103;
|
|
25
|
-
const EUI_DATA_GRID_ROW_HEIGHT = 40;
|
|
26
|
-
|
|
27
|
-
const GRID_STYLE: EuiDataGridStyle = {
|
|
28
|
-
border: 'horizontal',
|
|
29
|
-
stripes: false,
|
|
30
|
-
rowHover: 'highlight',
|
|
31
|
-
header: 'shade',
|
|
32
|
-
cellPadding: 'l',
|
|
33
|
-
fontSize: 'm',
|
|
34
|
-
footer: 'overline',
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type Pagination = EuiDataGridPaginationProps & {
|
|
38
|
-
totalRecords: number;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type WfoDataGridTableProps<T> = {
|
|
42
|
-
data: T[];
|
|
43
|
-
pagination: Pagination;
|
|
44
|
-
columns: WfoDataGridTableColumns<T>;
|
|
45
|
-
leadingControlColumns?: WfoControlColumn<T>[];
|
|
46
|
-
trailingControlColumns?: WfoControlColumn<T>[];
|
|
47
|
-
initialColumnOrder: TableColumnKeys<T>;
|
|
48
|
-
dataSorting?: WfoDataSorting<T>;
|
|
49
|
-
handleRowClick?: (row: T) => void;
|
|
50
|
-
updateDataSorting?: (updatedDataSorting: WfoDataSorting<T>) => void;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const WfoDataGridTable = <T,>({
|
|
54
|
-
data,
|
|
55
|
-
pagination,
|
|
56
|
-
columns,
|
|
57
|
-
leadingControlColumns,
|
|
58
|
-
trailingControlColumns,
|
|
59
|
-
initialColumnOrder,
|
|
60
|
-
dataSorting,
|
|
61
|
-
handleRowClick,
|
|
62
|
-
updateDataSorting,
|
|
63
|
-
}: WfoDataGridTableProps<T>) => {
|
|
64
|
-
const initialColumnOrderRef = useRef(
|
|
65
|
-
getInitialColumnOrder(columns, initialColumnOrder),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const defaultVisibleColumns: string[] = initialColumnOrder
|
|
69
|
-
.filter((columnId) => !columns[columnId].isHiddenByDefault)
|
|
70
|
-
.map((columnId) => columnId.toString());
|
|
71
|
-
const [visibleColumns, setVisibleColumns] = useState(defaultVisibleColumns);
|
|
72
|
-
const pageSize = pagination.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
73
|
-
const { pageIndex } = pagination;
|
|
74
|
-
|
|
75
|
-
const renderCellValue = ({
|
|
76
|
-
rowIndex,
|
|
77
|
-
columnId,
|
|
78
|
-
setCellProps,
|
|
79
|
-
}: EuiDataGridCellValueElementProps) => {
|
|
80
|
-
const rowIndexOnPage = rowIndex - pageIndex * pageSize;
|
|
81
|
-
|
|
82
|
-
const dataRow = data[rowIndexOnPage];
|
|
83
|
-
if (!dataRow) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const column = columns[columnId as keyof T];
|
|
88
|
-
const cellValue = dataRow[columnId as keyof T];
|
|
89
|
-
|
|
90
|
-
if (handleRowClick) {
|
|
91
|
-
setCellProps({
|
|
92
|
-
css: { cursor: 'pointer' },
|
|
93
|
-
onClick: () => handleRowClick(dataRow),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return column.renderCell
|
|
98
|
-
? column.renderCell(cellValue, dataRow)
|
|
99
|
-
: `${cellValue}`;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const mapControlColumnToEuiDataGridControlColumn: (
|
|
103
|
-
controlColumn: WfoControlColumn<T>,
|
|
104
|
-
) => EuiDataGridControlColumn = ({ id, width, rowCellRender }) => ({
|
|
105
|
-
id,
|
|
106
|
-
width,
|
|
107
|
-
headerCellRender: () => null,
|
|
108
|
-
rowCellRender: ({ rowIndex }: { rowIndex: number }) => {
|
|
109
|
-
const rowIndexOnPage = rowIndex - pageIndex * pageSize;
|
|
110
|
-
|
|
111
|
-
const dataRow = data[rowIndexOnPage];
|
|
112
|
-
|
|
113
|
-
return rowCellRender(dataRow);
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const euiDataGridLeadingControlColumns = leadingControlColumns?.map(
|
|
118
|
-
mapControlColumnToEuiDataGridControlColumn,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const euiDataGridTrailingControlColumns = trailingControlColumns?.map(
|
|
122
|
-
mapControlColumnToEuiDataGridControlColumn,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const gridHeightValue =
|
|
126
|
-
pageSize * EUI_DATA_GRID_ROW_HEIGHT + EUI_DATA_GRID_HEIGHT_OFFSET;
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<EuiDataGrid
|
|
130
|
-
aria-label="Data Grid"
|
|
131
|
-
columns={initialColumnOrderRef.current}
|
|
132
|
-
leadingControlColumns={euiDataGridLeadingControlColumns}
|
|
133
|
-
trailingControlColumns={euiDataGridTrailingControlColumns}
|
|
134
|
-
height={`${gridHeightValue}px`}
|
|
135
|
-
gridStyle={GRID_STYLE}
|
|
136
|
-
columnVisibility={{ visibleColumns, setVisibleColumns }}
|
|
137
|
-
pagination={pagination}
|
|
138
|
-
sorting={mapColumnSortToEuiDataGridSorting(
|
|
139
|
-
dataSorting,
|
|
140
|
-
updateDataSorting,
|
|
141
|
-
)}
|
|
142
|
-
rowCount={pagination.totalRecords}
|
|
143
|
-
renderCellValue={renderCellValue}
|
|
144
|
-
/>
|
|
145
|
-
);
|
|
146
|
-
};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { SortOrder } from '../../../types';
|
|
2
|
-
import { WfoDataSorting } from '../utils/columns';
|
|
3
|
-
import {
|
|
4
|
-
WfoDataGridTableColumns,
|
|
5
|
-
getInitialColumnOrder,
|
|
6
|
-
mapColumnSortToEuiDataGridSorting,
|
|
7
|
-
} from './WfodataGridColumns';
|
|
8
|
-
|
|
9
|
-
interface TestColumn {
|
|
10
|
-
id: string;
|
|
11
|
-
title: string;
|
|
12
|
-
date: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const columns: WfoDataGridTableColumns<TestColumn> = {
|
|
16
|
-
id: {
|
|
17
|
-
displayAsText: 'id',
|
|
18
|
-
initialWidth: 100,
|
|
19
|
-
},
|
|
20
|
-
title: {
|
|
21
|
-
displayAsText: 'title',
|
|
22
|
-
initialWidth: 200,
|
|
23
|
-
},
|
|
24
|
-
date: {
|
|
25
|
-
displayAsText: 'date',
|
|
26
|
-
initialWidth: 200,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
describe('dataGridColumns', () => {
|
|
31
|
-
describe('getInitialColumnOrder', () => {
|
|
32
|
-
it('returns columns sorted by initialColumnOrder (id, title, date)', () => {
|
|
33
|
-
const initialColumnOrder: Array<keyof TestColumn> = [
|
|
34
|
-
'id',
|
|
35
|
-
'title',
|
|
36
|
-
'date',
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
const result = getInitialColumnOrder(columns, initialColumnOrder);
|
|
40
|
-
|
|
41
|
-
expect(result).toEqual([
|
|
42
|
-
{
|
|
43
|
-
displayAsText: 'id',
|
|
44
|
-
id: 'id',
|
|
45
|
-
initialWidth: 100,
|
|
46
|
-
isExpandable: false,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
displayAsText: 'title',
|
|
50
|
-
id: 'title',
|
|
51
|
-
initialWidth: 200,
|
|
52
|
-
isExpandable: false,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
displayAsText: 'date',
|
|
56
|
-
id: 'date',
|
|
57
|
-
initialWidth: 200,
|
|
58
|
-
isExpandable: false,
|
|
59
|
-
},
|
|
60
|
-
]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should return columns sorted by (date, id, title)', () => {
|
|
64
|
-
const initialColumnOrder: Array<keyof TestColumn> = [
|
|
65
|
-
'date',
|
|
66
|
-
'id',
|
|
67
|
-
'title',
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const result = getInitialColumnOrder(columns, initialColumnOrder);
|
|
71
|
-
|
|
72
|
-
expect(result).toEqual([
|
|
73
|
-
{
|
|
74
|
-
displayAsText: 'date',
|
|
75
|
-
id: 'date',
|
|
76
|
-
initialWidth: 200,
|
|
77
|
-
isExpandable: false,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
displayAsText: 'id',
|
|
81
|
-
id: 'id',
|
|
82
|
-
initialWidth: 100,
|
|
83
|
-
isExpandable: false,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
displayAsText: 'title',
|
|
87
|
-
id: 'title',
|
|
88
|
-
initialWidth: 200,
|
|
89
|
-
isExpandable: false,
|
|
90
|
-
},
|
|
91
|
-
]);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('columnSortToEuiDataGridSorting', () => {
|
|
96
|
-
it('should return sort dict with columns and onsort', () => {
|
|
97
|
-
const sortBy: WfoDataSorting<TestColumn> = {
|
|
98
|
-
field: 'id',
|
|
99
|
-
sortOrder: SortOrder.ASC,
|
|
100
|
-
};
|
|
101
|
-
const onSort = (dataSorting: WfoDataSorting<TestColumn>) => {
|
|
102
|
-
sortBy.field = dataSorting.field;
|
|
103
|
-
sortBy.sortOrder = dataSorting.sortOrder;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const sorting = mapColumnSortToEuiDataGridSorting(sortBy, onSort);
|
|
107
|
-
expect(sorting.columns).toEqual([{ id: 'id', direction: 'asc' }]);
|
|
108
|
-
|
|
109
|
-
sorting.onSort([{ id: 'id', direction: 'desc' }]);
|
|
110
|
-
expect(sortBy).toEqual({ field: 'id', sortOrder: 'DESC' });
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|