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