@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,197 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './Table'
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
};
|