@ercioko/meblotex-api 0.2.0 → 0.2.2
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/.eslintrc +6 -0
- package/.nvmrc +1 -0
- package/.prettierrc +11 -0
- package/package.json +5 -16
- package/src/api/Api.ts +140 -0
- package/src/api/Endpoint.ts +76 -0
- package/src/api/createApi.ts +116 -0
- package/src/api/error.ts +17 -0
- package/{dist/api/index.d.ts → src/api/index.ts} +1 -0
- package/src/api/status.ts +3 -0
- package/src/api/utils/getAlert.ts +75 -0
- package/src/app_types.ts +695 -0
- package/src/components/ApiHostProvider.tsx +13 -0
- package/src/components/StatusTag.tsx +83 -0
- package/src/components/Table/DataTableWrapper.tsx +28 -0
- package/src/components/Table/FloatingActions.tsx +152 -0
- package/src/components/Table/Spinner.tsx +35 -0
- package/src/components/Table/Summary.tsx +18 -0
- package/src/components/Table/Table.tsx +474 -0
- package/src/components/Table/addIndexToObject.ts +6 -0
- package/src/components/Table/areProvidedColumnsDifferent.ts +26 -0
- package/src/components/Table/clicked.js +12 -0
- package/src/components/Table/displayActions.tsx +19 -0
- package/src/components/Table/hooks/useFetchPage.tsx +83 -0
- package/src/components/Table/hooks/useGetCellRenderer.tsx +197 -0
- package/src/components/Table/hooks/useGetColumnsWithCheckbox.tsx +34 -0
- package/src/components/Table/hooks/useGetDeleteRow.tsx +37 -0
- package/src/components/Table/hooks/useGetResizeColumn.ts +33 -0
- package/src/components/Table/hooks/useGetRowCheckbox.tsx +25 -0
- package/src/components/Table/hooks/useLoadDataSource.ts +24 -0
- package/src/components/Table/hooks/usePageSize.tsx +20 -0
- package/src/components/Table/hooks/useRenderRowActions.tsx +45 -0
- package/src/components/Table/hooks/useResizeColumns.ts +61 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/providers/OrderProvider.tsx +20 -0
- package/src/components/Table/styles.ts +208 -0
- package/src/config.ts +7 -0
- package/src/db_types.ts +220 -0
- package/src/hooks/useApi.ts +43 -0
- package/src/hooks/useEndpoint.ts +35 -0
- package/src/lib/jednostkaNazwa.ts +6 -0
- package/src/lib/typDokumentuNazwa.ts +8 -0
- package/src/utils/Query.ts +30 -0
- package/src/utils/getWZNumber.ts +13 -0
- package/src/utils/getZamowienieDokumentNumber.ts +11 -0
- package/{dist/src/utils/index.js → src/utils/index.ts} +2 -2
- package/tsconfig.json +25 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/api/Api.d.ts +0 -33
- package/dist/api/Api.js +0 -152
- package/dist/api/Endpoint.d.ts +0 -13
- package/dist/api/Endpoint.js +0 -126
- package/dist/api/createApi.d.ts +0 -52
- package/dist/api/createApi.js +0 -81
- package/dist/api/error.d.ts +0 -15
- package/dist/api/error.js +0 -18
- package/dist/api/index.js +0 -34
- package/dist/api/status.d.ts +0 -3
- package/dist/api/status.js +0 -6
- package/dist/api/utils/getAlert.d.ts +0 -6
- package/dist/api/utils/getAlert.js +0 -65
- package/dist/api/utils/index.js +0 -8
- package/dist/app_types.d.ts +0 -607
- package/dist/app_types.js +0 -75
- package/dist/components/ApiHostProvider.d.ts +0 -7
- package/dist/components/ApiHostProvider.js +0 -35
- package/dist/components/StatusTag.d.ts +0 -11
- package/dist/components/StatusTag.js +0 -86
- package/dist/components/Table/DataTableWrapper.d.ts +0 -3
- package/dist/components/Table/DataTableWrapper.js +0 -44
- package/dist/components/Table/FloatingActions.d.ts +0 -14
- package/dist/components/Table/FloatingActions.js +0 -32
- package/dist/components/Table/Spinner.d.ts +0 -2
- package/dist/components/Table/Spinner.js +0 -26
- package/dist/components/Table/Summary.js +0 -16
- package/dist/components/Table/Table.d.ts +0 -28
- package/dist/components/Table/Table.js +0 -330
- package/dist/components/Table/addIndexToObject.d.ts +0 -3
- package/dist/components/Table/addIndexToObject.js +0 -17
- package/dist/components/Table/areProvidedColumnsDifferent.d.ts +0 -2
- package/dist/components/Table/areProvidedColumnsDifferent.js +0 -16
- package/dist/components/Table/clicked.js +0 -11
- package/dist/components/Table/displayActions.js +0 -11
- package/dist/components/Table/hooks/useFetchPage.d.ts +0 -18
- package/dist/components/Table/hooks/useFetchPage.js +0 -123
- package/dist/components/Table/hooks/useGetCellRenderer.d.ts +0 -25
- package/dist/components/Table/hooks/useGetCellRenderer.js +0 -166
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.d.ts +0 -5
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -53
- package/dist/components/Table/hooks/useGetDeleteRow.d.ts +0 -9
- package/dist/components/Table/hooks/useGetDeleteRow.js +0 -74
- package/dist/components/Table/hooks/useGetResizeColumn.d.ts +0 -8
- package/dist/components/Table/hooks/useGetResizeColumn.js +0 -28
- package/dist/components/Table/hooks/useGetRowCheckbox.d.ts +0 -5
- package/dist/components/Table/hooks/useGetRowCheckbox.js +0 -54
- package/dist/components/Table/hooks/useLoadDataSource.d.ts +0 -10
- package/dist/components/Table/hooks/useLoadDataSource.js +0 -20
- package/dist/components/Table/hooks/usePageSize.d.ts +0 -5
- package/dist/components/Table/hooks/usePageSize.js +0 -16
- package/dist/components/Table/hooks/useRenderRowActions.d.ts +0 -6
- package/dist/components/Table/hooks/useRenderRowActions.js +0 -51
- package/dist/components/Table/hooks/useResizeColumns.d.ts +0 -9
- package/dist/components/Table/hooks/useResizeColumns.js +0 -60
- package/dist/components/Table/index.d.ts +0 -1
- package/dist/components/Table/index.js +0 -8
- package/dist/components/Table/providers/OrderProvider.d.ts +0 -9
- package/dist/components/Table/providers/OrderProvider.js +0 -17
- package/dist/components/Table/styles.d.ts +0 -6
- package/dist/components/Table/styles.js +0 -37
- package/dist/components/index.js +0 -26
- package/dist/config.d.ts +0 -6
- package/dist/config.js +0 -8
- package/dist/db_types.d.ts +0 -208
- package/dist/db_types.js +0 -2
- package/dist/hooks/index.js +0 -10
- package/dist/hooks/useApi.d.ts +0 -2
- package/dist/hooks/useApi.js +0 -42
- package/dist/hooks/useEndpoint.d.ts +0 -2
- package/dist/hooks/useEndpoint.js +0 -34
- package/dist/index.js +0 -19
- package/dist/lib/index.js +0 -18
- package/dist/lib/jednostka.d.ts +0 -6
- package/dist/lib/jednostkaNazwa.d.ts +0 -6
- package/dist/lib/jednostkaNazwa.js +0 -9
- package/dist/lib/typDokumentuNazwa.d.ts +0 -6
- package/dist/lib/typDokumentuNazwa.js +0 -11
- package/dist/lib/typ_dokument.d.ts +0 -0
- package/dist/lib/typ_dokumentu.d.ts +0 -6
- package/dist/lib/unit.d.ts +0 -0
- package/dist/src/api/Api.js +0 -316
- package/dist/src/api/Endpoint.js +0 -365
- package/dist/src/api/createApi.js +0 -50
- package/dist/src/api/error.js +0 -15
- package/dist/src/api/index.js +0 -5
- package/dist/src/api/status.js +0 -3
- package/dist/src/api/utils/getAlert.js +0 -63
- package/dist/src/api/utils/index.js +0 -1
- package/dist/src/app_types.js +0 -72
- package/dist/src/components/ApiHostProvider.js +0 -11
- package/dist/src/components/StatusTag.js +0 -153
- package/dist/src/components/Table/DataTableWrapper.js +0 -115
- package/dist/src/components/Table/FloatingActions.js +0 -60
- package/dist/src/components/Table/Spinner.js +0 -40
- package/dist/src/components/Table/Summary.js +0 -16
- package/dist/src/components/Table/Table.js +0 -498
- package/dist/src/components/Table/addIndexToObject.js +0 -57
- package/dist/src/components/Table/areProvidedColumnsDifferent.js +0 -19
- package/dist/src/components/Table/clicked.js +0 -12
- package/dist/src/components/Table/displayActions.js +0 -11
- package/dist/src/components/Table/hooks/useFetchPage.js +0 -254
- package/dist/src/components/Table/hooks/useGetCellRenderer.js +0 -231
- package/dist/src/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -33
- package/dist/src/components/Table/hooks/useGetDeleteRow.js +0 -181
- package/dist/src/components/Table/hooks/useGetResizeColumn.js +0 -72
- package/dist/src/components/Table/hooks/useGetRowCheckbox.js +0 -55
- package/dist/src/components/Table/hooks/useLoadDataSource.js +0 -16
- package/dist/src/components/Table/hooks/usePageSize.js +0 -15
- package/dist/src/components/Table/hooks/useRenderRowActions.js +0 -50
- package/dist/src/components/Table/hooks/useResizeColumns.js +0 -70
- package/dist/src/components/Table/index.js +0 -1
- package/dist/src/components/Table/providers/OrderProvider.js +0 -65
- package/dist/src/components/Table/styles.js +0 -66
- package/dist/src/components/index.js +0 -4
- package/dist/src/config.js +0 -6
- package/dist/src/db_types.js +0 -1
- package/dist/src/hooks/index.js +0 -2
- package/dist/src/hooks/useApi.js +0 -84
- package/dist/src/hooks/useEndpoint.js +0 -60
- package/dist/src/index.js +0 -3
- package/dist/src/lib/index.js +0 -2
- package/dist/src/lib/jednostkaNazwa.js +0 -6
- package/dist/src/lib/typDokumentuNazwa.js +0 -16
- package/dist/src/utils/Query.js +0 -73
- package/dist/src/utils/getWZNumber.js +0 -4
- package/dist/src/utils/getZamowienieDokumentNumber.js +0 -4
- package/dist/utils/AlertContext.d.ts +0 -3
- package/dist/utils/AlertContext.js +0 -3
- package/dist/utils/Query.d.ts +0 -6
- package/dist/utils/Query.js +0 -33
- package/dist/utils/geNumber.d.ts +0 -2
- package/dist/utils/getDocNumber.d.ts +0 -2
- package/dist/utils/getWZNumber.js +0 -10
- package/dist/utils/getWzNumber.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber copy.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber.js +0 -8
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -12
- /package/{dist/api/utils/index.d.ts → src/api/utils/index.ts} +0 -0
- /package/{dist/components/index.d.ts → src/components/index.ts} +0 -0
- /package/{dist/hooks/index.d.ts → src/hooks/index.ts} +0 -0
- /package/{dist/index.d.ts → src/index.ts} +0 -0
- /package/{dist/lib/index.d.ts → src/lib/index.ts} +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import React, { useCallback, useContext } from 'react';
|
|
2
|
+
import Draggable from 'react-draggable';
|
|
3
|
+
import { Actions, DataRow, TableColumn, TableColumnKey } from '../../../app_types';
|
|
4
|
+
import { useOrder } from '../providers/OrderProvider';
|
|
5
|
+
import { TableData, TableHeader } from '../styles';
|
|
6
|
+
import { ResizeColumnType } from './useGetResizeColumn';
|
|
7
|
+
|
|
8
|
+
type Props<DataType = DataRow> = {
|
|
9
|
+
idKey?: keyof DataType;
|
|
10
|
+
columns: TableColumn<DataType>[];
|
|
11
|
+
data?: (DataType & { index: number })[];
|
|
12
|
+
actions: Actions<DataType>;
|
|
13
|
+
resizeCol: ResizeColumnType;
|
|
14
|
+
setHoveredRow: (prev: unknown) => void;
|
|
15
|
+
hoveredRow: undefined;
|
|
16
|
+
selected: number | DataType;
|
|
17
|
+
checked: number[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const isKeyInRow = <DataType,>(key: TableColumnKey<DataType>, row: DataType & { index: number }): key is keyof DataType | 'index' => key in row;
|
|
21
|
+
|
|
22
|
+
export default function useGetCellRenderer<DataType extends object>({
|
|
23
|
+
columns,
|
|
24
|
+
data,
|
|
25
|
+
actions,
|
|
26
|
+
resizeCol,
|
|
27
|
+
setHoveredRow,
|
|
28
|
+
hoveredRow,
|
|
29
|
+
selected,
|
|
30
|
+
checked,
|
|
31
|
+
idKey,
|
|
32
|
+
}: Props<DataType>) {
|
|
33
|
+
const { order, setOrder } = useOrder();
|
|
34
|
+
|
|
35
|
+
const sortByColumn = useCallback(
|
|
36
|
+
({ orderNested, key }: TableColumn<DataType>) => {
|
|
37
|
+
if (key === 'akcje') {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(orderNested)) {
|
|
42
|
+
setOrder([
|
|
43
|
+
...orderNested,
|
|
44
|
+
Array.isArray(order) &&
|
|
45
|
+
order[0] === orderNested[0] &&
|
|
46
|
+
order[1] === orderNested[1] &&
|
|
47
|
+
order[2] === 'ASC'
|
|
48
|
+
? 'DESC'
|
|
49
|
+
: 'ASC',
|
|
50
|
+
]);
|
|
51
|
+
} else if (data && key as string in data[0]) {
|
|
52
|
+
setOrder([
|
|
53
|
+
key as string,
|
|
54
|
+
Array.isArray(order) && order[0] === key && order[1] === 'ASC'
|
|
55
|
+
? 'DESC'
|
|
56
|
+
: 'ASC',
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[order, setOrder, data]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const getBackgroundColor = useCallback(
|
|
64
|
+
(rowIndex: number) => {
|
|
65
|
+
const row = data[rowIndex - 1];
|
|
66
|
+
const dataIdKey = 'id' in row ? ('id' as keyof DataType) : idKey;
|
|
67
|
+
const hasId = typeof row?.[dataIdKey] !== 'undefined';
|
|
68
|
+
/// TODO: fix selected types
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
const isSelectedSingle = selected === row?.[dataIdKey] && hasId;
|
|
71
|
+
if (isSelectedSingle) {
|
|
72
|
+
return '#bae7ff';
|
|
73
|
+
}
|
|
74
|
+
if (typeof checked === 'undefined') {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (row && 'index' in row) {
|
|
79
|
+
const isSelected = checked.includes(row.index);
|
|
80
|
+
if (actions?.onRowClick && hoveredRow === rowIndex && !isSelected) {
|
|
81
|
+
return '#AAA';
|
|
82
|
+
}
|
|
83
|
+
if (isSelected) {
|
|
84
|
+
return '#bae7ff';
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[checked, actions, data]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const handleOnClick = useCallback(
|
|
93
|
+
(rowIndex) => (e) => {
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
actions?.onRowClick(data[rowIndex - 1]);
|
|
96
|
+
},
|
|
97
|
+
[actions, data]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return useCallback(
|
|
101
|
+
({ columnIndex, rowIndex, rowKey, style, isScrolling, isVisible }) => {
|
|
102
|
+
// const hoverRow = useCallback(
|
|
103
|
+
// (rowIndex) => () => {
|
|
104
|
+
// setHoveredRow(rowIndex);
|
|
105
|
+
// },
|
|
106
|
+
// [setHoveredRow]
|
|
107
|
+
// );
|
|
108
|
+
// const blurRow = useCallback(() => setHoveredRow(), []);
|
|
109
|
+
|
|
110
|
+
const colCfg = columns[columnIndex];
|
|
111
|
+
|
|
112
|
+
let value: DataType[keyof DataType] | number;
|
|
113
|
+
const row = data[rowIndex - 1];
|
|
114
|
+
if (row && isKeyInRow(colCfg.key, row)) {
|
|
115
|
+
value = rowIndex !== 0 ? row[colCfg.key] : undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (rowIndex === 0) {
|
|
119
|
+
return (
|
|
120
|
+
<TableHeader
|
|
121
|
+
key={rowKey}
|
|
122
|
+
style={{ ...style, display: 'flex', alignItems: 'center' }}
|
|
123
|
+
className="td th"
|
|
124
|
+
onClick={() => sortByColumn(colCfg)}
|
|
125
|
+
>
|
|
126
|
+
<div
|
|
127
|
+
className={`text-nowrap w-100${colCfg.resized ? ' resized' : ''}`}
|
|
128
|
+
>
|
|
129
|
+
{colCfg.title}
|
|
130
|
+
</div>
|
|
131
|
+
<Draggable
|
|
132
|
+
axis="x"
|
|
133
|
+
defaultClassName="DragHandle"
|
|
134
|
+
defaultClassNameDragging="DragHandleActive"
|
|
135
|
+
onDrag={(e, { deltaX }) => resizeCol(columnIndex, deltaX)}
|
|
136
|
+
position={{ x: 0, y: undefined }}
|
|
137
|
+
// TODO zindex?
|
|
138
|
+
>
|
|
139
|
+
<div className="DragHandleIcon">⋮</div>
|
|
140
|
+
</Draggable>
|
|
141
|
+
</TableHeader>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const clickable = actions?.onRowClick && colCfg.key !== 'akcje';
|
|
146
|
+
const divProps = colCfg.resized
|
|
147
|
+
? { className: 'td resized' }
|
|
148
|
+
: { className: 'td' };
|
|
149
|
+
|
|
150
|
+
let content: number | string | JSX.Element | DataType[keyof DataType] = value;
|
|
151
|
+
if (isScrolling && colCfg.lightRender) {
|
|
152
|
+
// TODO: improve
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
content = colCfg.lightRender(value, data[rowIndex - 1], rowIndex);
|
|
155
|
+
} else if (colCfg.render) {
|
|
156
|
+
// TODO: improve
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
content = colCfg.render(value, data[rowIndex - 1], rowIndex);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<TableData
|
|
163
|
+
// onMouseOver={hoverRow(rowIndex)} // TODO: is it useful?
|
|
164
|
+
// onMouseLeave={blurRow}
|
|
165
|
+
$align={colCfg.align}
|
|
166
|
+
role="button"
|
|
167
|
+
key={rowKey}
|
|
168
|
+
style={{
|
|
169
|
+
...style,
|
|
170
|
+
cursor: clickable ? 'pointer' : undefined,
|
|
171
|
+
backgroundColor: getBackgroundColor(rowIndex),
|
|
172
|
+
color:
|
|
173
|
+
actions?.onRowClick && hoveredRow === rowIndex
|
|
174
|
+
? 'black'
|
|
175
|
+
: undefined,
|
|
176
|
+
}}
|
|
177
|
+
{...divProps}
|
|
178
|
+
className={`tr td ${(rowIndex - 1) % 2 === 0 ? 'td-light' : ''}`}
|
|
179
|
+
onClick={clickable ? handleOnClick(rowIndex) : null}
|
|
180
|
+
>
|
|
181
|
+
{content as React.ReactNode}
|
|
182
|
+
</TableData>
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
[
|
|
186
|
+
columns,
|
|
187
|
+
data,
|
|
188
|
+
actions,
|
|
189
|
+
resizeCol,
|
|
190
|
+
setHoveredRow,
|
|
191
|
+
hoveredRow,
|
|
192
|
+
selected,
|
|
193
|
+
checked,
|
|
194
|
+
sortByColumn,
|
|
195
|
+
]
|
|
196
|
+
);
|
|
197
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Checkbox } from 'antd';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
export default function useGetColumnsWithCheckbox({
|
|
5
|
+
checked,
|
|
6
|
+
data,
|
|
7
|
+
RowCheckbox,
|
|
8
|
+
}) {
|
|
9
|
+
return useCallback(
|
|
10
|
+
function getColumnsWithCheckbox(updatedColumns) {
|
|
11
|
+
const checkboxColumn = getCheckboxColumn({
|
|
12
|
+
allChecked: data?.length === checked?.length,
|
|
13
|
+
RowCheckbox,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (updatedColumns[0].key === 'checkbox') {
|
|
17
|
+
updatedColumns[0] = checkboxColumn;
|
|
18
|
+
} else {
|
|
19
|
+
updatedColumns.unshift(checkboxColumn);
|
|
20
|
+
}
|
|
21
|
+
return updatedColumns;
|
|
22
|
+
},
|
|
23
|
+
[checked, data, RowCheckbox]
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getCheckboxColumn({ allChecked, RowCheckbox }) {
|
|
28
|
+
return {
|
|
29
|
+
title: <Checkbox checked={allChecked} disabled />,
|
|
30
|
+
width: 54,
|
|
31
|
+
key: 'checkbox',
|
|
32
|
+
render: RowCheckbox,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { message } from 'antd';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import { ApiResponse } from '../../../api/Api';
|
|
4
|
+
import addIndexToObject from '../addIndexToObject';
|
|
5
|
+
|
|
6
|
+
type UseGetDeleteRow<DataType> = {
|
|
7
|
+
onDelete: (row: DataType) => Promise<ApiResponse> | void;
|
|
8
|
+
setData: (rows: DataType[]) => void;
|
|
9
|
+
data: DataType[];
|
|
10
|
+
deleteMessage?: (record: DataType) => string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function useGetDeleteRow<DataType>({
|
|
14
|
+
onDelete,
|
|
15
|
+
setData,
|
|
16
|
+
data,
|
|
17
|
+
deleteMessage,
|
|
18
|
+
}: UseGetDeleteRow<DataType>) {
|
|
19
|
+
return useCallback(
|
|
20
|
+
async (row: DataType) => {
|
|
21
|
+
try {
|
|
22
|
+
const response = await onDelete(row);
|
|
23
|
+
if (!response) return;
|
|
24
|
+
deleteMessage &&
|
|
25
|
+
message.success(deleteMessage(row));
|
|
26
|
+
setData(
|
|
27
|
+
data
|
|
28
|
+
.filter((e) => JSON.stringify(e) !== JSON.stringify(row))
|
|
29
|
+
.map(addIndexToObject)
|
|
30
|
+
);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
message.error(`Wystąpił błąd ${e}`);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
[data, onDelete, setData]
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// TODO: fix resizing
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { DataRow, TableColumn } from '../../../app_types';
|
|
4
|
+
|
|
5
|
+
type Props<DataType = DataRow> = {
|
|
6
|
+
columns: TableColumn<DataType>[];
|
|
7
|
+
setColumns: React.Dispatch<React.SetStateAction<TableColumn<DataType>[]>>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ResizeColumnType = (columnIndex: number, deltaX: number) => void;
|
|
11
|
+
|
|
12
|
+
export default function useGetResizeColumn<DataType>({
|
|
13
|
+
columns,
|
|
14
|
+
setColumns,
|
|
15
|
+
}: Props<DataType>) {
|
|
16
|
+
return useCallback<ResizeColumnType>(
|
|
17
|
+
(columnIndex, deltaX) => {
|
|
18
|
+
const updatedColumns = columns.map((colCfg, index) => {
|
|
19
|
+
if (columnIndex === index) {
|
|
20
|
+
return {
|
|
21
|
+
...colCfg,
|
|
22
|
+
width: Math.max(colCfg.width + deltaX, 50),
|
|
23
|
+
resized: true,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { ...colCfg };
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// setColumns(updatedColumns);
|
|
30
|
+
},
|
|
31
|
+
[columns, setColumns]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Checkbox } from 'antd';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
export default function useGetRowCheckbox({ checked, setChecked }) {
|
|
5
|
+
return useCallback(
|
|
6
|
+
function RowCheckbox(v, row, index) {
|
|
7
|
+
const isInChecked = checked.indexOf(index) !== -1;
|
|
8
|
+
|
|
9
|
+
const handleOnChange = useCallback(
|
|
10
|
+
({ target: { checked: hasBeenChecked } }) => {
|
|
11
|
+
const shouldBeInChecked = !isInChecked && hasBeenChecked;
|
|
12
|
+
if (shouldBeInChecked) {
|
|
13
|
+
setChecked([...checked, index]);
|
|
14
|
+
} else {
|
|
15
|
+
setChecked(checked.filter((e) => e !== index));
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
[checked, isInChecked]
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return <Checkbox checked={isInChecked} onChange={handleOnChange} />;
|
|
22
|
+
},
|
|
23
|
+
[checked]
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import addIndexToObject from '../addIndexToObject';
|
|
3
|
+
|
|
4
|
+
export default function useLoadDataSource({
|
|
5
|
+
filters,
|
|
6
|
+
added,
|
|
7
|
+
data,
|
|
8
|
+
dataSource,
|
|
9
|
+
setData,
|
|
10
|
+
fetchPage,
|
|
11
|
+
pageSize,
|
|
12
|
+
loadPage,
|
|
13
|
+
}) {
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (
|
|
16
|
+
dataSource !== undefined &&
|
|
17
|
+
JSON.stringify(data) !== JSON.stringify(dataSource.map(addIndexToObject))
|
|
18
|
+
) {
|
|
19
|
+
setData(dataSource.map(addIndexToObject));
|
|
20
|
+
} else if (loadPage !== undefined) {
|
|
21
|
+
fetchPage(0, pageSize() * 2);
|
|
22
|
+
}
|
|
23
|
+
}, [filters, added, dataSource]);
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { MARGIN_FOR_SPINNER } from '../Table';
|
|
3
|
+
|
|
4
|
+
export function usePageSize({
|
|
5
|
+
mainRef,
|
|
6
|
+
rowSize,
|
|
7
|
+
}: {
|
|
8
|
+
mainRef: React.MutableRefObject<HTMLDivElement>;
|
|
9
|
+
rowSize: number;
|
|
10
|
+
}): () => number {
|
|
11
|
+
return useCallback(() => {
|
|
12
|
+
const maxSpace = Math.ceil(
|
|
13
|
+
(mainRef.current?.offsetHeight || 0 - MARGIN_FOR_SPINNER) / rowSize
|
|
14
|
+
);
|
|
15
|
+
if (mainRef.current && maxSpace >= 0) {
|
|
16
|
+
return maxSpace;
|
|
17
|
+
}
|
|
18
|
+
return 2;
|
|
19
|
+
}, [mainRef]);
|
|
20
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Space } from 'antd';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import { DeleteTwoTone } from '@ant-design/icons';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
|
|
6
|
+
const Action = styled.div`
|
|
7
|
+
span {
|
|
8
|
+
svg {
|
|
9
|
+
transition: 150ms ease-in-out;
|
|
10
|
+
font-size: 16px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
img {
|
|
14
|
+
width: 16px;
|
|
15
|
+
height: 16px;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export default function useRenderRowActions({ data, actions, deleteRow }) {
|
|
21
|
+
return useCallback(
|
|
22
|
+
(v, row, rowIndex) => {
|
|
23
|
+
if (!data) return null;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Space size={28}>
|
|
27
|
+
{actions.buttons?.map((e, i) => (
|
|
28
|
+
<Action key={i} className="action">
|
|
29
|
+
{e(data[rowIndex - 1])}
|
|
30
|
+
</Action>
|
|
31
|
+
))}
|
|
32
|
+
{actions.delete ? (
|
|
33
|
+
<Action className="action">
|
|
34
|
+
<DeleteTwoTone
|
|
35
|
+
onClick={() => deleteRow(data[rowIndex - 1])}
|
|
36
|
+
twoToneColor="#F5222D"
|
|
37
|
+
/>
|
|
38
|
+
</Action>
|
|
39
|
+
) : undefined}
|
|
40
|
+
</Space>
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
[data, actions, deleteRow]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import areProvidedColumnsDifferent from '../areProvidedColumnsDifferent';
|
|
3
|
+
|
|
4
|
+
const SCROLLBAR_WIDTH = 16;
|
|
5
|
+
export default function useResizeColumns({
|
|
6
|
+
providedColumns,
|
|
7
|
+
columns,
|
|
8
|
+
main,
|
|
9
|
+
floatingActions,
|
|
10
|
+
actions,
|
|
11
|
+
setColumns,
|
|
12
|
+
grid,
|
|
13
|
+
}) {
|
|
14
|
+
return useCallback(() => {
|
|
15
|
+
if (areProvidedColumnsDifferent(providedColumns, columns)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const sum = columns.map((e) => e.width).reduce((a, b) => a + b, 0);
|
|
20
|
+
|
|
21
|
+
const restSum = columns
|
|
22
|
+
.slice(0, columns.length - 1)
|
|
23
|
+
.map((e) => e.width)
|
|
24
|
+
.reduce((a, b) => a + b, 0);
|
|
25
|
+
|
|
26
|
+
const space = main.current?.offsetWidth - SCROLLBAR_WIDTH;
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
sum < space ||
|
|
30
|
+
(columns[columns.length - 1].modified &&
|
|
31
|
+
columns[columns.length - 1].width !== space - restSum)
|
|
32
|
+
) {
|
|
33
|
+
if (
|
|
34
|
+
!floatingActions &&
|
|
35
|
+
actions &&
|
|
36
|
+
columns[columns.length - 1].key !== 'akcje'
|
|
37
|
+
) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const updatedColumns = [...columns];
|
|
42
|
+
if (updatedColumns[columns.length - 1]) {
|
|
43
|
+
updatedColumns[columns.length - 1].width = space - restSum;
|
|
44
|
+
updatedColumns[columns.length - 1].modified = true;
|
|
45
|
+
setColumns(updatedColumns);
|
|
46
|
+
} else {
|
|
47
|
+
console.error('updating non-existent column');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
grid.current?.recomputeGridSize();
|
|
52
|
+
}, [
|
|
53
|
+
providedColumns,
|
|
54
|
+
setColumns,
|
|
55
|
+
columns,
|
|
56
|
+
main,
|
|
57
|
+
floatingActions,
|
|
58
|
+
actions,
|
|
59
|
+
grid,
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Table'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createContext, useContext, useState } from 'react';
|
|
3
|
+
import { Order } from '../../../app_types';
|
|
4
|
+
|
|
5
|
+
const OrderContext = createContext<{
|
|
6
|
+
order?: Order;
|
|
7
|
+
setOrder: (order: Order) => void;
|
|
8
|
+
}>({ order: undefined, setOrder: () => {} });
|
|
9
|
+
|
|
10
|
+
export const useOrder = () => useContext(OrderContext);
|
|
11
|
+
|
|
12
|
+
export const OrderProvider = ({ children }) => {
|
|
13
|
+
const [order, setOrder] = useState<Order>();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<OrderContext.Provider value={{ order, setOrder }}>
|
|
17
|
+
{children}
|
|
18
|
+
</OrderContext.Provider>
|
|
19
|
+
);
|
|
20
|
+
};
|