@orchestrator-ui/orchestrator-ui-components 1.38.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.turbo/turbo-build.log +11 -9
  2. package/.turbo/turbo-lint.log +5 -2
  3. package/.turbo/turbo-test.log +14 -14
  4. package/CHANGELOG.md +30 -0
  5. package/dist/index.d.ts +329 -172
  6. package/dist/index.js +6152 -5545
  7. package/dist/index.js.map +1 -0
  8. package/package.json +2 -2
  9. package/src/components/WfoContentHeader/WfoContentHeader.tsx +55 -0
  10. package/src/components/WfoContentHeader/index.ts +1 -0
  11. package/src/components/WfoForms/formFields/SubscriptionSummaryField.tsx +6 -5
  12. package/src/components/WfoInlineNoteEdit/WfoInlineNoteEdit.tsx +105 -0
  13. package/src/components/WfoInlineNoteEdit/index.ts +1 -0
  14. package/src/components/WfoPageTemplate/WfoPageHeader/WfoPageHeader.tsx +3 -1
  15. package/src/components/WfoPageTemplate/WfoSidebar/WfoCopyright.tsx +1 -1
  16. package/src/components/WfoPageTemplate/WfoSidebar/WfoSidebar.tsx +6 -6
  17. package/src/components/WfoProcessList/WfoProcessesList.tsx +52 -51
  18. package/src/components/WfoRadioDropdown/WfoRadioDropdown.tsx +88 -0
  19. package/src/components/WfoRadioDropdown/index.ts +1 -0
  20. package/src/components/WfoRenderElementOrString/WfoRenderElementOrString.tsx +16 -0
  21. package/src/components/WfoRenderElementOrString/index.ts +1 -0
  22. package/src/components/WfoSubscription/WfoInSyncField.tsx +13 -9
  23. package/src/components/WfoSubscription/WfoInUseByRelations.tsx +4 -2
  24. package/src/components/WfoSubscription/WfoProcessesTimeline.tsx +76 -29
  25. package/src/components/WfoSubscription/WfoRelatedSubscriptions.tsx +92 -84
  26. package/src/components/WfoSubscription/WfoSubscription.tsx +19 -37
  27. package/src/components/WfoSubscription/WfoSubscriptionDetailTree.tsx +17 -9
  28. package/src/components/WfoSubscription/WfoSubscriptionGeneral.tsx +18 -156
  29. package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionDetailSection.tsx +119 -0
  30. package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionFixedInputSection.tsx +28 -0
  31. package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionMetadataSection.tsx +29 -0
  32. package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/WfoSubscriptionProductInfoSection.tsx +55 -0
  33. package/src/components/WfoSubscription/WfoSubscriptionGeneralSections/index.ts +4 -0
  34. package/src/components/WfoSubscription/index.ts +3 -0
  35. package/src/components/WfoSubscription/overrides/index.ts +1 -0
  36. package/src/components/WfoSubscription/styles.ts +4 -1
  37. package/src/components/WfoSubscription/utils/relatedSubscriptionsListItemsObjectMappers.ts +62 -0
  38. package/src/components/WfoSubscription/utils/utils.spec.ts +0 -13
  39. package/src/components/WfoSubscription/utils/utils.ts +18 -5
  40. package/src/components/WfoSubscriptionsList/WfoSubscriptionsList.tsx +105 -100
  41. package/src/components/WfoTable/{WfoTableWithFilter/WfoTableWithFilter.tsx → WfoAdvancedTable/WfoAdvancedTable.tsx} +65 -123
  42. package/src/components/WfoTable/WfoAdvancedTable/getRowDetailData.tsx +55 -0
  43. package/src/components/WfoTable/WfoAdvancedTable/index.ts +4 -0
  44. package/src/components/WfoTable/WfoAdvancedTable/toSortedTableColumnConfig.ts +12 -0
  45. package/src/components/WfoTable/WfoAdvancedTable/types.ts +23 -0
  46. package/src/components/WfoTable/WfoStatusColorField/WfoStatusColorField.tsx +16 -0
  47. package/src/components/WfoTable/WfoStatusColorField/index.ts +1 -0
  48. package/src/components/WfoTable/WfoStatusColorField/styles.ts +20 -0
  49. package/src/components/WfoTable/WfoTable/WfoExpandedRow.tsx +33 -0
  50. package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoExpandableRow.tsx +48 -0
  51. package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoExpandedGroupRow.tsx +71 -0
  52. package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoGroupedTable.tsx +100 -0
  53. package/src/components/WfoTable/WfoTable/WfoGroupedTable/WfoGroupedTableGroups.tsx +74 -0
  54. package/src/components/WfoTable/WfoTable/WfoGroupedTable/styles.ts +39 -0
  55. package/src/components/WfoTable/WfoTable/WfoGroupedTable/useGroupedTableConfig.tsx +184 -0
  56. package/src/components/WfoTable/WfoTable/WfoGroupedTable/utils.spec.ts +133 -0
  57. package/src/components/WfoTable/WfoTable/WfoGroupedTable/utils.ts +41 -0
  58. package/src/components/WfoTable/WfoTable/WfoMultilineCell.tsx +13 -0
  59. package/src/components/WfoTable/WfoTable/WfoTable.tsx +201 -0
  60. package/src/components/WfoTable/WfoTable/WfoTableDataRows.tsx +112 -0
  61. package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/WfoSortDirectionIcon.tsx +3 -3
  62. package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/WfoTableHeaderCell.tsx +4 -3
  63. package/src/components/WfoTable/WfoTable/WfoTableHeaderCell/index.ts +2 -0
  64. package/src/components/WfoTable/WfoTable/WfoTableHeaderRow.tsx +114 -0
  65. package/src/components/WfoTable/WfoTable/WfoTruncateCell.tsx +23 -0
  66. package/src/components/WfoTable/WfoTable/constants.ts +1 -0
  67. package/src/components/WfoTable/WfoTable/index.ts +14 -0
  68. package/src/components/WfoTable/WfoTable/styles.ts +117 -0
  69. package/src/components/WfoTable/WfoTable/utils.spec.ts +79 -0
  70. package/src/components/WfoTable/WfoTable/utils.ts +78 -0
  71. package/src/components/WfoTable/WfoTableSettingsModal/WfoTableSettingsModal.tsx +13 -12
  72. package/src/components/WfoTable/WfoTableWithFilter/index.ts +1 -1
  73. package/src/components/WfoTable/index.ts +4 -5
  74. package/src/components/WfoTable/utils/columns.ts +1 -48
  75. package/src/components/WfoTable/utils/tableUtils.ts +13 -10
  76. package/src/components/WfoTree/WfoTreeBranch.tsx +10 -1
  77. package/src/components/WfoTree/WfoTreeNode.tsx +8 -57
  78. package/src/components/WfoTree/WfoTreeNodeListItem.tsx +65 -0
  79. package/src/components/WfoTree/styles.ts +28 -4
  80. package/src/components/index.ts +4 -0
  81. package/src/configuration/policy-resources.ts +1 -0
  82. package/src/configuration/version.ts +1 -1
  83. package/src/icons/WfoXMarkSmall.tsx +29 -0
  84. package/src/messages/en-GB.json +4 -0
  85. package/src/messages/nl-NL.json +4 -0
  86. package/src/pages/metadata/WfoMetadataPageLayout.tsx +4 -4
  87. package/src/pages/metadata/WfoProductBlocksPage.tsx +42 -59
  88. package/src/pages/metadata/WfoProductsPage.tsx +41 -47
  89. package/src/pages/metadata/WfoResourceTypesPage.tsx +26 -35
  90. package/src/pages/metadata/WfoTasksPage.tsx +35 -33
  91. package/src/pages/metadata/WfoWorkflowsPage.tsx +33 -29
  92. package/src/pages/processes/WfoProcessDetail.tsx +47 -55
  93. package/src/pages/settings/WfoSettingsPage.tsx +9 -4
  94. package/src/pages/startPage/WfoStartPage.tsx +17 -1
  95. package/src/pages/subscriptions/WfoSubscriptionsListPage.tsx +4 -5
  96. package/src/pages/tasks/WfoTasksListPage.tsx +44 -52
  97. package/src/pages/workflows/WfoWorkflowsListPage.tsx +4 -5
  98. package/src/rtk/endpoints/index.ts +1 -0
  99. package/src/rtk/endpoints/relatedSubscriptions.ts +5 -4
  100. package/src/rtk/endpoints/subscriptionActions.ts +11 -1
  101. package/src/utils/getObjectKeys.ts +3 -0
  102. package/src/utils/index.ts +5 -3
  103. package/tsup.config.ts +10 -0
  104. package/src/components/WfoTable/WfoBasicTable/WfoBasicTable.tsx +0 -194
  105. package/src/components/WfoTable/WfoBasicTable/WfoStatusColorField.tsx +0 -21
  106. package/src/components/WfoTable/WfoBasicTable/index.ts +0 -5
  107. package/src/components/WfoTable/WfoDataGridTable/WfoDataGridTable.stories.tsx +0 -136
  108. package/src/components/WfoTable/WfoDataGridTable/WfoDataGridTable.tsx +0 -146
  109. package/src/components/WfoTable/WfoDataGridTable/WfodataGridColumns.spec.ts +0 -113
  110. package/src/components/WfoTable/WfoDataGridTable/WfodataGridColumns.ts +0 -81
  111. package/src/components/WfoTable/utils/mapSortableAndFilterableValuesToTableColumnConfig.spec.ts +0 -52
  112. package/src/components/WfoTable/utils/mapSortableAndFilterableValuesToTableColumnConfig.ts +0 -23
  113. /package/src/components/WfoTable/{WfoBasicTable → WfoTable/WfoTableHeaderCell}/styles.ts +0 -0
@@ -15,3 +15,4 @@ export * from './subscriptionInUseByRelationsList';
15
15
  export * from './subscriptionList';
16
16
  export * from './subscriptionListSummary';
17
17
  export * from './subscriptionsDropdownOptions';
18
+ export * from './forms';
@@ -60,10 +60,11 @@ export type RelatedSubscriptionsResponse = {
60
60
  relatedSubscriptions: RelatedSubscription[];
61
61
  } & BaseGraphQlResult;
62
62
 
63
- type RelatedSubscriptionVariables = GraphqlQueryVariables<RelatedSubscription> &
64
- Pick<Subscription, 'subscriptionId'> & {
65
- terminatedSubscriptionFilter?: GraphqlFilter<RelatedSubscription>;
66
- };
63
+ export type RelatedSubscriptionVariables =
64
+ GraphqlQueryVariables<RelatedSubscription> &
65
+ Pick<Subscription, 'subscriptionId'> & {
66
+ terminatedSubscriptionFilter?: GraphqlFilter<RelatedSubscription>;
67
+ };
67
68
 
68
69
  const relatedSubscriptionsApi = orchestratorApi.injectEndpoints({
69
70
  endpoints: (build) => ({
@@ -1,6 +1,7 @@
1
1
  import { SUBSCRIPTION_ACTIONS_ENDPOINT } from '@/configuration';
2
2
  import { BaseQueryTypes, orchestratorApi } from '@/rtk';
3
- import { SubscriptionActions } from '@/types';
3
+ import { CacheTagType, SubscriptionActions } from '@/types';
4
+ import { getCacheTag } from '@/utils/cacheTag';
4
5
 
5
6
  const subscriptionActionsApi = orchestratorApi.injectEndpoints({
6
7
  endpoints: (build) => ({
@@ -13,6 +14,15 @@ const subscriptionActionsApi = orchestratorApi.injectEndpoints({
13
14
  extraOptions: {
14
15
  baseQueryType: BaseQueryTypes.fetch,
15
16
  },
17
+ providesTags: (result, error, queryArguments) => {
18
+ if (!error && result) {
19
+ return getCacheTag(
20
+ CacheTagType.subscriptions,
21
+ queryArguments.subscriptionId,
22
+ );
23
+ }
24
+ return [];
25
+ },
16
26
  }),
17
27
  }),
18
28
  });
@@ -0,0 +1,3 @@
1
+ export const getObjectKeys = <T extends object>(
2
+ inputObject: T,
3
+ ): Array<keyof T> => Object.keys(inputObject) as Array<keyof T>;
@@ -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 './uuid';
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';
package/tsup.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ target: 'es2020',
5
+ format: ['esm'],
6
+ splitting: false,
7
+ sourcemap: true,
8
+ dts: true,
9
+ tsconfig: 'tsconfig.build.json',
10
+ });
@@ -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,5 +0,0 @@
1
- export * from './WfoBasicTable';
2
- export * from './WfoSortDirectionIcon';
3
- export * from './WfoTableHeaderCell';
4
- export * from './WfoStatusColorField';
5
- export * from './styles';
@@ -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
- };