@licklist/design 0.44.488 → 0.44.490
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/customers/components/filter/CustomerFilter.d.ts +13 -0
- package/dist/customers/components/filter/CustomerFilter.d.ts.map +1 -0
- package/dist/customers/components/filter/CustomerFilter.js +1 -0
- package/dist/customers/components/filter/index.d.ts +3 -0
- package/dist/customers/components/filter/index.d.ts.map +1 -0
- package/dist/customers/components/index.d.ts +2 -0
- package/dist/customers/components/index.d.ts.map +1 -0
- package/dist/customers/index.d.ts +2 -0
- package/dist/customers/index.d.ts.map +1 -0
- package/dist/events/event-statistic-modal/EventStatisticModal.d.ts +1 -2
- package/dist/events/event-statistic-modal/EventStatisticModal.d.ts.map +1 -1
- package/dist/events/event-statistic-modal/EventStatisticModal.js +1 -1
- package/dist/events/event-statistic-modal/hooks/useTableData.d.ts +1 -1
- package/dist/events/event-statistic-modal/hooks/useTableData.d.ts.map +1 -1
- package/dist/events/event-statistic-modal/hooks/useTableData.js +1 -1
- package/dist/events/event-statistic-modal/utils/index.d.ts +1 -1
- package/dist/events/event-statistic-modal/utils/index.d.ts.map +1 -1
- package/dist/events/event-statistic-modal/utils/index.js +1 -1
- package/dist/iframe/payment/order-items-table/OrderItemsTable.js +1 -1
- package/dist/iframe/payment/payment-form/PaymentForm.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/sales/guest-profile/previous-bookings/PreviousBookings.d.ts +3 -2
- package/dist/sales/guest-profile/previous-bookings/PreviousBookings.d.ts.map +1 -1
- package/dist/sales/guest-profile/previous-bookings/PreviousBookings.js +1 -1
- package/dist/sales/notes/NotesTableRow.js +1 -1
- package/dist/setting/dashboard/snippets/card/SnippetCard.js +1 -1
- package/dist/styles/customers/Filter.scss +53 -0
- package/dist/styles/customers/_index.scss +1 -0
- package/dist/styles/packages.scss +1 -0
- package/dist/table/ReactTableHelperComponent.d.ts +12 -0
- package/dist/table/ReactTableHelperComponent.d.ts.map +1 -0
- package/dist/table/ReactTableHelperComponent.js +1 -0
- package/dist/table/TableHelperComponent.d.ts +2 -3
- package/dist/table/TableHelperComponent.d.ts.map +1 -1
- package/dist/table/hooks/useTableQueryOptions.d.ts +20 -0
- package/dist/table/hooks/useTableQueryOptions.d.ts.map +1 -0
- package/dist/table/hooks/useTableQueryOptions.js +1 -0
- package/dist/table/index.d.ts +1 -0
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/types.d.ts +41 -0
- package/dist/table/types.d.ts.map +1 -0
- package/dist/table/utils/index.d.ts +1 -0
- package/dist/table/utils/index.d.ts.map +1 -1
- package/dist/table/utils/index.js +1 -1
- package/package.json +2 -1
- package/src/customers/components/filter/CustomerFilter.stories.tsx +18 -0
- package/src/customers/components/filter/CustomerFilter.tsx +48 -0
- package/src/customers/components/filter/index.ts +2 -0
- package/src/customers/components/index.ts +1 -0
- package/src/customers/index.ts +1 -0
- package/src/events/event-statistic-modal/EventStatisticModal.tsx +1 -4
- package/src/events/event-statistic-modal/hooks/useTableData.tsx +4 -10
- package/src/events/event-statistic-modal/utils/index.ts +35 -38
- package/src/index.ts +1 -0
- package/src/sales/guest-profile/previous-bookings/PreviousBookings.stories.tsx +35 -5
- package/src/sales/guest-profile/previous-bookings/PreviousBookings.tsx +11 -3
- package/src/styles/customers/Filter.scss +53 -0
- package/src/styles/customers/_index.scss +1 -0
- package/src/styles/packages.scss +1 -0
- package/src/table/ReactTableHelperComponent.tsx +321 -0
- package/src/table/Table.stories.tsx +127 -1
- package/src/table/TableHelperComponent.tsx +3 -1
- package/src/table/hooks/useTableQueryOptions.ts +49 -0
- package/src/table/index.ts +1 -0
- package/src/table/types.ts +47 -0
- package/src/table/utils/index.ts +2 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useMemo,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
Ref,
|
|
7
|
+
ReactElement,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { Col, Row, Table } from "react-bootstrap";
|
|
10
|
+
import { useLocation } from "react-router-dom";
|
|
11
|
+
import { isEqual } from "lodash";
|
|
12
|
+
import clsx from "clsx";
|
|
13
|
+
import {
|
|
14
|
+
useReactTable,
|
|
15
|
+
ColumnDefResolved,
|
|
16
|
+
getCoreRowModel,
|
|
17
|
+
} from "@tanstack/react-table";
|
|
18
|
+
import RouteService from "@licklist/plugins/dist/services/Route/RouteService";
|
|
19
|
+
import TableService from "@licklist/plugins/dist/services/Table/TableService";
|
|
20
|
+
import { LoaderIndicator } from "../static/loader/LoaderIndicator";
|
|
21
|
+
import { FilterHelperComponent } from "./FilterHelperComponent";
|
|
22
|
+
import { PaginationHelperComponent } from "./PaginationHelperComponent";
|
|
23
|
+
import { PerPageHelperComponent } from "./PerPageHelperComponent";
|
|
24
|
+
import { flexRender } from "./utils";
|
|
25
|
+
import {
|
|
26
|
+
TableComponentProps,
|
|
27
|
+
TableComponentPropsWithOldTableData,
|
|
28
|
+
TableComponentPropsWithReactTableData,
|
|
29
|
+
TableColumnMeta,
|
|
30
|
+
ExtendedTableOptions,
|
|
31
|
+
} from "./types";
|
|
32
|
+
import { useTableQueryOptions } from "./hooks/useTableQueryOptions";
|
|
33
|
+
|
|
34
|
+
export type { ReactTableHelperRow } from "./types";
|
|
35
|
+
|
|
36
|
+
export type ReactTableHelperComponentProps<T extends object> =
|
|
37
|
+
TableComponentProps<T> &
|
|
38
|
+
(
|
|
39
|
+
| TableComponentPropsWithOldTableData<T>
|
|
40
|
+
| TableComponentPropsWithReactTableData<T>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export type ReactTableHelperComponentRef = {
|
|
44
|
+
options: ExtendedTableOptions | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* ReactTableHelperComponent
|
|
49
|
+
* simple table with our backend realization
|
|
50
|
+
* and pagination.
|
|
51
|
+
* @param props
|
|
52
|
+
* @constructor
|
|
53
|
+
*/
|
|
54
|
+
function WrappedReactTableHelperComponent<T extends object>(
|
|
55
|
+
props: ReactTableHelperComponentProps<T>,
|
|
56
|
+
ref: Ref<ReactTableHelperComponentRef>
|
|
57
|
+
) {
|
|
58
|
+
const {
|
|
59
|
+
paginator,
|
|
60
|
+
headers,
|
|
61
|
+
renderItemFn,
|
|
62
|
+
isLoading,
|
|
63
|
+
striped = true,
|
|
64
|
+
bordered = true,
|
|
65
|
+
displaySearchBar = true,
|
|
66
|
+
displayPerPageSelect = true,
|
|
67
|
+
displayShowingSection = true,
|
|
68
|
+
externalFilters = {},
|
|
69
|
+
initialOptions = {},
|
|
70
|
+
columns,
|
|
71
|
+
sortableColumns = [],
|
|
72
|
+
renderRow,
|
|
73
|
+
...tableProps
|
|
74
|
+
} = props;
|
|
75
|
+
|
|
76
|
+
const { pathname } = useLocation();
|
|
77
|
+
|
|
78
|
+
const {
|
|
79
|
+
sortKey,
|
|
80
|
+
sortDirection,
|
|
81
|
+
options,
|
|
82
|
+
setOptions,
|
|
83
|
+
optionsCache,
|
|
84
|
+
setOptionsCache,
|
|
85
|
+
cachedExternalFilters,
|
|
86
|
+
setCachedExternalFilters,
|
|
87
|
+
} = useTableQueryOptions({ initialOptions, externalFilters });
|
|
88
|
+
|
|
89
|
+
const tableColumns = useMemo(() => {
|
|
90
|
+
if (!columns && !headers) return [];
|
|
91
|
+
|
|
92
|
+
if (columns && !headers) {
|
|
93
|
+
return columns.map((column) => {
|
|
94
|
+
const { accessorKey } = column as ColumnDefResolved<T>;
|
|
95
|
+
const isSortable = sortableColumns.includes(accessorKey);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
...column,
|
|
99
|
+
meta: {
|
|
100
|
+
className: TableService.getHeaderClasses(
|
|
101
|
+
{ isSortable, key: accessorKey, title: accessorKey },
|
|
102
|
+
sortKey,
|
|
103
|
+
sortDirection
|
|
104
|
+
),
|
|
105
|
+
onClick: isSortable ? () => onSort(accessorKey!) : undefined,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return headers.map((header) => {
|
|
112
|
+
if (typeof header === "string") {
|
|
113
|
+
return {
|
|
114
|
+
accessorKey: header.toLowerCase(),
|
|
115
|
+
header: () => header,
|
|
116
|
+
meta: {
|
|
117
|
+
className: TableService.getHeaderClasses(
|
|
118
|
+
header,
|
|
119
|
+
sortKey,
|
|
120
|
+
sortDirection
|
|
121
|
+
),
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
accessorKey: header?.key || header.title.toLowerCase(),
|
|
128
|
+
header: () => header.title,
|
|
129
|
+
meta: {
|
|
130
|
+
onClick: () => header.isSortable && onSort(header.key!),
|
|
131
|
+
className: TableService.getHeaderClasses(
|
|
132
|
+
header,
|
|
133
|
+
sortKey,
|
|
134
|
+
sortDirection
|
|
135
|
+
),
|
|
136
|
+
style: { width: header?.width || "auto" },
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
141
|
+
}, [headers, columns, sortKey, sortDirection, sortableColumns]);
|
|
142
|
+
|
|
143
|
+
const { getHeaderGroups, getRowModel } = useReactTable<T>({
|
|
144
|
+
data: paginator?.data || [],
|
|
145
|
+
columns: tableColumns,
|
|
146
|
+
getCoreRowModel: getCoreRowModel<T>(),
|
|
147
|
+
...tableProps,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
useImperativeHandle(ref, () => {
|
|
151
|
+
return { options };
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Redirect to the URL with a new parameters
|
|
155
|
+
// ONLY: if any option or external filters has changed
|
|
156
|
+
useEffect(
|
|
157
|
+
() => {
|
|
158
|
+
if (
|
|
159
|
+
isEqual(optionsCache, options) &&
|
|
160
|
+
isEqual(cachedExternalFilters, externalFilters)
|
|
161
|
+
)
|
|
162
|
+
return;
|
|
163
|
+
|
|
164
|
+
setOptionsCache(options);
|
|
165
|
+
setCachedExternalFilters(externalFilters);
|
|
166
|
+
|
|
167
|
+
const nextUrlSearchParams = new URLSearchParams({
|
|
168
|
+
...options,
|
|
169
|
+
...externalFilters,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
RouteService.redirectTo(
|
|
173
|
+
[pathname, nextUrlSearchParams.toString()].join("?")
|
|
174
|
+
);
|
|
175
|
+
},
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
[pathname, options, externalFilters]
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const onSort = (key: string) => {
|
|
181
|
+
let nextDirection = TableService.DEFAULT_SORT_DIRECTION;
|
|
182
|
+
|
|
183
|
+
if (sortKey === key) {
|
|
184
|
+
setOptions((prevOptions) => {
|
|
185
|
+
nextDirection = TableService.getSortDirection(
|
|
186
|
+
prevOptions.sortDirection,
|
|
187
|
+
nextDirection
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
...prevOptions,
|
|
192
|
+
sortKey: key,
|
|
193
|
+
sortDirection: nextDirection,
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
setOptions((prevOptions) => ({
|
|
198
|
+
...prevOptions,
|
|
199
|
+
sortKey: key,
|
|
200
|
+
sortDirection: nextDirection,
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const onPerPageChange = (nextPerPage: number) => {
|
|
206
|
+
setOptions((prevOptions) => ({
|
|
207
|
+
...prevOptions,
|
|
208
|
+
perPage: nextPerPage,
|
|
209
|
+
}));
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const onPageChange = (nextPage: number) => {
|
|
213
|
+
setOptions((prevOptions) => ({
|
|
214
|
+
...prevOptions,
|
|
215
|
+
page: nextPage,
|
|
216
|
+
}));
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const onFilterChange = (nextFilter: string) => {
|
|
220
|
+
setOptions(({ page: prevPage, ...prevOptions }) => {
|
|
221
|
+
let nextPage = prevPage;
|
|
222
|
+
|
|
223
|
+
if (
|
|
224
|
+
(!nextFilter && prevOptions.filter) ||
|
|
225
|
+
(nextFilter && !prevOptions.filter)
|
|
226
|
+
) {
|
|
227
|
+
nextPage = 1;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
...prevOptions,
|
|
232
|
+
page: nextPage,
|
|
233
|
+
filter: nextFilter,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<div className={clsx("table-helper", isLoading ? "py-5" : "py-1")}>
|
|
240
|
+
<LoaderIndicator isLoaded={!isLoading}>
|
|
241
|
+
<Row>
|
|
242
|
+
<Col>
|
|
243
|
+
{displayPerPageSelect && (
|
|
244
|
+
<PerPageHelperComponent
|
|
245
|
+
onChangeFn={onPerPageChange}
|
|
246
|
+
defaultValue={
|
|
247
|
+
paginator?.per_page ?? TableService.DEFAULT_PER_PAGE
|
|
248
|
+
}
|
|
249
|
+
/>
|
|
250
|
+
)}
|
|
251
|
+
</Col>
|
|
252
|
+
<Col>
|
|
253
|
+
{displaySearchBar && (
|
|
254
|
+
<FilterHelperComponent
|
|
255
|
+
onClickFn={onFilterChange}
|
|
256
|
+
defaultValue={options.filter ?? ""}
|
|
257
|
+
/>
|
|
258
|
+
)}
|
|
259
|
+
</Col>
|
|
260
|
+
</Row>
|
|
261
|
+
<Row>
|
|
262
|
+
<Col>
|
|
263
|
+
<div className="table-responsive">
|
|
264
|
+
<Table striped={striped} bordered={bordered} hover>
|
|
265
|
+
<thead>
|
|
266
|
+
{getHeaderGroups().map((headerGroup) => (
|
|
267
|
+
<tr key={headerGroup.id}>
|
|
268
|
+
{headerGroup.headers.map((header) => {
|
|
269
|
+
const headerMeta = header.column.columnDef
|
|
270
|
+
.meta as TableColumnMeta;
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<th
|
|
274
|
+
key={header.id}
|
|
275
|
+
className={headerMeta?.className}
|
|
276
|
+
onClick={headerMeta?.onClick}
|
|
277
|
+
style={headerMeta?.style}
|
|
278
|
+
>
|
|
279
|
+
{flexRender(
|
|
280
|
+
header.column.columnDef.header,
|
|
281
|
+
header.getContext()
|
|
282
|
+
)}
|
|
283
|
+
</th>
|
|
284
|
+
);
|
|
285
|
+
})}
|
|
286
|
+
</tr>
|
|
287
|
+
))}
|
|
288
|
+
</thead>
|
|
289
|
+
<tbody>
|
|
290
|
+
{getRowModel().rows.map((row, index) => {
|
|
291
|
+
if (renderItemFn) {
|
|
292
|
+
return renderItemFn(row.original, index);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return renderRow(row);
|
|
296
|
+
})}
|
|
297
|
+
</tbody>
|
|
298
|
+
</Table>
|
|
299
|
+
</div>
|
|
300
|
+
</Col>
|
|
301
|
+
</Row>
|
|
302
|
+
|
|
303
|
+
<PaginationHelperComponent
|
|
304
|
+
displayShowingSection={displayShowingSection}
|
|
305
|
+
paginator={paginator}
|
|
306
|
+
onPageChangeFn={onPageChange}
|
|
307
|
+
/>
|
|
308
|
+
</LoaderIndicator>
|
|
309
|
+
</div>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const ReactTableHelperComponent = forwardRef(
|
|
314
|
+
WrappedReactTableHelperComponent
|
|
315
|
+
) as <T extends object>(
|
|
316
|
+
props: ReactTableHelperComponentProps<T> & {
|
|
317
|
+
ref?: Ref<ReactTableHelperComponentRef>;
|
|
318
|
+
}
|
|
319
|
+
) => ReactElement;
|
|
320
|
+
|
|
321
|
+
export { ReactTableHelperComponent };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ILengthAwarePaginator from "@licklist/plugins/dist/types/services/Table/ILengthAwarePaginator";
|
|
2
2
|
import { Meta, Story } from "@storybook/react";
|
|
3
3
|
import { range } from "lodash";
|
|
4
|
-
import React from "react";
|
|
4
|
+
import React, { useRef } from "react";
|
|
5
5
|
import { Router } from "../auth/Router";
|
|
6
6
|
import {
|
|
7
7
|
FilterHelperComponent as FilterHelper,
|
|
@@ -19,6 +19,13 @@ import {
|
|
|
19
19
|
TableHelperComponent as TableHelper,
|
|
20
20
|
TableHelperComponentProps,
|
|
21
21
|
} from "./TableHelperComponent";
|
|
22
|
+
import {
|
|
23
|
+
ReactTableHelperComponent as ReactTableHelper,
|
|
24
|
+
ReactTableHelperComponentProps,
|
|
25
|
+
ReactTableHelperRow,
|
|
26
|
+
ReactTableHelperComponentRef,
|
|
27
|
+
} from "./ReactTableHelperComponent";
|
|
28
|
+
import { flexRender } from "./utils/index";
|
|
22
29
|
|
|
23
30
|
export default {
|
|
24
31
|
title: "Table",
|
|
@@ -45,6 +52,40 @@ export const PerPageHelperComponent: Story<PerPageHelperComponentProps> = (
|
|
|
45
52
|
args
|
|
46
53
|
) => <PerPageHelper {...args} />;
|
|
47
54
|
|
|
55
|
+
export const ReactTableHelperComponent: Story<
|
|
56
|
+
ReactTableHelperComponentProps<any>
|
|
57
|
+
> = (args) => (
|
|
58
|
+
<>
|
|
59
|
+
<Router>
|
|
60
|
+
<ReactTableHelper {...args} />
|
|
61
|
+
</Router>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const ComponentInsideRouter = (args) => {
|
|
66
|
+
const ref = useRef<ReactTableHelperComponentRef>(null);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<ReactTableHelper
|
|
70
|
+
{...args}
|
|
71
|
+
ref={ref}
|
|
72
|
+
externalFilters={{ uniqField: "uniqField" }}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const ReactTableHelperComponentWithColumns: Story<
|
|
78
|
+
ReactTableHelperComponentProps<any>
|
|
79
|
+
> = (args) => {
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<Router>
|
|
83
|
+
<ComponentInsideRouter {...args} />
|
|
84
|
+
</Router>
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
48
89
|
const getPaginator = (perPage, items = 100) =>
|
|
49
90
|
({
|
|
50
91
|
current_page: 1,
|
|
@@ -98,3 +139,88 @@ TableHelperComponent.args = {
|
|
|
98
139
|
PaginationHelperComponent.args = {
|
|
99
140
|
paginator: getPaginator(24, 100),
|
|
100
141
|
};
|
|
142
|
+
|
|
143
|
+
ReactTableHelperComponent.args = {
|
|
144
|
+
isLoading: false,
|
|
145
|
+
headers: [
|
|
146
|
+
{
|
|
147
|
+
title: "ID",
|
|
148
|
+
key: "id",
|
|
149
|
+
isSortable: true,
|
|
150
|
+
width: "600px",
|
|
151
|
+
},
|
|
152
|
+
"Title",
|
|
153
|
+
"Description",
|
|
154
|
+
"Action",
|
|
155
|
+
],
|
|
156
|
+
paginator: getPaginator(24, 10),
|
|
157
|
+
renderItemFn: (row) => {
|
|
158
|
+
return (
|
|
159
|
+
<tr key={row.id}>
|
|
160
|
+
<td>{row.id}</td>
|
|
161
|
+
<td>{row.title}</td>
|
|
162
|
+
<td>{row.description}</td>
|
|
163
|
+
<td>ADD | REMOVE</td>
|
|
164
|
+
</tr>
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
striped: false,
|
|
168
|
+
bordered: false,
|
|
169
|
+
displayShowingSection: false,
|
|
170
|
+
initialOptions: {
|
|
171
|
+
page: 1,
|
|
172
|
+
perPage: 10,
|
|
173
|
+
sortKey: "id",
|
|
174
|
+
sortDirection: "desc",
|
|
175
|
+
filter: "",
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
ReactTableHelperComponentWithColumns.args = {
|
|
180
|
+
isLoading: false,
|
|
181
|
+
columns: [
|
|
182
|
+
{
|
|
183
|
+
accessorKey: "id",
|
|
184
|
+
header: () => "CustomHeader",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
accessorKey: "title",
|
|
188
|
+
header: () => "SuperTitle",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
accessorKey: "description",
|
|
192
|
+
header: () => "AwesomeDescription",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
accessorKey: "actions",
|
|
196
|
+
header: () => "Incredible Actions",
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
sortableColumns: ["id"],
|
|
200
|
+
paginator: getPaginator(24, 10),
|
|
201
|
+
renderRow: (row: ReactTableHelperRow<any>) => {
|
|
202
|
+
return (
|
|
203
|
+
<tr key={row.id}>
|
|
204
|
+
{row.getVisibleCells().map((cell) => {
|
|
205
|
+
return (
|
|
206
|
+
<td key={cell.id}>
|
|
207
|
+
{cell.column.id === "actions"
|
|
208
|
+
? "ADD | REMOVE"
|
|
209
|
+
: flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
210
|
+
</td>
|
|
211
|
+
);
|
|
212
|
+
})}
|
|
213
|
+
</tr>
|
|
214
|
+
);
|
|
215
|
+
},
|
|
216
|
+
striped: false,
|
|
217
|
+
bordered: false,
|
|
218
|
+
displayShowingSection: false,
|
|
219
|
+
initialOptions: {
|
|
220
|
+
page: 1,
|
|
221
|
+
perPage: 10,
|
|
222
|
+
sortKey: "id",
|
|
223
|
+
sortDirection: "desc",
|
|
224
|
+
filter: "",
|
|
225
|
+
},
|
|
226
|
+
};
|
|
@@ -14,6 +14,7 @@ import { FilterHelperComponent } from "./FilterHelperComponent";
|
|
|
14
14
|
import { PaginationHelperComponent } from "./PaginationHelperComponent";
|
|
15
15
|
import { PerPageHelperComponent } from "./PerPageHelperComponent";
|
|
16
16
|
import { getFilterOptionsValue } from "./utils";
|
|
17
|
+
import { ExtendedTableOptions } from "./types";
|
|
17
18
|
|
|
18
19
|
export interface TableHelperComponentProps {
|
|
19
20
|
headers: ITableHeader[];
|
|
@@ -31,7 +32,6 @@ export interface TableHelperComponentProps {
|
|
|
31
32
|
initialOptions?: Partial<ITableProps>;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export type ExtendedTableOptions = ITableProps & { [key: string]: any };
|
|
35
35
|
// @TODO Refactor? component to get less complexity
|
|
36
36
|
// with query filter params. Now External filters use only in
|
|
37
37
|
// one place of Dashboard.
|
|
@@ -42,6 +42,8 @@ export type ExtendedTableOptions = ITableProps & { [key: string]: any };
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* TableHelperComponent
|
|
45
|
+
* @deprecated use new ReactTableHelperComponent
|
|
46
|
+
* for default tables
|
|
45
47
|
* @param props
|
|
46
48
|
* @constructor
|
|
47
49
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import useQuery from "@licklist/plugins/dist/hooks/Query/useQuery";
|
|
3
|
+
import { getFilterOptionsValue } from "../utils";
|
|
4
|
+
import { TableComponentProps, ExtendedTableOptions } from "../types";
|
|
5
|
+
|
|
6
|
+
export const useTableQueryOptions = <T extends object>({
|
|
7
|
+
initialOptions = {},
|
|
8
|
+
externalFilters = {},
|
|
9
|
+
}: Pick<TableComponentProps<T>, "initialOptions" | "externalFilters">) => {
|
|
10
|
+
const query = useQuery();
|
|
11
|
+
|
|
12
|
+
const page = Number(getFilterOptionsValue(query, initialOptions, "page"));
|
|
13
|
+
const perPage = Number(
|
|
14
|
+
getFilterOptionsValue(query, initialOptions, "perPage")
|
|
15
|
+
);
|
|
16
|
+
const sortKey = String(
|
|
17
|
+
getFilterOptionsValue(query, initialOptions, "sortKey")
|
|
18
|
+
);
|
|
19
|
+
const sortDirection = String(
|
|
20
|
+
getFilterOptionsValue(query, initialOptions, "sortDirection")
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const filter = String(getFilterOptionsValue(query, initialOptions, "filter"));
|
|
24
|
+
|
|
25
|
+
const [optionsCache, setOptionsCache] = useState<ExtendedTableOptions>();
|
|
26
|
+
const [options, setOptions] = useState<ExtendedTableOptions>({
|
|
27
|
+
page,
|
|
28
|
+
perPage,
|
|
29
|
+
sortKey,
|
|
30
|
+
sortDirection,
|
|
31
|
+
filter,
|
|
32
|
+
});
|
|
33
|
+
const [cachedExternalFilters, setCachedExternalFilters] =
|
|
34
|
+
useState<{ [key: string]: any }>(externalFilters);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
page,
|
|
38
|
+
perPage,
|
|
39
|
+
sortKey,
|
|
40
|
+
sortDirection,
|
|
41
|
+
filter,
|
|
42
|
+
optionsCache,
|
|
43
|
+
setOptionsCache,
|
|
44
|
+
options,
|
|
45
|
+
setOptions,
|
|
46
|
+
cachedExternalFilters,
|
|
47
|
+
setCachedExternalFilters,
|
|
48
|
+
};
|
|
49
|
+
};
|
package/src/table/index.ts
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties } from "react";
|
|
2
|
+
import {
|
|
3
|
+
TableOptions,
|
|
4
|
+
ColumnDef,
|
|
5
|
+
Row as TableRow,
|
|
6
|
+
} from "@tanstack/react-table";
|
|
7
|
+
import ILengthAwarePaginator from "@licklist/plugins/dist/types/services/Table/ILengthAwarePaginator";
|
|
8
|
+
import ITableHeader from "@licklist/plugins/dist/types/services/Table/ITableHeader";
|
|
9
|
+
import ITableProps from "@licklist/plugins/dist/types/services/Table/ITableProps";
|
|
10
|
+
|
|
11
|
+
export type ReactTableHelperRow<T extends object> = TableRow<T>;
|
|
12
|
+
|
|
13
|
+
export type ExtendedTableOptions = ITableProps & { [key: string]: any };
|
|
14
|
+
|
|
15
|
+
export interface TableComponentProps<T extends object>
|
|
16
|
+
extends Omit<TableOptions<T>, "columns" | "data" | "getCoreRowModel"> {
|
|
17
|
+
paginator?: ILengthAwarePaginator<T>;
|
|
18
|
+
isLoading?: boolean;
|
|
19
|
+
striped?: boolean;
|
|
20
|
+
bordered?: boolean;
|
|
21
|
+
displaySearchBar?: boolean;
|
|
22
|
+
displayPerPageSelect?: boolean;
|
|
23
|
+
displayShowingSection?: boolean;
|
|
24
|
+
externalFilters?: { [key: string]: any };
|
|
25
|
+
initialOptions?: Partial<ITableProps>;
|
|
26
|
+
sortableColumns?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type TableColumnMeta = {
|
|
30
|
+
onClick?: () => void;
|
|
31
|
+
className?: string;
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type TableComponentPropsWithOldTableData<T extends object> = {
|
|
36
|
+
headers: ITableHeader[];
|
|
37
|
+
renderItemFn: (row: T, index: number) => void;
|
|
38
|
+
columns?: never;
|
|
39
|
+
renderRow?: never;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type TableComponentPropsWithReactTableData<T extends object> = {
|
|
43
|
+
headers?: never;
|
|
44
|
+
renderItemFn?: never;
|
|
45
|
+
columns: ColumnDef<T, any>[];
|
|
46
|
+
renderRow: (row: ReactTableHelperRow<T>) => ReactNode;
|
|
47
|
+
};
|
package/src/table/utils/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ITableProps from "@licklist/plugins/dist/types/services/Table/ITableProps";
|
|
2
2
|
import TableService from "@licklist/plugins/dist/services/Table/TableService";
|
|
3
3
|
|
|
4
|
+
export { flexRender } from "@tanstack/react-table";
|
|
5
|
+
|
|
4
6
|
const DEFAULT_QUERY_VALUES: { [key in keyof ITableProps]: string | number } = {
|
|
5
7
|
page: TableService.DEFAULT_PAGE,
|
|
6
8
|
perPage: TableService.DEFAULT_PER_PAGE,
|