@ercioko/meblotex-api 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/Api.d.ts +33 -0
- package/dist/api/Api.js +152 -0
- package/dist/api/Endpoint.d.ts +13 -0
- package/dist/api/Endpoint.js +126 -0
- package/dist/api/createApi.d.ts +53 -0
- package/dist/api/createApi.js +82 -0
- package/dist/api/error.d.ts +15 -0
- package/dist/api/error.js +18 -0
- package/{src/api/index.ts → dist/api/index.d.ts} +0 -1
- package/dist/api/index.js +34 -0
- package/dist/api/status.d.ts +3 -0
- package/dist/api/status.js +6 -0
- package/dist/api/utils/getAlert.d.ts +6 -0
- package/dist/api/utils/getAlert.js +65 -0
- package/dist/api/utils/index.js +8 -0
- package/dist/app_types.d.ts +607 -0
- package/dist/app_types.js +75 -0
- package/dist/components/ApiHostProvider.d.ts +7 -0
- package/dist/components/ApiHostProvider.js +35 -0
- package/dist/components/StatusTag.d.ts +11 -0
- package/dist/components/StatusTag.js +86 -0
- package/dist/components/Table/DataTableWrapper.d.ts +3 -0
- package/dist/components/Table/DataTableWrapper.js +44 -0
- package/dist/components/Table/FloatingActions.d.ts +14 -0
- package/dist/components/Table/FloatingActions.js +32 -0
- package/dist/components/Table/Spinner.d.ts +2 -0
- package/dist/components/Table/Spinner.js +26 -0
- package/dist/components/Table/Table.d.ts +28 -0
- package/dist/components/Table/Table.js +330 -0
- package/dist/components/Table/addIndexToObject.d.ts +3 -0
- package/dist/components/Table/addIndexToObject.js +17 -0
- package/dist/components/Table/areProvidedColumnsDifferent.d.ts +2 -0
- package/dist/components/Table/areProvidedColumnsDifferent.js +16 -0
- package/dist/components/Table/hooks/useFetchPage.d.ts +18 -0
- package/dist/components/Table/hooks/useFetchPage.js +123 -0
- package/dist/components/Table/hooks/useGetCellRenderer.d.ts +25 -0
- package/dist/components/Table/hooks/useGetCellRenderer.js +166 -0
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.d.ts +5 -0
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.js +53 -0
- package/dist/components/Table/hooks/useGetDeleteRow.d.ts +9 -0
- package/dist/components/Table/hooks/useGetDeleteRow.js +74 -0
- package/dist/components/Table/hooks/useGetResizeColumn.d.ts +8 -0
- package/dist/components/Table/hooks/useGetResizeColumn.js +28 -0
- package/dist/components/Table/hooks/useGetRowCheckbox.d.ts +5 -0
- package/dist/components/Table/hooks/useGetRowCheckbox.js +54 -0
- package/dist/components/Table/hooks/useLoadDataSource.d.ts +10 -0
- package/dist/components/Table/hooks/useLoadDataSource.js +20 -0
- package/dist/components/Table/hooks/usePageSize.d.ts +5 -0
- package/dist/components/Table/hooks/usePageSize.js +16 -0
- package/dist/components/Table/hooks/useRenderRowActions.d.ts +6 -0
- package/dist/components/Table/hooks/useRenderRowActions.js +51 -0
- package/dist/components/Table/hooks/useResizeColumns.d.ts +9 -0
- package/dist/components/Table/hooks/useResizeColumns.js +60 -0
- package/dist/components/Table/index.d.ts +1 -0
- package/dist/components/Table/index.js +8 -0
- package/dist/components/Table/providers/OrderProvider.d.ts +9 -0
- package/dist/components/Table/providers/OrderProvider.js +17 -0
- package/dist/components/Table/styles.d.ts +6 -0
- package/dist/components/Table/styles.js +37 -0
- package/dist/components/index.js +26 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +8 -0
- package/dist/db_types.d.ts +208 -0
- package/dist/db_types.js +2 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/useApi.d.ts +2 -0
- package/dist/hooks/useApi.js +42 -0
- package/dist/hooks/useEndpoint.d.ts +2 -0
- package/dist/hooks/useEndpoint.js +34 -0
- package/dist/index.js +19 -0
- package/dist/lib/index.js +18 -0
- package/dist/lib/jednostkaNazwa.d.ts +6 -0
- package/dist/lib/jednostkaNazwa.js +9 -0
- package/dist/lib/typDokumentuNazwa.d.ts +6 -0
- package/dist/lib/typDokumentuNazwa.js +11 -0
- package/dist/src/api/Api.js +316 -0
- package/dist/src/api/Endpoint.js +365 -0
- package/dist/src/api/createApi.js +51 -0
- package/dist/src/api/error.js +15 -0
- package/dist/src/api/index.js +5 -0
- package/dist/src/api/status.js +3 -0
- package/dist/src/api/utils/getAlert.js +63 -0
- package/dist/src/api/utils/index.js +1 -0
- package/dist/src/app_types.js +72 -0
- package/dist/src/components/ApiHostProvider.js +11 -0
- package/dist/src/components/StatusTag.js +153 -0
- package/dist/src/components/Table/DataTableWrapper.js +115 -0
- package/dist/src/components/Table/FloatingActions.js +60 -0
- package/dist/src/components/Table/Spinner.js +40 -0
- package/dist/src/components/Table/Summary.js +16 -0
- package/dist/src/components/Table/Table.js +498 -0
- package/dist/src/components/Table/addIndexToObject.js +57 -0
- package/dist/src/components/Table/areProvidedColumnsDifferent.js +19 -0
- package/dist/src/components/Table/clicked.js +12 -0
- package/dist/src/components/Table/displayActions.js +11 -0
- package/dist/src/components/Table/hooks/useFetchPage.js +254 -0
- package/dist/src/components/Table/hooks/useGetCellRenderer.js +231 -0
- package/dist/src/components/Table/hooks/useGetColumnsWithCheckbox.js +33 -0
- package/dist/src/components/Table/hooks/useGetDeleteRow.js +181 -0
- package/dist/src/components/Table/hooks/useGetResizeColumn.js +72 -0
- package/dist/src/components/Table/hooks/useGetRowCheckbox.js +55 -0
- package/dist/src/components/Table/hooks/useLoadDataSource.js +16 -0
- package/dist/src/components/Table/hooks/usePageSize.js +15 -0
- package/dist/src/components/Table/hooks/useRenderRowActions.js +50 -0
- package/dist/src/components/Table/hooks/useResizeColumns.js +70 -0
- package/dist/src/components/Table/index.js +1 -0
- package/dist/src/components/Table/providers/OrderProvider.js +65 -0
- package/dist/src/components/Table/styles.js +66 -0
- package/dist/src/components/index.js +4 -0
- package/dist/src/config.js +6 -0
- package/dist/src/db_types.js +1 -0
- package/dist/src/hooks/index.js +2 -0
- package/dist/src/hooks/useApi.js +84 -0
- package/dist/src/hooks/useEndpoint.js +60 -0
- package/dist/src/index.js +3 -0
- package/dist/src/lib/index.js +2 -0
- package/dist/src/lib/jednostkaNazwa.js +6 -0
- package/dist/src/lib/typDokumentuNazwa.js +16 -0
- package/dist/src/utils/Query.js +73 -0
- package/dist/src/utils/getWZNumber.js +4 -0
- package/dist/src/utils/getZamowienieDokumentNumber.js +4 -0
- package/{src/utils/index.ts → dist/src/utils/index.js} +2 -2
- package/dist/utils/Query.d.ts +6 -0
- package/dist/utils/Query.js +33 -0
- package/dist/utils/getWZNumber.d.ts +2 -0
- package/dist/utils/getWZNumber.js +10 -0
- package/dist/utils/getZamowienieDokumentNumber.d.ts +2 -0
- package/dist/utils/getZamowienieDokumentNumber.js +8 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +12 -0
- package/package.json +3 -2
- package/.eslintrc +0 -6
- package/.nvmrc +0 -1
- package/.prettierrc +0 -11
- package/src/api/Api.ts +0 -140
- package/src/api/Endpoint.ts +0 -76
- package/src/api/createApi.ts +0 -116
- package/src/api/error.ts +0 -17
- package/src/api/status.ts +0 -3
- package/src/api/utils/getAlert.ts +0 -75
- package/src/app_types.ts +0 -695
- package/src/components/ApiHostProvider.tsx +0 -13
- package/src/components/StatusTag.tsx +0 -83
- package/src/components/Table/DataTableWrapper.tsx +0 -28
- package/src/components/Table/FloatingActions.tsx +0 -152
- package/src/components/Table/Spinner.tsx +0 -35
- package/src/components/Table/Summary.tsx +0 -18
- package/src/components/Table/Table.tsx +0 -474
- package/src/components/Table/addIndexToObject.ts +0 -6
- package/src/components/Table/areProvidedColumnsDifferent.ts +0 -26
- package/src/components/Table/clicked.js +0 -12
- package/src/components/Table/displayActions.tsx +0 -19
- package/src/components/Table/hooks/useFetchPage.tsx +0 -83
- package/src/components/Table/hooks/useGetCellRenderer.tsx +0 -197
- package/src/components/Table/hooks/useGetColumnsWithCheckbox.tsx +0 -34
- package/src/components/Table/hooks/useGetDeleteRow.tsx +0 -37
- package/src/components/Table/hooks/useGetResizeColumn.ts +0 -33
- package/src/components/Table/hooks/useGetRowCheckbox.tsx +0 -25
- package/src/components/Table/hooks/useLoadDataSource.ts +0 -24
- package/src/components/Table/hooks/usePageSize.tsx +0 -20
- package/src/components/Table/hooks/useRenderRowActions.tsx +0 -45
- package/src/components/Table/hooks/useResizeColumns.ts +0 -61
- package/src/components/Table/index.ts +0 -1
- package/src/components/Table/providers/OrderProvider.tsx +0 -20
- package/src/components/Table/styles.ts +0 -208
- package/src/config.ts +0 -7
- package/src/db_types.ts +0 -220
- package/src/hooks/useApi.ts +0 -43
- package/src/hooks/useEndpoint.ts +0 -35
- package/src/lib/jednostkaNazwa.ts +0 -6
- package/src/lib/typDokumentuNazwa.ts +0 -8
- package/src/utils/Query.ts +0 -30
- package/src/utils/getWZNumber.ts +0 -13
- package/src/utils/getZamowienieDokumentNumber.ts +0 -11
- package/tsconfig.json +0 -25
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src/api/utils/index.ts → dist/api/utils/index.d.ts} +0 -0
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/hooks/index.ts → dist/hooks/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/lib/index.ts → dist/lib/index.d.ts} +0 -0
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import { Spin, Empty } from 'antd';
|
|
2
|
-
import React, {
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import { useSelector } from 'react-redux';
|
|
10
|
-
import { MultiGrid } from 'react-virtualized';
|
|
11
|
-
import config from '../../config';
|
|
12
|
-
import {
|
|
13
|
-
Actions,
|
|
14
|
-
DataRow,
|
|
15
|
-
TableColumn,
|
|
16
|
-
loadPage as loadPageType,
|
|
17
|
-
State,
|
|
18
|
-
UseData,
|
|
19
|
-
} from '../../app_types';
|
|
20
|
-
import Spinner from './Spinner';
|
|
21
|
-
import useGetRowCheckbox from './hooks/useGetRowCheckbox';
|
|
22
|
-
import useGetCellRenderer from './hooks/useGetCellRenderer';
|
|
23
|
-
import useGetResizeColumn from './hooks/useGetResizeColumn';
|
|
24
|
-
import useRenderRowActions from './hooks/useRenderRowActions';
|
|
25
|
-
import addIndexToObject from './addIndexToObject';
|
|
26
|
-
import useGetColumnsWithCheckbox from './hooks/useGetColumnsWithCheckbox';
|
|
27
|
-
import useDeleteRow from './hooks/useGetDeleteRow';
|
|
28
|
-
import useResizeColumns from './hooks/useResizeColumns';
|
|
29
|
-
import useLoadDataSource from './hooks/useLoadDataSource';
|
|
30
|
-
import areProvidedColumnsDifferent from './areProvidedColumnsDifferent';
|
|
31
|
-
import useFetchPage from './hooks/useFetchPage';
|
|
32
|
-
import FloatingActions from './FloatingActions';
|
|
33
|
-
import DataTableWrapper from './DataTableWrapper';
|
|
34
|
-
import { DataTable, StyledTable } from './styles';
|
|
35
|
-
import { ApiResponse } from '../../api/Api';
|
|
36
|
-
import { usePageSize } from './hooks/usePageSize';
|
|
37
|
-
import { OrderProvider, useOrder } from './providers/OrderProvider';
|
|
38
|
-
|
|
39
|
-
const { ROW_SIZE, ROW_SIZE_MOBILE, MOBILE_BREAKPOINT } = config;
|
|
40
|
-
|
|
41
|
-
const getSearchBarCollapsed = (s: State) => s.searchBarCollapsed;
|
|
42
|
-
|
|
43
|
-
export const MARGIN_FOR_SPINNER = 55;
|
|
44
|
-
|
|
45
|
-
type Props<DataType = DataRow> = {
|
|
46
|
-
idKey?: keyof DataType;
|
|
47
|
-
added?: DataType[];
|
|
48
|
-
style?: React.CSSProperties;
|
|
49
|
-
columns: TableColumn<DataType>[];
|
|
50
|
-
filters?: Record<string, unknown> | undefined;
|
|
51
|
-
actions?: Actions<DataType>;
|
|
52
|
-
loadPage?: loadPageType<DataType>;
|
|
53
|
-
dataSource?: DataType[];
|
|
54
|
-
onDelete?: (row: DataType) => Promise<ApiResponse> | void;
|
|
55
|
-
selected?: number | DataType;
|
|
56
|
-
withCheckbox?: boolean;
|
|
57
|
-
checked?: number[];
|
|
58
|
-
setChecked?: React.Dispatch<React.SetStateAction<number[]>>;
|
|
59
|
-
suspend?: boolean;
|
|
60
|
-
pinned?: DataType[];
|
|
61
|
-
loadingDataSource?: boolean;
|
|
62
|
-
floatingActions?: boolean;
|
|
63
|
-
useData?: UseData<DataType>;
|
|
64
|
-
responsive?: boolean;
|
|
65
|
-
deleteMessage?: (record: DataType) => string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
function BaseTable<DataType extends object = DataRow>({
|
|
69
|
-
style,
|
|
70
|
-
columns: providedColumns,
|
|
71
|
-
filters,
|
|
72
|
-
actions,
|
|
73
|
-
loadPage,
|
|
74
|
-
onDelete,
|
|
75
|
-
added,
|
|
76
|
-
dataSource,
|
|
77
|
-
withCheckbox,
|
|
78
|
-
checked,
|
|
79
|
-
setChecked,
|
|
80
|
-
selected,
|
|
81
|
-
loadingDataSource = false,
|
|
82
|
-
floatingActions,
|
|
83
|
-
suspend,
|
|
84
|
-
pinned,
|
|
85
|
-
useData = useState<DataType[]>,
|
|
86
|
-
responsive,
|
|
87
|
-
deleteMessage,
|
|
88
|
-
idKey,
|
|
89
|
-
}: Props<DataType>): JSX.Element {
|
|
90
|
-
const { order } = useOrder();
|
|
91
|
-
const [rowSize, setRowSize] = useState<number>(ROW_SIZE);
|
|
92
|
-
const main = useRef<HTMLDivElement>(null);
|
|
93
|
-
const table = useRef<HTMLDivElement>(null);
|
|
94
|
-
const grid = useRef<MultiGrid>(null);
|
|
95
|
-
const [listWidth, setListWidth] = useState<number>(
|
|
96
|
-
main.current?.offsetWidth || 0
|
|
97
|
-
);
|
|
98
|
-
const [listHeight, setListHeight] = useState(
|
|
99
|
-
(main.current?.offsetHeight || 0) - rowSize
|
|
100
|
-
);
|
|
101
|
-
const [hoveredRow, setHoveredRow] = useState(); // TODO: is it used anywhere?
|
|
102
|
-
const [data, setData] = useData(
|
|
103
|
-
dataSource?.map(addIndexToObject<DataType>) || undefined
|
|
104
|
-
);
|
|
105
|
-
const [total, setTotal] = useState<number>();
|
|
106
|
-
const [columns, setColumns] = useState(providedColumns);
|
|
107
|
-
const [loading, setLoading] = useState(false);
|
|
108
|
-
const [actionsFor, setActionsFor] = useState<undefined>();
|
|
109
|
-
const [actionsDimensions, setActionsDimensions] = useState({
|
|
110
|
-
top: -20,
|
|
111
|
-
width: 0,
|
|
112
|
-
transition: '',
|
|
113
|
-
});
|
|
114
|
-
const collapsed = useSelector(getSearchBarCollapsed);
|
|
115
|
-
const menuCollapsed = useSelector<State>((state) => state.menuCollapsed);
|
|
116
|
-
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
setLoading(loadingDataSource);
|
|
119
|
-
}, [loadingDataSource]);
|
|
120
|
-
|
|
121
|
-
const deleteRow = useDeleteRow<DataType>({
|
|
122
|
-
deleteMessage,
|
|
123
|
-
onDelete,
|
|
124
|
-
setData,
|
|
125
|
-
data,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const resizeCol = useGetResizeColumn<DataType>({ columns, setColumns });
|
|
129
|
-
|
|
130
|
-
const CellRenderer = useGetCellRenderer<DataType>({
|
|
131
|
-
idKey,
|
|
132
|
-
columns,
|
|
133
|
-
// TODO: improve
|
|
134
|
-
data: data as (DataType & { index: number })[],
|
|
135
|
-
actions,
|
|
136
|
-
resizeCol,
|
|
137
|
-
setHoveredRow,
|
|
138
|
-
hoveredRow,
|
|
139
|
-
selected:
|
|
140
|
-
typeof selected === 'object'
|
|
141
|
-
? (selected as unknown as { id: number })?.id
|
|
142
|
-
: selected, // TODO fix types
|
|
143
|
-
checked,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const RowActions = useRenderRowActions({ data, actions, deleteRow });
|
|
147
|
-
|
|
148
|
-
const getColumnsWithActions = useCallback(
|
|
149
|
-
(updatedColumns) => {
|
|
150
|
-
const newUpdatedColumns = [...updatedColumns];
|
|
151
|
-
|
|
152
|
-
if (newUpdatedColumns[newUpdatedColumns.length - 1].key === 'akcje') {
|
|
153
|
-
newUpdatedColumns[newUpdatedColumns.length - 1] = {
|
|
154
|
-
...newUpdatedColumns[newUpdatedColumns.length - 1],
|
|
155
|
-
render: RowActions,
|
|
156
|
-
};
|
|
157
|
-
} else if (actions.width) {
|
|
158
|
-
newUpdatedColumns.push({
|
|
159
|
-
title: 'Akcja',
|
|
160
|
-
width: actions.width,
|
|
161
|
-
key: 'akcje',
|
|
162
|
-
render: RowActions,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return newUpdatedColumns;
|
|
166
|
-
},
|
|
167
|
-
[RowActions, actions]
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const RowCheckbox = useGetRowCheckbox({
|
|
171
|
-
checked,
|
|
172
|
-
setChecked,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const getColumnsWithCheckbox = useGetColumnsWithCheckbox({
|
|
176
|
-
data,
|
|
177
|
-
checked,
|
|
178
|
-
RowCheckbox,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const addCheckboxAndActions = useCallback(() => {
|
|
182
|
-
let updatedColumns = [...columns];
|
|
183
|
-
if (withCheckbox) {
|
|
184
|
-
updatedColumns = getColumnsWithCheckbox(updatedColumns);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!floatingActions && actions && actions.width) {
|
|
188
|
-
updatedColumns = getColumnsWithActions(updatedColumns);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (withCheckbox || (!floatingActions && actions && actions.width)) {
|
|
192
|
-
// if (JSON.stringify(updatedColumns) !== JSON.stringify(columns)) {
|
|
193
|
-
setColumns(updatedColumns);
|
|
194
|
-
// }
|
|
195
|
-
}
|
|
196
|
-
}, [
|
|
197
|
-
getColumnsWithCheckbox,
|
|
198
|
-
getColumnsWithActions,
|
|
199
|
-
// columns,
|
|
200
|
-
withCheckbox,
|
|
201
|
-
actions,
|
|
202
|
-
floatingActions,
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
useEffect(() => {
|
|
206
|
-
addCheckboxAndActions();
|
|
207
|
-
}, [addCheckboxAndActions, checked, data]);
|
|
208
|
-
|
|
209
|
-
const resizeColumns = useResizeColumns({
|
|
210
|
-
providedColumns,
|
|
211
|
-
columns,
|
|
212
|
-
main,
|
|
213
|
-
floatingActions,
|
|
214
|
-
actions,
|
|
215
|
-
setColumns,
|
|
216
|
-
grid,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
useEffect(() => {
|
|
220
|
-
resizeColumns();
|
|
221
|
-
}, [resizeColumns, columns, collapsed, menuCollapsed, listWidth, listHeight]);
|
|
222
|
-
|
|
223
|
-
useEffect(() => {
|
|
224
|
-
setListHeight(main.current?.offsetHeight || 0 - rowSize);
|
|
225
|
-
}, [collapsed]);
|
|
226
|
-
|
|
227
|
-
const pageSize = usePageSize({ mainRef: main, rowSize });
|
|
228
|
-
|
|
229
|
-
const handleResize = useCallback(() => {
|
|
230
|
-
if (main.current) {
|
|
231
|
-
if (responsive) {
|
|
232
|
-
setRowSize(
|
|
233
|
-
main.current.offsetWidth < MOBILE_BREAKPOINT
|
|
234
|
-
? ROW_SIZE_MOBILE
|
|
235
|
-
: ROW_SIZE
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
setListWidth(main.current.offsetWidth);
|
|
239
|
-
setListHeight(main.current.offsetHeight - rowSize);
|
|
240
|
-
}
|
|
241
|
-
}, [main]);
|
|
242
|
-
|
|
243
|
-
useEffect(() => {
|
|
244
|
-
handleResize();
|
|
245
|
-
}, [handleResize, menuCollapsed]);
|
|
246
|
-
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
if (main.current) {
|
|
249
|
-
if (responsive) {
|
|
250
|
-
setRowSize(
|
|
251
|
-
main.current.offsetWidth < MOBILE_BREAKPOINT
|
|
252
|
-
? ROW_SIZE_MOBILE
|
|
253
|
-
: ROW_SIZE
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
setListWidth(main.current.offsetWidth);
|
|
257
|
-
setListHeight(main.current.offsetHeight - rowSize);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
window.removeEventListener('resize', handleResize);
|
|
261
|
-
window.addEventListener('resize', handleResize);
|
|
262
|
-
return () => window.removeEventListener('resize', handleResize);
|
|
263
|
-
}, [handleResize]);
|
|
264
|
-
|
|
265
|
-
useEffect(() => {
|
|
266
|
-
if (areProvidedColumnsDifferent(providedColumns, columns)) {
|
|
267
|
-
setColumns(providedColumns);
|
|
268
|
-
}
|
|
269
|
-
}, [providedColumns, columns]);
|
|
270
|
-
|
|
271
|
-
const floatingButtons = useMemo(() => {
|
|
272
|
-
if (actions) {
|
|
273
|
-
return [...(actions.floatingOnly || []), ...(actions.buttons || [])];
|
|
274
|
-
}
|
|
275
|
-
return undefined;
|
|
276
|
-
}, [actions]);
|
|
277
|
-
|
|
278
|
-
const fetchPage = useFetchPage({
|
|
279
|
-
suspend,
|
|
280
|
-
setLoading,
|
|
281
|
-
pageSize,
|
|
282
|
-
loadPage,
|
|
283
|
-
filters,
|
|
284
|
-
// TODO: improve
|
|
285
|
-
data: data as (DataType & { index: number })[],
|
|
286
|
-
pinned,
|
|
287
|
-
setData,
|
|
288
|
-
setTotal,
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
useLoadDataSource({
|
|
292
|
-
filters,
|
|
293
|
-
added,
|
|
294
|
-
data,
|
|
295
|
-
dataSource,
|
|
296
|
-
setData,
|
|
297
|
-
fetchPage,
|
|
298
|
-
pageSize,
|
|
299
|
-
loadPage,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
const hide = useCallback(
|
|
303
|
-
(e?: MouseEvent) => {
|
|
304
|
-
if (!actionsFor) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
if (e) {
|
|
308
|
-
e.stopPropagation();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
setActionsFor(undefined);
|
|
312
|
-
setActionsDimensions({
|
|
313
|
-
...actionsDimensions,
|
|
314
|
-
width: 0,
|
|
315
|
-
transition: '',
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
[actionsFor, actionsDimensions]
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
const scrolled = useCallback(
|
|
322
|
-
({ scrollTop, clientHeight }) => {
|
|
323
|
-
if (actionsFor) {
|
|
324
|
-
hide();
|
|
325
|
-
}
|
|
326
|
-
if (dataSource !== undefined || loading || data.length === total) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const page = Math.ceil(
|
|
331
|
-
(data.length - (pinned?.length || 0)) / pageSize()
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
if (scrollTop < clientHeight * (page - 1)) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
fetchPage(page);
|
|
339
|
-
},
|
|
340
|
-
[
|
|
341
|
-
fetchPage,
|
|
342
|
-
actionsFor,
|
|
343
|
-
dataSource,
|
|
344
|
-
data,
|
|
345
|
-
loading,
|
|
346
|
-
total,
|
|
347
|
-
pageSize,
|
|
348
|
-
hide,
|
|
349
|
-
pinned?.length,
|
|
350
|
-
]
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
useEffect(() => {
|
|
354
|
-
if (loadPage !== undefined) {
|
|
355
|
-
fetchPage(0);
|
|
356
|
-
}
|
|
357
|
-
}, [order]);
|
|
358
|
-
|
|
359
|
-
useEffect(() => {
|
|
360
|
-
window.addEventListener('click', hide);
|
|
361
|
-
|
|
362
|
-
return () => window.removeEventListener('click', hide);
|
|
363
|
-
}, [hide, actionsFor, actionsDimensions]);
|
|
364
|
-
|
|
365
|
-
const actionHover = useCallback(() => {
|
|
366
|
-
if (Array.isArray(floatingButtons)) {
|
|
367
|
-
setActionsDimensions({
|
|
368
|
-
...actionsDimensions,
|
|
369
|
-
width:
|
|
370
|
-
floatingButtons.length * 24 +
|
|
371
|
-
(floatingButtons.length - 1) * 28 +
|
|
372
|
-
(actions.delete ? 53 : 0) +
|
|
373
|
-
98 +
|
|
374
|
-
(actions.additionalWidth || 0),
|
|
375
|
-
transition: 'width 150ms ease-in-out',
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}, [actionsDimensions, floatingButtons, actions]);
|
|
379
|
-
|
|
380
|
-
const actionLeave = useCallback(() => {
|
|
381
|
-
if (Array.isArray(floatingButtons) && actionsFor) {
|
|
382
|
-
setActionsDimensions({
|
|
383
|
-
...actionsDimensions,
|
|
384
|
-
width:
|
|
385
|
-
floatingButtons.length * 24 +
|
|
386
|
-
(floatingButtons.length - 1) * 28 +
|
|
387
|
-
(actions.delete ? 53 : 0) +
|
|
388
|
-
74,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
}, [actionsFor, actionsDimensions, floatingButtons, actions]);
|
|
392
|
-
|
|
393
|
-
const isVisibleCellRenderer = useCallback(
|
|
394
|
-
({
|
|
395
|
-
columnIndex,
|
|
396
|
-
key,
|
|
397
|
-
rowIndex,
|
|
398
|
-
style: cellStyle,
|
|
399
|
-
isVisible,
|
|
400
|
-
isScrolling,
|
|
401
|
-
}) => {
|
|
402
|
-
if (isVisible) {
|
|
403
|
-
return (
|
|
404
|
-
<CellRenderer
|
|
405
|
-
isVisible={isVisible}
|
|
406
|
-
columnIndex={columnIndex}
|
|
407
|
-
key={key}
|
|
408
|
-
rowKey={key}
|
|
409
|
-
rowIndex={rowIndex}
|
|
410
|
-
isScrolling={isScrolling}
|
|
411
|
-
style={cellStyle}
|
|
412
|
-
/>
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
return null;
|
|
416
|
-
},
|
|
417
|
-
[CellRenderer]
|
|
418
|
-
);
|
|
419
|
-
return (
|
|
420
|
-
<DataTable style={style} className="data-table" ref={main}>
|
|
421
|
-
{(actions?.both || floatingActions) && actions ? (
|
|
422
|
-
<FloatingActions<DataType>
|
|
423
|
-
actionsDimensions={actionsDimensions}
|
|
424
|
-
actionsFor={actionsFor}
|
|
425
|
-
floatingButtons={floatingButtons}
|
|
426
|
-
actionHover={actionHover}
|
|
427
|
-
actionLeave={actionLeave}
|
|
428
|
-
hide={hide}
|
|
429
|
-
actions={actions}
|
|
430
|
-
/>
|
|
431
|
-
) : undefined}
|
|
432
|
-
|
|
433
|
-
<DataTableWrapper>
|
|
434
|
-
<StyledTable className="table" ref={table}>
|
|
435
|
-
{data && (
|
|
436
|
-
<MultiGrid
|
|
437
|
-
cellRenderer={isVisibleCellRenderer}
|
|
438
|
-
height={listHeight}
|
|
439
|
-
width={listWidth}
|
|
440
|
-
columnWidth={({ index }) => columns[index].width}
|
|
441
|
-
rowHeight={rowSize}
|
|
442
|
-
fixedRowCount={1}
|
|
443
|
-
columnCount={columns.length}
|
|
444
|
-
rowCount={data.length + 1}
|
|
445
|
-
overscanRowCount={22}
|
|
446
|
-
styleBottomLeftGrid={{ outline: 'none' }}
|
|
447
|
-
styleBottomRightGrid={{ outline: 'none' }}
|
|
448
|
-
onScroll={scrolled}
|
|
449
|
-
ref={grid}
|
|
450
|
-
/>
|
|
451
|
-
)}
|
|
452
|
-
</StyledTable>
|
|
453
|
-
|
|
454
|
-
{data && loading ? <Spinner /> : undefined}
|
|
455
|
-
</DataTableWrapper>
|
|
456
|
-
{/* <div className="data-table-wrapper" ref={wrapper} /> */}
|
|
457
|
-
{!data ? (
|
|
458
|
-
<div className="data-table-no-data">
|
|
459
|
-
{loading ? <Spin /> : <Empty description="Brak danych" />}
|
|
460
|
-
</div>
|
|
461
|
-
) : undefined}
|
|
462
|
-
</DataTable>
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function Table<DataType extends object = DataRow>(props: Props<DataType>) {
|
|
467
|
-
return (
|
|
468
|
-
<OrderProvider>
|
|
469
|
-
<BaseTable<DataType> {...props} />
|
|
470
|
-
</OrderProvider>
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
export default Table;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { DataRow, TableColumn } from '../../app_types';
|
|
2
|
-
|
|
3
|
-
export default function areProvidedColumnsDifferent<DataType = DataRow>(
|
|
4
|
-
providedColumns: TableColumn<DataType>[],
|
|
5
|
-
currentColumns: TableColumn<DataType>[]
|
|
6
|
-
) {
|
|
7
|
-
const providedKeys = providedColumns.map((c) => String(c.key).toLowerCase());
|
|
8
|
-
const currentKeys = currentColumns.map((c) => String(c.key).toLowerCase());
|
|
9
|
-
const currentHasActions = currentKeys.includes('akcje');
|
|
10
|
-
const providedHasActions = providedKeys.includes('akcje');
|
|
11
|
-
|
|
12
|
-
const currentHasCheckbox = currentKeys.includes('checkbox');
|
|
13
|
-
const providedHasCheckbox = providedKeys.includes('checkbox');
|
|
14
|
-
|
|
15
|
-
const providedKeysWithAdditional = providedKeys.concat(
|
|
16
|
-
currentHasActions && !providedHasActions ? ['akcje'] : []
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
if (currentHasCheckbox && !providedHasCheckbox) {
|
|
20
|
-
providedKeysWithAdditional.unshift('checkbox');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
JSON.stringify(providedKeysWithAdditional) !== JSON.stringify(currentKeys)
|
|
25
|
-
);
|
|
26
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { displayActions } from './displayActions';
|
|
2
|
-
|
|
3
|
-
const clicked = (e, row, type) => {
|
|
4
|
-
if (type === 0) {
|
|
5
|
-
// Left-click
|
|
6
|
-
if (actionsFor) hide();
|
|
7
|
-
else if (withCheckbox) onChecked(row, checked.indexOf(row) === -1);
|
|
8
|
-
} else if (type === 1) {
|
|
9
|
-
// Right-click
|
|
10
|
-
if (actions?.both || floatingActions) displayActions(e, row);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// TODO: remove?
|
|
2
|
-
import { ROW_SIZE } from './index';
|
|
3
|
-
|
|
4
|
-
export default function displayActions(e, row) {
|
|
5
|
-
if (actionsFor) e.stopPropagation();
|
|
6
|
-
|
|
7
|
-
setActionsFor(row);
|
|
8
|
-
setActionsDimensions({
|
|
9
|
-
top:
|
|
10
|
-
(data ? (ROW_SIZE + 1) * data.indexOf(row) - 50 : -50) -
|
|
11
|
-
wrapper.current.scrollTop,
|
|
12
|
-
width:
|
|
13
|
-
floatingButtons.length * 24 +
|
|
14
|
-
(floatingButtons.length - 1) * 28 +
|
|
15
|
-
(actions.delete ? 53 : 0) +
|
|
16
|
-
74,
|
|
17
|
-
transition: actionsFor ? 'top 150ms ease-in-out' : undefined,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { message } from 'antd';
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
3
|
-
import addIndexToObject from '../addIndexToObject';
|
|
4
|
-
import { useOrder } from '../providers/OrderProvider';
|
|
5
|
-
import { loadPage as loadPageType } from '../../../app_types';
|
|
6
|
-
|
|
7
|
-
type Props<DataType extends object> = {
|
|
8
|
-
suspend?: boolean;
|
|
9
|
-
setLoading?: (v: boolean) => void;
|
|
10
|
-
pageSize: () => number;
|
|
11
|
-
loadPage?: loadPageType<DataType>;
|
|
12
|
-
filters;
|
|
13
|
-
data: (DataType & { index: number })[];
|
|
14
|
-
pinned: DataType[];
|
|
15
|
-
setData: (rows: (DataType & { index: number })[]) => void;
|
|
16
|
-
setTotal: (total: number) => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default function useFetchPage<DataType extends object>({
|
|
20
|
-
suspend,
|
|
21
|
-
setLoading,
|
|
22
|
-
pageSize,
|
|
23
|
-
loadPage,
|
|
24
|
-
filters,
|
|
25
|
-
data,
|
|
26
|
-
pinned,
|
|
27
|
-
setData,
|
|
28
|
-
setTotal,
|
|
29
|
-
}: Props<DataType>) {
|
|
30
|
-
const { order } = useOrder();
|
|
31
|
-
|
|
32
|
-
return useCallback(
|
|
33
|
-
async (page: number, size?: number) => {
|
|
34
|
-
if (typeof suspend === 'boolean' && suspend) {
|
|
35
|
-
setLoading(false);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (size === undefined) {
|
|
40
|
-
size = pageSize();
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
setLoading(true);
|
|
44
|
-
const loaded = await loadPage(page, size, filters, order);
|
|
45
|
-
let newData;
|
|
46
|
-
if (page !== 0) {
|
|
47
|
-
newData = [...(data || []), ...loaded.data];
|
|
48
|
-
} else {
|
|
49
|
-
newData = loaded.data || [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (Array.isArray(pinned)) {
|
|
53
|
-
pinned.forEach((pinnedEl, pinnedIdx) => {
|
|
54
|
-
const indexes = newData
|
|
55
|
-
.map(({ id }, index) => ({ id, index }))
|
|
56
|
-
// TODO fix
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
.filter((el) => el.id === pinnedEl.id)
|
|
59
|
-
.map(({ index }) => index);
|
|
60
|
-
|
|
61
|
-
indexes.forEach((index) => {
|
|
62
|
-
if (index !== pinnedIdx) {
|
|
63
|
-
newData.splice(index, 1);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (!indexes.includes(pinnedIdx)) {
|
|
68
|
-
newData.unshift(pinnedEl);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setData(newData.map(addIndexToObject));
|
|
74
|
-
setTotal(loaded.total);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
message.error(`${e}`);
|
|
77
|
-
} finally {
|
|
78
|
-
setLoading(false);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[suspend, pageSize, loadPage, filters, data, order]
|
|
82
|
-
);
|
|
83
|
-
}
|