@etsoo/react 1.5.79 → 1.5.82
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/README.md +7 -2
- package/__tests__/ReactUtils.ts +6 -0
- package/lib/{mu → components}/DnDList.d.ts +1 -14
- package/lib/{mu → components}/DnDList.js +1 -24
- package/lib/components/GridMethodRef.d.ts +11 -0
- package/lib/{mu → components}/GridMethodRef.js +0 -0
- package/lib/components/ScrollerGrid.d.ts +3 -3
- package/lib/components/ScrollerList.d.ts +3 -3
- package/lib/index.d.ts +2 -74
- package/lib/index.js +2 -75
- package/lib/notifier/Notifier.d.ts +2 -3
- package/lib/uses/useWindowScroll.d.ts +10 -0
- package/lib/uses/useWindowScroll.js +46 -0
- package/lib/uses/useWindowSize.js +11 -5
- package/package.json +9 -21
- package/src/{mu → components}/DnDList.tsx +11 -34
- package/src/components/GridMethodRef.ts +12 -0
- package/src/components/ScrollerGrid.tsx +3 -3
- package/src/components/ScrollerList.tsx +5 -3
- package/src/index.ts +2 -78
- package/src/notifier/Notifier.ts +2 -3
- package/src/uses/useWindowScroll.ts +60 -0
- package/src/uses/useWindowSize.ts +14 -5
- package/__tests__/mu/MUGlobalTests.tsx +0 -58
- package/__tests__/mu/NotifierMUTests.tsx +0 -213
- package/lib/app/CommonApp.d.ts +0 -39
- package/lib/app/CommonApp.js +0 -149
- package/lib/app/IServiceAppSettings.d.ts +0 -11
- package/lib/app/IServiceAppSettings.js +0 -1
- package/lib/app/IServicePage.d.ts +0 -6
- package/lib/app/IServicePage.js +0 -1
- package/lib/app/IServiceUser.d.ts +0 -14
- package/lib/app/IServiceUser.js +0 -1
- package/lib/app/ISmartERPUser.d.ts +0 -14
- package/lib/app/ISmartERPUser.js +0 -1
- package/lib/app/Labels.d.ts +0 -65
- package/lib/app/Labels.js +0 -62
- package/lib/app/ReactApp.d.ts +0 -194
- package/lib/app/ReactApp.js +0 -298
- package/lib/app/ServiceApp.d.ts +0 -78
- package/lib/app/ServiceApp.js +0 -244
- package/lib/components/ShowDataComparison.d.ts +0 -20
- package/lib/components/ShowDataComparison.js +0 -60
- package/lib/mu/AuditDisplay.d.ts +0 -33
- package/lib/mu/AuditDisplay.js +0 -52
- package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
- package/lib/mu/AutocompleteExtendedProps.js +0 -1
- package/lib/mu/BackButton.d.ts +0 -13
- package/lib/mu/BackButton.js +0 -33
- package/lib/mu/BridgeCloseButton.d.ts +0 -23
- package/lib/mu/BridgeCloseButton.js +0 -32
- package/lib/mu/ButtonLink.d.ts +0 -17
- package/lib/mu/ButtonLink.js +0 -19
- package/lib/mu/ComboBox.d.ts +0 -38
- package/lib/mu/ComboBox.js +0 -108
- package/lib/mu/CountdownButton.d.ts +0 -23
- package/lib/mu/CountdownButton.js +0 -81
- package/lib/mu/CustomFabProps.d.ts +0 -27
- package/lib/mu/CustomFabProps.js +0 -1
- package/lib/mu/DataGridEx.d.ts +0 -96
- package/lib/mu/DataGridEx.js +0 -331
- package/lib/mu/DataGridRenderers.d.ts +0 -22
- package/lib/mu/DataGridRenderers.js +0 -99
- package/lib/mu/DialogButton.d.ts +0 -54
- package/lib/mu/DialogButton.js +0 -45
- package/lib/mu/DraggablePaperComponent.d.ts +0 -8
- package/lib/mu/DraggablePaperComponent.js +0 -12
- package/lib/mu/EmailInput.d.ts +0 -11
- package/lib/mu/EmailInput.js +0 -15
- package/lib/mu/FabBox.d.ts +0 -21
- package/lib/mu/FabBox.js +0 -31
- package/lib/mu/FlexBox.d.ts +0 -14
- package/lib/mu/FlexBox.js +0 -18
- package/lib/mu/GridDataFormat.d.ts +0 -10
- package/lib/mu/GridDataFormat.js +0 -43
- package/lib/mu/GridMethodRef.d.ts +0 -11
- package/lib/mu/IconButtonLink.d.ts +0 -17
- package/lib/mu/IconButtonLink.js +0 -16
- package/lib/mu/InputField.d.ts +0 -21
- package/lib/mu/InputField.js +0 -39
- package/lib/mu/ItemList.d.ts +0 -56
- package/lib/mu/ItemList.js +0 -69
- package/lib/mu/ListItemRightIcon.d.ts +0 -4
- package/lib/mu/ListItemRightIcon.js +0 -8
- package/lib/mu/ListMoreDisplay.d.ts +0 -35
- package/lib/mu/ListMoreDisplay.js +0 -99
- package/lib/mu/LoadingButton.d.ts +0 -16
- package/lib/mu/LoadingButton.js +0 -41
- package/lib/mu/MUGlobal.d.ts +0 -102
- package/lib/mu/MUGlobal.js +0 -184
- package/lib/mu/MaskInput.d.ts +0 -34
- package/lib/mu/MaskInput.js +0 -43
- package/lib/mu/MobileListItemRenderer.d.ts +0 -17
- package/lib/mu/MobileListItemRenderer.js +0 -35
- package/lib/mu/MoreFab.d.ts +0 -45
- package/lib/mu/MoreFab.js +0 -95
- package/lib/mu/NotifierMU.d.ts +0 -47
- package/lib/mu/NotifierMU.js +0 -387
- package/lib/mu/NotifierPromptProps.d.ts +0 -22
- package/lib/mu/NotifierPromptProps.js +0 -1
- package/lib/mu/OptionGroup.d.ts +0 -58
- package/lib/mu/OptionGroup.js +0 -81
- package/lib/mu/PList.d.ts +0 -15
- package/lib/mu/PList.js +0 -12
- package/lib/mu/ProgressCount.d.ts +0 -44
- package/lib/mu/ProgressCount.js +0 -79
- package/lib/mu/PullToRefreshUI.d.ts +0 -9
- package/lib/mu/PullToRefreshUI.js +0 -18
- package/lib/mu/RLink.d.ts +0 -14
- package/lib/mu/RLink.js +0 -37
- package/lib/mu/ResponsibleContainer.d.ts +0 -89
- package/lib/mu/ResponsibleContainer.js +0 -159
- package/lib/mu/ScrollTopFab.d.ts +0 -7
- package/lib/mu/ScrollTopFab.js +0 -25
- package/lib/mu/ScrollerListEx.d.ts +0 -81
- package/lib/mu/ScrollerListEx.js +0 -167
- package/lib/mu/SearchBar.d.ts +0 -29
- package/lib/mu/SearchBar.js +0 -262
- package/lib/mu/SearchField.d.ts +0 -21
- package/lib/mu/SearchField.js +0 -39
- package/lib/mu/SearchOptionGroup.d.ts +0 -9
- package/lib/mu/SearchOptionGroup.js +0 -14
- package/lib/mu/SelectBool.d.ts +0 -13
- package/lib/mu/SelectBool.js +0 -22
- package/lib/mu/SelectEx.d.ts +0 -50
- package/lib/mu/SelectEx.js +0 -156
- package/lib/mu/Switch.d.ts +0 -29
- package/lib/mu/Switch.js +0 -34
- package/lib/mu/SwitchAnt.d.ts +0 -25
- package/lib/mu/SwitchAnt.js +0 -40
- package/lib/mu/TabBox.d.ts +0 -54
- package/lib/mu/TabBox.js +0 -31
- package/lib/mu/TableEx.d.ts +0 -66
- package/lib/mu/TableEx.js +0 -271
- package/lib/mu/TextFieldEx.d.ts +0 -101
- package/lib/mu/TextFieldEx.js +0 -127
- package/lib/mu/Tiplist.d.ts +0 -18
- package/lib/mu/Tiplist.js +0 -158
- package/lib/mu/TooltipClick.d.ts +0 -15
- package/lib/mu/TooltipClick.js +0 -40
- package/lib/mu/UserAvatar.d.ts +0 -24
- package/lib/mu/UserAvatar.js +0 -25
- package/lib/mu/UserAvatarEditor.d.ts +0 -53
- package/lib/mu/UserAvatarEditor.js +0 -129
- package/lib/mu/pages/CommonPage.d.ts +0 -11
- package/lib/mu/pages/CommonPage.js +0 -60
- package/lib/mu/pages/CommonPageProps.d.ts +0 -60
- package/lib/mu/pages/CommonPageProps.js +0 -1
- package/lib/mu/pages/DataGridPage.d.ts +0 -9
- package/lib/mu/pages/DataGridPage.js +0 -81
- package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
- package/lib/mu/pages/DataGridPageProps.js +0 -1
- package/lib/mu/pages/EditPage.d.ts +0 -33
- package/lib/mu/pages/EditPage.js +0 -29
- package/lib/mu/pages/FixedListPage.d.ts +0 -15
- package/lib/mu/pages/FixedListPage.js +0 -72
- package/lib/mu/pages/ListPage.d.ts +0 -9
- package/lib/mu/pages/ListPage.js +0 -51
- package/lib/mu/pages/ListPageProps.d.ts +0 -7
- package/lib/mu/pages/ListPageProps.js +0 -1
- package/lib/mu/pages/ResponsivePage.d.ts +0 -9
- package/lib/mu/pages/ResponsivePage.js +0 -45
- package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
- package/lib/mu/pages/ResponsivePageProps.js +0 -1
- package/lib/mu/pages/SearchPageProps.d.ts +0 -30
- package/lib/mu/pages/SearchPageProps.js +0 -1
- package/lib/mu/pages/TablePage.d.ts +0 -9
- package/lib/mu/pages/TablePage.js +0 -71
- package/lib/mu/pages/TablePageProps.d.ts +0 -7
- package/lib/mu/pages/TablePageProps.js +0 -1
- package/lib/mu/pages/ViewPage.d.ts +0 -66
- package/lib/mu/pages/ViewPage.js +0 -105
- package/lib/mu/texts/DateText.d.ts +0 -34
- package/lib/mu/texts/DateText.js +0 -25
- package/lib/mu/texts/MoneyText.d.ts +0 -21
- package/lib/mu/texts/MoneyText.js +0 -14
- package/lib/mu/texts/NumberText.d.ts +0 -25
- package/lib/mu/texts/NumberText.js +0 -14
- package/src/app/CommonApp.ts +0 -225
- package/src/app/IServiceAppSettings.ts +0 -13
- package/src/app/IServicePage.ts +0 -6
- package/src/app/IServiceUser.ts +0 -17
- package/src/app/ISmartERPUser.ts +0 -16
- package/src/app/Labels.ts +0 -77
- package/src/app/ReactApp.ts +0 -500
- package/src/app/ServiceApp.ts +0 -353
- package/src/components/ShowDataComparison.tsx +0 -108
- package/src/mu/AuditDisplay.tsx +0 -117
- package/src/mu/AutocompleteExtendedProps.ts +0 -83
- package/src/mu/BackButton.tsx +0 -55
- package/src/mu/BridgeCloseButton.tsx +0 -69
- package/src/mu/ButtonLink.tsx +0 -32
- package/src/mu/ComboBox.tsx +0 -251
- package/src/mu/CountdownButton.tsx +0 -119
- package/src/mu/CustomFabProps.ts +0 -32
- package/src/mu/DataGridEx.tsx +0 -712
- package/src/mu/DataGridRenderers.tsx +0 -140
- package/src/mu/DialogButton.tsx +0 -163
- package/src/mu/DraggablePaperComponent.tsx +0 -19
- package/src/mu/EmailInput.tsx +0 -24
- package/src/mu/FabBox.tsx +0 -51
- package/src/mu/FlexBox.tsx +0 -20
- package/src/mu/GridDataFormat.tsx +0 -77
- package/src/mu/GridMethodRef.ts +0 -12
- package/src/mu/IconButtonLink.tsx +0 -29
- package/src/mu/InputField.tsx +0 -82
- package/src/mu/ItemList.tsx +0 -204
- package/src/mu/ListItemRightIcon.tsx +0 -9
- package/src/mu/ListMoreDisplay.tsx +0 -205
- package/src/mu/LoadingButton.tsx +0 -75
- package/src/mu/MUGlobal.ts +0 -220
- package/src/mu/MaskInput.tsx +0 -107
- package/src/mu/MobileListItemRenderer.tsx +0 -79
- package/src/mu/MoreFab.tsx +0 -211
- package/src/mu/NotifierMU.tsx +0 -654
- package/src/mu/NotifierPromptProps.ts +0 -26
- package/src/mu/OptionGroup.tsx +0 -223
- package/src/mu/PList.tsx +0 -27
- package/src/mu/ProgressCount.tsx +0 -166
- package/src/mu/PullToRefreshUI.tsx +0 -21
- package/src/mu/RLink.tsx +0 -64
- package/src/mu/ResponsibleContainer.tsx +0 -394
- package/src/mu/ScrollTopFab.tsx +0 -34
- package/src/mu/ScrollerListEx.tsx +0 -387
- package/src/mu/SearchBar.tsx +0 -398
- package/src/mu/SearchField.tsx +0 -82
- package/src/mu/SearchOptionGroup.tsx +0 -31
- package/src/mu/SelectBool.tsx +0 -33
- package/src/mu/SelectEx.tsx +0 -290
- package/src/mu/Switch.tsx +0 -94
- package/src/mu/SwitchAnt.tsx +0 -95
- package/src/mu/TabBox.tsx +0 -118
- package/src/mu/TableEx.tsx +0 -560
- package/src/mu/TextFieldEx.tsx +0 -250
- package/src/mu/Tiplist.tsx +0 -304
- package/src/mu/TooltipClick.tsx +0 -84
- package/src/mu/UserAvatar.tsx +0 -64
- package/src/mu/UserAvatarEditor.tsx +0 -287
- package/src/mu/pages/CommonPage.tsx +0 -128
- package/src/mu/pages/CommonPageProps.ts +0 -71
- package/src/mu/pages/DataGridPage.tsx +0 -137
- package/src/mu/pages/DataGridPageProps.ts +0 -24
- package/src/mu/pages/EditPage.tsx +0 -114
- package/src/mu/pages/FixedListPage.tsx +0 -135
- package/src/mu/pages/ListPage.tsx +0 -87
- package/src/mu/pages/ListPageProps.ts +0 -12
- package/src/mu/pages/ResponsivePage.tsx +0 -68
- package/src/mu/pages/ResponsivePageProps.ts +0 -57
- package/src/mu/pages/SearchPageProps.ts +0 -39
- package/src/mu/pages/TablePage.tsx +0 -120
- package/src/mu/pages/TablePageProps.ts +0 -12
- package/src/mu/pages/ViewPage.tsx +0 -285
- package/src/mu/texts/DateText.tsx +0 -74
- package/src/mu/texts/MoneyText.tsx +0 -49
- package/src/mu/texts/NumberText.tsx +0 -40
package/src/mu/TableEx.tsx
DELETED
|
@@ -1,560 +0,0 @@
|
|
|
1
|
-
import { DataTypes, IdDefaultType } from '@etsoo/shared';
|
|
2
|
-
import {
|
|
3
|
-
Checkbox,
|
|
4
|
-
Paper,
|
|
5
|
-
Table,
|
|
6
|
-
TableBody,
|
|
7
|
-
TableCell,
|
|
8
|
-
TableCellProps,
|
|
9
|
-
TableContainer,
|
|
10
|
-
TableHead,
|
|
11
|
-
TablePagination,
|
|
12
|
-
TableProps,
|
|
13
|
-
TableRow,
|
|
14
|
-
TableSortLabel,
|
|
15
|
-
useTheme
|
|
16
|
-
} from '@mui/material';
|
|
17
|
-
import React from 'react';
|
|
18
|
-
import {
|
|
19
|
-
GridAlignGet,
|
|
20
|
-
GridCellFormatterProps,
|
|
21
|
-
GridColumn
|
|
22
|
-
} from '../components/GridColumn';
|
|
23
|
-
import {
|
|
24
|
-
GridLoadDataProps,
|
|
25
|
-
GridLoader,
|
|
26
|
-
GridLoaderStates,
|
|
27
|
-
GridSizeGet
|
|
28
|
-
} from '../components/GridLoader';
|
|
29
|
-
import { DataGridRenderers } from './DataGridRenderers';
|
|
30
|
-
import { GridMethodRef } from './GridMethodRef';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Extended table min width for width-unset column
|
|
34
|
-
*/
|
|
35
|
-
export const TableExMinWidth: number = 180;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Extended table methods ref
|
|
39
|
-
*/
|
|
40
|
-
export interface TableExMethodRef extends GridMethodRef {
|
|
41
|
-
/**
|
|
42
|
-
* Refresh data
|
|
43
|
-
*/
|
|
44
|
-
refresh(): void;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Extended table props
|
|
49
|
-
*/
|
|
50
|
-
export type TableExProps<
|
|
51
|
-
T extends object,
|
|
52
|
-
D extends DataTypes.Keys<T>
|
|
53
|
-
> = TableProps &
|
|
54
|
-
GridLoader<T> & {
|
|
55
|
-
/**
|
|
56
|
-
* Alternating colors for odd/even rows
|
|
57
|
-
*/
|
|
58
|
-
alternatingColors?: [string?, string?];
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Columns
|
|
62
|
-
*/
|
|
63
|
-
columns: GridColumn<T>[];
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Header cells background color and font color
|
|
67
|
-
*/
|
|
68
|
-
headerColors?: [string?, string?];
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Id field
|
|
72
|
-
*/
|
|
73
|
-
idField?: D;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Max height
|
|
77
|
-
*/
|
|
78
|
-
maxHeight?: number;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Methods
|
|
82
|
-
*/
|
|
83
|
-
mRef?: React.Ref<TableExMethodRef>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* On items select change
|
|
87
|
-
*/
|
|
88
|
-
onSelectChange?: (selectedItems: T[]) => void;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Row height
|
|
92
|
-
*/
|
|
93
|
-
rowHeight?: number;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Header and bottom height
|
|
97
|
-
*/
|
|
98
|
-
otherHeight?: number;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Extended Table
|
|
103
|
-
* @param props Props
|
|
104
|
-
* @returns Component
|
|
105
|
-
*/
|
|
106
|
-
export function TableEx<
|
|
107
|
-
T extends object,
|
|
108
|
-
D extends DataTypes.Keys<T> = IdDefaultType<T>
|
|
109
|
-
>(props: TableExProps<T, D>) {
|
|
110
|
-
// Theme
|
|
111
|
-
const theme = useTheme();
|
|
112
|
-
|
|
113
|
-
// Destruct
|
|
114
|
-
const {
|
|
115
|
-
alternatingColors = [theme.palette.action.hover, undefined],
|
|
116
|
-
autoLoad = true,
|
|
117
|
-
columns,
|
|
118
|
-
defaultOrderBy,
|
|
119
|
-
headerColors = [undefined, undefined],
|
|
120
|
-
idField = 'id' as D,
|
|
121
|
-
loadBatchSize,
|
|
122
|
-
loadData,
|
|
123
|
-
maxHeight,
|
|
124
|
-
mRef,
|
|
125
|
-
onSelectChange,
|
|
126
|
-
rowHeight = 53,
|
|
127
|
-
otherHeight = 110,
|
|
128
|
-
threshold,
|
|
129
|
-
...rest
|
|
130
|
-
} = props;
|
|
131
|
-
|
|
132
|
-
const selectable: boolean = onSelectChange != null;
|
|
133
|
-
|
|
134
|
-
// Rows per page
|
|
135
|
-
let rowsPerPageLocal: number;
|
|
136
|
-
if (maxHeight != null) {
|
|
137
|
-
if (loadBatchSize != null)
|
|
138
|
-
rowsPerPageLocal = GridSizeGet(loadBatchSize, maxHeight);
|
|
139
|
-
else
|
|
140
|
-
rowsPerPageLocal = Math.floor(
|
|
141
|
-
(maxHeight - otherHeight) / rowHeight
|
|
142
|
-
);
|
|
143
|
-
} else if (typeof loadBatchSize === 'number') {
|
|
144
|
-
rowsPerPageLocal = loadBatchSize;
|
|
145
|
-
} else {
|
|
146
|
-
rowsPerPageLocal = 10;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Rows
|
|
150
|
-
const [rows, updateRows] = React.useState<T[]>([]);
|
|
151
|
-
const setRows = (rows: T[]) => {
|
|
152
|
-
state.loadedItems = rows.length;
|
|
153
|
-
updateRows(rows);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// States
|
|
157
|
-
const stateRefs = React.useRef<GridLoaderStates<T>>({
|
|
158
|
-
autoLoad,
|
|
159
|
-
currentPage: 0,
|
|
160
|
-
loadedItems: 0,
|
|
161
|
-
hasNextPage: true,
|
|
162
|
-
isNextPageLoading: false,
|
|
163
|
-
orderBy: defaultOrderBy,
|
|
164
|
-
orderByAsc: defaultOrderBy
|
|
165
|
-
? columns.find((column) => column.field === defaultOrderBy)?.sortAsc
|
|
166
|
-
: undefined,
|
|
167
|
-
batchSize: rowsPerPageLocal,
|
|
168
|
-
selectedItems: []
|
|
169
|
-
});
|
|
170
|
-
const state = stateRefs.current;
|
|
171
|
-
|
|
172
|
-
// Reset the state and load again
|
|
173
|
-
const reset = (add?: Partial<GridLoaderStates<T>>) => {
|
|
174
|
-
const resetState: Partial<GridLoaderStates<T>> = {
|
|
175
|
-
autoLoad: true,
|
|
176
|
-
currentPage: 0,
|
|
177
|
-
loadedItems: 0,
|
|
178
|
-
hasNextPage: true,
|
|
179
|
-
isNextPageLoading: false,
|
|
180
|
-
lastLoadedItems: undefined,
|
|
181
|
-
...add
|
|
182
|
-
};
|
|
183
|
-
Object.assign(state, resetState);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
React.useImperativeHandle(
|
|
187
|
-
mRef,
|
|
188
|
-
() => ({
|
|
189
|
-
/**
|
|
190
|
-
* Refresh data
|
|
191
|
-
*/
|
|
192
|
-
refresh(): void {
|
|
193
|
-
loadDataLocal();
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Reset
|
|
198
|
-
*/
|
|
199
|
-
reset
|
|
200
|
-
}),
|
|
201
|
-
[]
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
// Load data
|
|
205
|
-
const loadDataLocal = () => {
|
|
206
|
-
// Prevent multiple loadings
|
|
207
|
-
if (!state.hasNextPage || state.isNextPageLoading) return;
|
|
208
|
-
|
|
209
|
-
// Update state
|
|
210
|
-
state.isNextPageLoading = true;
|
|
211
|
-
|
|
212
|
-
// Parameters
|
|
213
|
-
const { currentPage, batchSize, orderBy, orderByAsc, data, isMounted } =
|
|
214
|
-
state;
|
|
215
|
-
|
|
216
|
-
const loadProps: GridLoadDataProps = {
|
|
217
|
-
currentPage,
|
|
218
|
-
batchSize,
|
|
219
|
-
orderBy,
|
|
220
|
-
orderByAsc,
|
|
221
|
-
data
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
loadData(loadProps).then((result) => {
|
|
225
|
-
state.isMounted = true;
|
|
226
|
-
if (result == null || isMounted === false) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const newItems = result.length;
|
|
231
|
-
state.lastLoadedItems = newItems;
|
|
232
|
-
state.hasNextPage = newItems >= batchSize;
|
|
233
|
-
state.isNextPageLoading = false;
|
|
234
|
-
|
|
235
|
-
// Update rows
|
|
236
|
-
setRows(result);
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const handleChangePage = (_event: unknown, newPage: number) => {
|
|
241
|
-
state.hasNextPage = true;
|
|
242
|
-
state.currentPage = newPage;
|
|
243
|
-
loadDataLocal();
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const handleChangeRowsPerPage = (
|
|
247
|
-
event: React.ChangeEvent<HTMLInputElement>
|
|
248
|
-
) => {
|
|
249
|
-
const batchSize = parseInt(event.target.value);
|
|
250
|
-
reset({ batchSize });
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const handleSelect = (item: T, checked: Boolean) => {
|
|
254
|
-
const selectedItems = state.selectedItems;
|
|
255
|
-
|
|
256
|
-
const index = selectedItems.findIndex(
|
|
257
|
-
(selectedItem) => selectedItem[idField] === item[idField]
|
|
258
|
-
);
|
|
259
|
-
if (checked) {
|
|
260
|
-
if (index === -1) selectedItems.push(item);
|
|
261
|
-
} else {
|
|
262
|
-
if (index !== -1) selectedItems.splice(index, 1);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (onSelectChange != null) {
|
|
266
|
-
onSelectChange(selectedItems);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const handleSelectAll = (checked: boolean) => {
|
|
271
|
-
const selectedItems = state.selectedItems;
|
|
272
|
-
|
|
273
|
-
rows.forEach((row) => {
|
|
274
|
-
const index = selectedItems.findIndex(
|
|
275
|
-
(selectedItem) => selectedItem[idField] === row[idField]
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
if (checked) {
|
|
279
|
-
if (index === -1) selectedItems.push(row);
|
|
280
|
-
} else if (index !== -1) {
|
|
281
|
-
selectedItems.splice(index, 1);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
if (onSelectChange != null) {
|
|
286
|
-
onSelectChange(selectedItems);
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// New sort
|
|
291
|
-
const handleSort = (field: string, asc?: boolean) => {
|
|
292
|
-
reset({ orderBy: field, orderByAsc: asc });
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
// Destruct states
|
|
296
|
-
const {
|
|
297
|
-
autoLoad: stateAutoLoad,
|
|
298
|
-
currentPage,
|
|
299
|
-
hasNextPage,
|
|
300
|
-
lastLoadedItems,
|
|
301
|
-
orderBy,
|
|
302
|
-
batchSize,
|
|
303
|
-
selectedItems
|
|
304
|
-
} = state;
|
|
305
|
-
|
|
306
|
-
// Current page selected items
|
|
307
|
-
const pageSelectedItems = selectable
|
|
308
|
-
? rows.reduce((previousValue, currentItem) => {
|
|
309
|
-
if (
|
|
310
|
-
selectedItems.some(
|
|
311
|
-
(item) => item[idField] === currentItem[idField]
|
|
312
|
-
)
|
|
313
|
-
)
|
|
314
|
-
return previousValue + 1;
|
|
315
|
-
|
|
316
|
-
return previousValue;
|
|
317
|
-
}, 0)
|
|
318
|
-
: 0;
|
|
319
|
-
|
|
320
|
-
// Total rows
|
|
321
|
-
const totalRows = hasNextPage
|
|
322
|
-
? -1
|
|
323
|
-
: currentPage * batchSize + (lastLoadedItems ?? 0);
|
|
324
|
-
|
|
325
|
-
// Auto load data when current page is 0
|
|
326
|
-
if (currentPage === 0 && stateAutoLoad && lastLoadedItems == null)
|
|
327
|
-
loadDataLocal();
|
|
328
|
-
|
|
329
|
-
React.useEffect(() => {
|
|
330
|
-
return () => {
|
|
331
|
-
state.isMounted = false;
|
|
332
|
-
};
|
|
333
|
-
}, []);
|
|
334
|
-
|
|
335
|
-
// Layout
|
|
336
|
-
return (
|
|
337
|
-
<Paper>
|
|
338
|
-
<TableContainer sx={{ maxHeight }}>
|
|
339
|
-
<Table {...rest}>
|
|
340
|
-
<TableHead>
|
|
341
|
-
<TableRow
|
|
342
|
-
sx={{
|
|
343
|
-
'& th': {
|
|
344
|
-
backgroundColor: headerColors[0],
|
|
345
|
-
color: headerColors[1]
|
|
346
|
-
}
|
|
347
|
-
}}
|
|
348
|
-
>
|
|
349
|
-
{selectable && (
|
|
350
|
-
<TableCell padding="checkbox">
|
|
351
|
-
<Checkbox
|
|
352
|
-
color="primary"
|
|
353
|
-
indeterminate={
|
|
354
|
-
pageSelectedItems > 0 &&
|
|
355
|
-
pageSelectedItems < rows.length
|
|
356
|
-
}
|
|
357
|
-
checked={pageSelectedItems > 0}
|
|
358
|
-
onChange={(_event, checked) =>
|
|
359
|
-
handleSelectAll(checked)
|
|
360
|
-
}
|
|
361
|
-
/>
|
|
362
|
-
</TableCell>
|
|
363
|
-
)}
|
|
364
|
-
{columns.map((column, index) => {
|
|
365
|
-
// Destruct
|
|
366
|
-
const {
|
|
367
|
-
align,
|
|
368
|
-
field,
|
|
369
|
-
header,
|
|
370
|
-
minWidth,
|
|
371
|
-
sortable,
|
|
372
|
-
sortAsc = true,
|
|
373
|
-
type,
|
|
374
|
-
width
|
|
375
|
-
} = column;
|
|
376
|
-
|
|
377
|
-
// Header text
|
|
378
|
-
const headerText = header ?? field;
|
|
379
|
-
|
|
380
|
-
// Sortable
|
|
381
|
-
let sortLabel: React.ReactNode;
|
|
382
|
-
if (sortable && field != null) {
|
|
383
|
-
const active = orderBy === field;
|
|
384
|
-
|
|
385
|
-
sortLabel = (
|
|
386
|
-
<TableSortLabel
|
|
387
|
-
active={active}
|
|
388
|
-
direction={sortAsc ? 'asc' : 'desc'}
|
|
389
|
-
onClick={(_event) => {
|
|
390
|
-
if (active)
|
|
391
|
-
column.sortAsc = !sortAsc;
|
|
392
|
-
|
|
393
|
-
handleSort(
|
|
394
|
-
field,
|
|
395
|
-
column.sortAsc
|
|
396
|
-
);
|
|
397
|
-
}}
|
|
398
|
-
>
|
|
399
|
-
{headerText}
|
|
400
|
-
</TableSortLabel>
|
|
401
|
-
);
|
|
402
|
-
} else {
|
|
403
|
-
sortLabel = headerText;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return (
|
|
407
|
-
<TableCell
|
|
408
|
-
align={GridAlignGet(align, type)}
|
|
409
|
-
key={field ?? index.toString()}
|
|
410
|
-
width={width}
|
|
411
|
-
sx={{
|
|
412
|
-
minWidth:
|
|
413
|
-
minWidth == null
|
|
414
|
-
? width == null
|
|
415
|
-
? TableExMinWidth
|
|
416
|
-
: undefined
|
|
417
|
-
: minWidth
|
|
418
|
-
}}
|
|
419
|
-
>
|
|
420
|
-
{sortLabel}
|
|
421
|
-
</TableCell>
|
|
422
|
-
);
|
|
423
|
-
})}
|
|
424
|
-
</TableRow>
|
|
425
|
-
</TableHead>
|
|
426
|
-
<TableBody
|
|
427
|
-
sx={{
|
|
428
|
-
'& tr:nth-of-type(odd):not(.Mui-selected)': {
|
|
429
|
-
backgroundColor: alternatingColors[0]
|
|
430
|
-
},
|
|
431
|
-
'& tr:nth-of-type(even):not(.Mui-selected)': {
|
|
432
|
-
backgroundColor: alternatingColors[1]
|
|
433
|
-
}
|
|
434
|
-
}}
|
|
435
|
-
>
|
|
436
|
-
{[...Array(batchSize)].map((_item, rowIndex) => {
|
|
437
|
-
// Row
|
|
438
|
-
const row =
|
|
439
|
-
rowIndex < rows.length
|
|
440
|
-
? rows[rowIndex]
|
|
441
|
-
: undefined;
|
|
442
|
-
|
|
443
|
-
// Row id field value
|
|
444
|
-
const rowId =
|
|
445
|
-
DataTypes.getValue(row, idField) ?? rowIndex;
|
|
446
|
-
|
|
447
|
-
// Selected or not
|
|
448
|
-
const isItemSelected = selectable
|
|
449
|
-
? selectedItems.some(
|
|
450
|
-
(item) => item[idField] === rowId
|
|
451
|
-
)
|
|
452
|
-
: false;
|
|
453
|
-
|
|
454
|
-
return (
|
|
455
|
-
<TableRow
|
|
456
|
-
key={rowId as unknown as React.Key}
|
|
457
|
-
selected={isItemSelected}
|
|
458
|
-
>
|
|
459
|
-
{selectable && (
|
|
460
|
-
<TableCell padding="checkbox">
|
|
461
|
-
{row && (
|
|
462
|
-
<Checkbox
|
|
463
|
-
color="primary"
|
|
464
|
-
checked={isItemSelected}
|
|
465
|
-
onChange={(
|
|
466
|
-
_event,
|
|
467
|
-
checked
|
|
468
|
-
) =>
|
|
469
|
-
handleSelect(
|
|
470
|
-
row,
|
|
471
|
-
checked
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
/>
|
|
475
|
-
)}
|
|
476
|
-
</TableCell>
|
|
477
|
-
)}
|
|
478
|
-
{columns.map(
|
|
479
|
-
(
|
|
480
|
-
{
|
|
481
|
-
align,
|
|
482
|
-
cellRenderer = DataGridRenderers.defaultCellRenderer,
|
|
483
|
-
field,
|
|
484
|
-
type,
|
|
485
|
-
valueFormatter
|
|
486
|
-
},
|
|
487
|
-
columnIndex
|
|
488
|
-
) => {
|
|
489
|
-
const formatProps: GridCellFormatterProps<T> =
|
|
490
|
-
{
|
|
491
|
-
data: row,
|
|
492
|
-
field,
|
|
493
|
-
rowIndex,
|
|
494
|
-
columnIndex
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
const cellProps: TableCellProps = {
|
|
498
|
-
align: GridAlignGet(
|
|
499
|
-
align,
|
|
500
|
-
type
|
|
501
|
-
),
|
|
502
|
-
valign: 'middle'
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
const child = row ? (
|
|
506
|
-
cellRenderer({
|
|
507
|
-
data: row,
|
|
508
|
-
field,
|
|
509
|
-
formattedValue:
|
|
510
|
-
valueFormatter
|
|
511
|
-
? valueFormatter(
|
|
512
|
-
formatProps
|
|
513
|
-
)
|
|
514
|
-
: undefined,
|
|
515
|
-
selected: isItemSelected,
|
|
516
|
-
type,
|
|
517
|
-
rowIndex,
|
|
518
|
-
columnIndex,
|
|
519
|
-
cellProps
|
|
520
|
-
})
|
|
521
|
-
) : (
|
|
522
|
-
<React.Fragment>
|
|
523
|
-
|
|
524
|
-
</React.Fragment>
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
return (
|
|
528
|
-
<TableCell
|
|
529
|
-
key={`${rowId}${columnIndex}`}
|
|
530
|
-
{...cellProps}
|
|
531
|
-
>
|
|
532
|
-
{child}
|
|
533
|
-
</TableCell>
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
)}
|
|
537
|
-
</TableRow>
|
|
538
|
-
);
|
|
539
|
-
})}
|
|
540
|
-
</TableBody>
|
|
541
|
-
</Table>
|
|
542
|
-
</TableContainer>
|
|
543
|
-
<TablePagination
|
|
544
|
-
component="div"
|
|
545
|
-
showFirstButton
|
|
546
|
-
count={totalRows}
|
|
547
|
-
rowsPerPage={batchSize}
|
|
548
|
-
page={currentPage}
|
|
549
|
-
onPageChange={handleChangePage}
|
|
550
|
-
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
551
|
-
rowsPerPageOptions={[
|
|
552
|
-
batchSize,
|
|
553
|
-
2 * batchSize,
|
|
554
|
-
5 * batchSize,
|
|
555
|
-
10 * batchSize
|
|
556
|
-
]}
|
|
557
|
-
/>
|
|
558
|
-
</Paper>
|
|
559
|
-
);
|
|
560
|
-
}
|