@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.
Files changed (193) hide show
  1. package/.eslintrc +6 -0
  2. package/.nvmrc +1 -0
  3. package/.prettierrc +11 -0
  4. package/package.json +5 -16
  5. package/src/api/Api.ts +140 -0
  6. package/src/api/Endpoint.ts +76 -0
  7. package/src/api/createApi.ts +116 -0
  8. package/src/api/error.ts +17 -0
  9. package/{dist/api/index.d.ts → src/api/index.ts} +1 -0
  10. package/src/api/status.ts +3 -0
  11. package/src/api/utils/getAlert.ts +75 -0
  12. package/src/app_types.ts +695 -0
  13. package/src/components/ApiHostProvider.tsx +13 -0
  14. package/src/components/StatusTag.tsx +83 -0
  15. package/src/components/Table/DataTableWrapper.tsx +28 -0
  16. package/src/components/Table/FloatingActions.tsx +152 -0
  17. package/src/components/Table/Spinner.tsx +35 -0
  18. package/src/components/Table/Summary.tsx +18 -0
  19. package/src/components/Table/Table.tsx +474 -0
  20. package/src/components/Table/addIndexToObject.ts +6 -0
  21. package/src/components/Table/areProvidedColumnsDifferent.ts +26 -0
  22. package/src/components/Table/clicked.js +12 -0
  23. package/src/components/Table/displayActions.tsx +19 -0
  24. package/src/components/Table/hooks/useFetchPage.tsx +83 -0
  25. package/src/components/Table/hooks/useGetCellRenderer.tsx +197 -0
  26. package/src/components/Table/hooks/useGetColumnsWithCheckbox.tsx +34 -0
  27. package/src/components/Table/hooks/useGetDeleteRow.tsx +37 -0
  28. package/src/components/Table/hooks/useGetResizeColumn.ts +33 -0
  29. package/src/components/Table/hooks/useGetRowCheckbox.tsx +25 -0
  30. package/src/components/Table/hooks/useLoadDataSource.ts +24 -0
  31. package/src/components/Table/hooks/usePageSize.tsx +20 -0
  32. package/src/components/Table/hooks/useRenderRowActions.tsx +45 -0
  33. package/src/components/Table/hooks/useResizeColumns.ts +61 -0
  34. package/src/components/Table/index.ts +1 -0
  35. package/src/components/Table/providers/OrderProvider.tsx +20 -0
  36. package/src/components/Table/styles.ts +208 -0
  37. package/src/config.ts +7 -0
  38. package/src/db_types.ts +220 -0
  39. package/src/hooks/useApi.ts +43 -0
  40. package/src/hooks/useEndpoint.ts +35 -0
  41. package/src/lib/jednostkaNazwa.ts +6 -0
  42. package/src/lib/typDokumentuNazwa.ts +8 -0
  43. package/src/utils/Query.ts +30 -0
  44. package/src/utils/getWZNumber.ts +13 -0
  45. package/src/utils/getZamowienieDokumentNumber.ts +11 -0
  46. package/{dist/src/utils/index.js → src/utils/index.ts} +2 -2
  47. package/tsconfig.json +25 -0
  48. package/tsconfig.tsbuildinfo +1 -0
  49. package/dist/api/Api.d.ts +0 -33
  50. package/dist/api/Api.js +0 -152
  51. package/dist/api/Endpoint.d.ts +0 -13
  52. package/dist/api/Endpoint.js +0 -126
  53. package/dist/api/createApi.d.ts +0 -52
  54. package/dist/api/createApi.js +0 -81
  55. package/dist/api/error.d.ts +0 -15
  56. package/dist/api/error.js +0 -18
  57. package/dist/api/index.js +0 -34
  58. package/dist/api/status.d.ts +0 -3
  59. package/dist/api/status.js +0 -6
  60. package/dist/api/utils/getAlert.d.ts +0 -6
  61. package/dist/api/utils/getAlert.js +0 -65
  62. package/dist/api/utils/index.js +0 -8
  63. package/dist/app_types.d.ts +0 -607
  64. package/dist/app_types.js +0 -75
  65. package/dist/components/ApiHostProvider.d.ts +0 -7
  66. package/dist/components/ApiHostProvider.js +0 -35
  67. package/dist/components/StatusTag.d.ts +0 -11
  68. package/dist/components/StatusTag.js +0 -86
  69. package/dist/components/Table/DataTableWrapper.d.ts +0 -3
  70. package/dist/components/Table/DataTableWrapper.js +0 -44
  71. package/dist/components/Table/FloatingActions.d.ts +0 -14
  72. package/dist/components/Table/FloatingActions.js +0 -32
  73. package/dist/components/Table/Spinner.d.ts +0 -2
  74. package/dist/components/Table/Spinner.js +0 -26
  75. package/dist/components/Table/Summary.js +0 -16
  76. package/dist/components/Table/Table.d.ts +0 -28
  77. package/dist/components/Table/Table.js +0 -330
  78. package/dist/components/Table/addIndexToObject.d.ts +0 -3
  79. package/dist/components/Table/addIndexToObject.js +0 -17
  80. package/dist/components/Table/areProvidedColumnsDifferent.d.ts +0 -2
  81. package/dist/components/Table/areProvidedColumnsDifferent.js +0 -16
  82. package/dist/components/Table/clicked.js +0 -11
  83. package/dist/components/Table/displayActions.js +0 -11
  84. package/dist/components/Table/hooks/useFetchPage.d.ts +0 -18
  85. package/dist/components/Table/hooks/useFetchPage.js +0 -123
  86. package/dist/components/Table/hooks/useGetCellRenderer.d.ts +0 -25
  87. package/dist/components/Table/hooks/useGetCellRenderer.js +0 -166
  88. package/dist/components/Table/hooks/useGetColumnsWithCheckbox.d.ts +0 -5
  89. package/dist/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -53
  90. package/dist/components/Table/hooks/useGetDeleteRow.d.ts +0 -9
  91. package/dist/components/Table/hooks/useGetDeleteRow.js +0 -74
  92. package/dist/components/Table/hooks/useGetResizeColumn.d.ts +0 -8
  93. package/dist/components/Table/hooks/useGetResizeColumn.js +0 -28
  94. package/dist/components/Table/hooks/useGetRowCheckbox.d.ts +0 -5
  95. package/dist/components/Table/hooks/useGetRowCheckbox.js +0 -54
  96. package/dist/components/Table/hooks/useLoadDataSource.d.ts +0 -10
  97. package/dist/components/Table/hooks/useLoadDataSource.js +0 -20
  98. package/dist/components/Table/hooks/usePageSize.d.ts +0 -5
  99. package/dist/components/Table/hooks/usePageSize.js +0 -16
  100. package/dist/components/Table/hooks/useRenderRowActions.d.ts +0 -6
  101. package/dist/components/Table/hooks/useRenderRowActions.js +0 -51
  102. package/dist/components/Table/hooks/useResizeColumns.d.ts +0 -9
  103. package/dist/components/Table/hooks/useResizeColumns.js +0 -60
  104. package/dist/components/Table/index.d.ts +0 -1
  105. package/dist/components/Table/index.js +0 -8
  106. package/dist/components/Table/providers/OrderProvider.d.ts +0 -9
  107. package/dist/components/Table/providers/OrderProvider.js +0 -17
  108. package/dist/components/Table/styles.d.ts +0 -6
  109. package/dist/components/Table/styles.js +0 -37
  110. package/dist/components/index.js +0 -26
  111. package/dist/config.d.ts +0 -6
  112. package/dist/config.js +0 -8
  113. package/dist/db_types.d.ts +0 -208
  114. package/dist/db_types.js +0 -2
  115. package/dist/hooks/index.js +0 -10
  116. package/dist/hooks/useApi.d.ts +0 -2
  117. package/dist/hooks/useApi.js +0 -42
  118. package/dist/hooks/useEndpoint.d.ts +0 -2
  119. package/dist/hooks/useEndpoint.js +0 -34
  120. package/dist/index.js +0 -19
  121. package/dist/lib/index.js +0 -18
  122. package/dist/lib/jednostka.d.ts +0 -6
  123. package/dist/lib/jednostkaNazwa.d.ts +0 -6
  124. package/dist/lib/jednostkaNazwa.js +0 -9
  125. package/dist/lib/typDokumentuNazwa.d.ts +0 -6
  126. package/dist/lib/typDokumentuNazwa.js +0 -11
  127. package/dist/lib/typ_dokument.d.ts +0 -0
  128. package/dist/lib/typ_dokumentu.d.ts +0 -6
  129. package/dist/lib/unit.d.ts +0 -0
  130. package/dist/src/api/Api.js +0 -316
  131. package/dist/src/api/Endpoint.js +0 -365
  132. package/dist/src/api/createApi.js +0 -50
  133. package/dist/src/api/error.js +0 -15
  134. package/dist/src/api/index.js +0 -5
  135. package/dist/src/api/status.js +0 -3
  136. package/dist/src/api/utils/getAlert.js +0 -63
  137. package/dist/src/api/utils/index.js +0 -1
  138. package/dist/src/app_types.js +0 -72
  139. package/dist/src/components/ApiHostProvider.js +0 -11
  140. package/dist/src/components/StatusTag.js +0 -153
  141. package/dist/src/components/Table/DataTableWrapper.js +0 -115
  142. package/dist/src/components/Table/FloatingActions.js +0 -60
  143. package/dist/src/components/Table/Spinner.js +0 -40
  144. package/dist/src/components/Table/Summary.js +0 -16
  145. package/dist/src/components/Table/Table.js +0 -498
  146. package/dist/src/components/Table/addIndexToObject.js +0 -57
  147. package/dist/src/components/Table/areProvidedColumnsDifferent.js +0 -19
  148. package/dist/src/components/Table/clicked.js +0 -12
  149. package/dist/src/components/Table/displayActions.js +0 -11
  150. package/dist/src/components/Table/hooks/useFetchPage.js +0 -254
  151. package/dist/src/components/Table/hooks/useGetCellRenderer.js +0 -231
  152. package/dist/src/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -33
  153. package/dist/src/components/Table/hooks/useGetDeleteRow.js +0 -181
  154. package/dist/src/components/Table/hooks/useGetResizeColumn.js +0 -72
  155. package/dist/src/components/Table/hooks/useGetRowCheckbox.js +0 -55
  156. package/dist/src/components/Table/hooks/useLoadDataSource.js +0 -16
  157. package/dist/src/components/Table/hooks/usePageSize.js +0 -15
  158. package/dist/src/components/Table/hooks/useRenderRowActions.js +0 -50
  159. package/dist/src/components/Table/hooks/useResizeColumns.js +0 -70
  160. package/dist/src/components/Table/index.js +0 -1
  161. package/dist/src/components/Table/providers/OrderProvider.js +0 -65
  162. package/dist/src/components/Table/styles.js +0 -66
  163. package/dist/src/components/index.js +0 -4
  164. package/dist/src/config.js +0 -6
  165. package/dist/src/db_types.js +0 -1
  166. package/dist/src/hooks/index.js +0 -2
  167. package/dist/src/hooks/useApi.js +0 -84
  168. package/dist/src/hooks/useEndpoint.js +0 -60
  169. package/dist/src/index.js +0 -3
  170. package/dist/src/lib/index.js +0 -2
  171. package/dist/src/lib/jednostkaNazwa.js +0 -6
  172. package/dist/src/lib/typDokumentuNazwa.js +0 -16
  173. package/dist/src/utils/Query.js +0 -73
  174. package/dist/src/utils/getWZNumber.js +0 -4
  175. package/dist/src/utils/getZamowienieDokumentNumber.js +0 -4
  176. package/dist/utils/AlertContext.d.ts +0 -3
  177. package/dist/utils/AlertContext.js +0 -3
  178. package/dist/utils/Query.d.ts +0 -6
  179. package/dist/utils/Query.js +0 -33
  180. package/dist/utils/geNumber.d.ts +0 -2
  181. package/dist/utils/getDocNumber.d.ts +0 -2
  182. package/dist/utils/getWZNumber.js +0 -10
  183. package/dist/utils/getWzNumber.d.ts +0 -2
  184. package/dist/utils/getZamowienieDokumentNumber copy.d.ts +0 -2
  185. package/dist/utils/getZamowienieDokumentNumber.d.ts +0 -2
  186. package/dist/utils/getZamowienieDokumentNumber.js +0 -8
  187. package/dist/utils/index.d.ts +0 -3
  188. package/dist/utils/index.js +0 -12
  189. /package/{dist/api/utils/index.d.ts → src/api/utils/index.ts} +0 -0
  190. /package/{dist/components/index.d.ts → src/components/index.ts} +0 -0
  191. /package/{dist/hooks/index.d.ts → src/hooks/index.ts} +0 -0
  192. /package/{dist/index.d.ts → src/index.ts} +0 -0
  193. /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
+ };