@gobolt/genesis 0.3.21 → 0.3.22
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/Table/Table.d.ts +51 -0
- package/dist/Table/Table.js +14 -0
- package/dist/Table/TableControls/CustomPagination.d.ts +13 -0
- package/dist/Table/TableControls/CustomPagination.js +158 -0
- package/dist/Table/TableControls/PaginationNumber.d.ts +7 -0
- package/dist/Table/TableControls/PaginationNumber.js +30 -0
- package/dist/Table/styles.d.ts +14 -0
- package/dist/Table/styles.js +64 -0
- package/dist/Table/useTable.d.ts +26 -0
- package/dist/Table/useTable.js +141 -0
- package/dist/Typography/Typography.d.ts +17 -0
- package/dist/Typography/Typography.js +16 -0
- package/dist/Typography/index.d.ts +2 -0
- package/dist/Typography/index.js +1 -0
- package/dist/Typography/styles.d.ts +3 -0
- package/dist/Typography/styles.js +54 -0
- package/dist/components/Badge/Badge.js +9 -32
- package/dist/components/Badge/styles.d.ts +1 -10
- package/dist/components/Badge/styles.js +39 -14
- package/dist/components/Button/Button.js +4 -27
- package/dist/components/Button/IconButton.js +4 -27
- package/dist/components/Button/icon-button-styles.d.ts +1 -12
- package/dist/components/Button/icon-button-styles.js +69 -16
- package/dist/components/Button/styles.d.ts +1 -16
- package/dist/components/Button/styles.js +88 -30
- package/dist/components/Input/Input.js +6 -29
- package/dist/components/Input/styles.d.ts +1 -18
- package/dist/components/Input/styles.js +146 -42
- package/dist/components/Select/Select.js +101 -125
- package/dist/components/Select/SelectTrigger.js +71 -57
- package/dist/components/Table/Table.js +8 -27
- package/dist/components/Table/TableControls/CustomPagination.js +50 -66
- package/dist/components/Table/TableControls/PaginationNumber.js +27 -43
- package/dist/components/Table/TableControls/PrimaryTableControlsRow.js +16 -17
- package/dist/components/Table/TableControls/SecondaryTableControlsRow.js +14 -36
- package/dist/components/Table/TableControls/TableControls.js +3 -4
- package/dist/components/Table/TablePagination.js +4 -21
- package/dist/components/Table/__mocks__/table-mocks.js +15 -24
- package/dist/components/Table/styles.d.ts +1 -15
- package/dist/components/Table/styles.js +57 -13
- package/dist/components/Table/useTable.js +69 -166
- package/dist/components/TableWithControls/TableWithControls.js +6 -7
- package/dist/components/TableWithControls/useTableWithControls.js +82 -63
- package/dist/components/Tooltip/Tooltip.js +1 -2
- package/dist/components/Tooltip/styles.d.ts +1 -14
- package/dist/components/Tooltip/styles.js +23 -14
- package/dist/components/Typography/Typography.js +6 -29
- package/dist/components/Typography/styles.d.ts +3 -21
- package/dist/components/Typography/styles.js +41 -24
- package/dist/components/UtilityButton/UtilityButton.js +4 -27
- package/dist/components/shared/DropdownChevron.js +3 -14
- package/dist/constants/index.js +14 -14
- package/dist/genesis-theme.types.d.ts +263 -0
- package/dist/genesis-theme.types.js +6 -0
- package/dist/index.js +89 -0
- package/dist/styled.d.ts +1 -0
- package/dist/styled.js +44 -0
- package/dist/utils/icon-util.d.ts +2 -2
- package/dist/utils/icon-util.js +16 -19
- package/package.json +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import PrimaryTableControlsRow from "./PrimaryTableControlsRow";
|
|
3
3
|
import SecondaryTableControlsRow from "./SecondaryTableControlsRow";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var onPrimaryChange = function (actionEvent) {
|
|
4
|
+
const TableControls = ({ primaryTableRowData, secondaryTableRowData, onChange, }) => {
|
|
5
|
+
const onPrimaryChange = (actionEvent) => {
|
|
7
6
|
onChange(actionEvent);
|
|
8
7
|
};
|
|
9
|
-
|
|
8
|
+
const onSecondaryChange = (actionEvent) => {
|
|
10
9
|
onChange(actionEvent);
|
|
11
10
|
};
|
|
12
11
|
return (_jsxs("div", { "data-testid": "TableControls", style: { margin: "16px 0px" }, children: [_jsx(PrimaryTableControlsRow, { sortOptions: primaryTableRowData.sortOptions, searchByPlaceholder: primaryTableRowData.searchByPlaceholder, isSortedAscending: primaryTableRowData.isSortedAscending, onChange: onPrimaryChange, searchValue: primaryTableRowData.searchValue, selectedSortOption: primaryTableRowData.selectedSortOption }), secondaryTableRowData ? (_jsx(SecondaryTableControlsRow, { groups: secondaryTableRowData.groups, totalRecords: secondaryTableRowData.totalRecords, onChange: onSecondaryChange })) : null] }));
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
2
|
import { useState } from "react";
|
|
19
3
|
import Table from "./Table";
|
|
20
4
|
import CustomPagination, { PaginationStyle, } from "./TableControls/CustomPagination";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var paginatedData = dataSource.slice((current - 1) * pageSize, current * pageSize);
|
|
5
|
+
const TablePagination = ({ columns, dataSource, rowSelection, onChange, paginationStyle = PaginationStyle.SIMPLE, pageSize = 10, isMainContentCell, }) => {
|
|
6
|
+
const [current, setCurrent] = useState(1);
|
|
7
|
+
const total = dataSource.length;
|
|
8
|
+
const paginatedData = dataSource.slice((current - 1) * pageSize, current * pageSize);
|
|
26
9
|
return (_jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "0px" }, children: [_jsx(Table, { columns: columns, dataSource: paginatedData, rowSelection: rowSelection, onChange: onChange, pagination: false, isMainContentCell: isMainContentCell }), _jsx("div", { style: { display: "flex", justifyContent: "flex-end", marginTop: 16 }, children: _jsx(CustomPagination, { paginationStyle: paginationStyle, current: current, total: total, pageSize: pageSize, onChange: setCurrent }) })] }));
|
|
27
10
|
};
|
|
28
11
|
export default TablePagination;
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { Badge } from "@gobolt/genesis/components";
|
|
13
2
|
import React from "react";
|
|
14
3
|
// Helper function for title case
|
|
15
|
-
|
|
4
|
+
const startCase = (string_) => {
|
|
16
5
|
if (string_) {
|
|
17
6
|
return string_
|
|
18
7
|
.replaceAll(/([A-Z])/g, " $1")
|
|
19
|
-
.replace(/^./,
|
|
8
|
+
.replace(/^./, (s) => s.toUpperCase());
|
|
20
9
|
}
|
|
21
10
|
return string_;
|
|
22
11
|
};
|
|
23
|
-
export
|
|
12
|
+
export const mockColumns = [
|
|
24
13
|
{
|
|
25
14
|
key: "number",
|
|
26
15
|
title: "Id",
|
|
@@ -35,13 +24,13 @@ export var mockColumns = [
|
|
|
35
24
|
key: "status",
|
|
36
25
|
title: "Status",
|
|
37
26
|
dataIndex: "status",
|
|
38
|
-
render:
|
|
39
|
-
|
|
27
|
+
render: (status) => {
|
|
28
|
+
const colorStateMap = {
|
|
40
29
|
in_progress: "warning",
|
|
41
30
|
scheduled: "generic",
|
|
42
31
|
completed: "success",
|
|
43
32
|
};
|
|
44
|
-
|
|
33
|
+
const statusLabel = status === "in_progress" ? "in progress" : status;
|
|
45
34
|
return React.createElement(Badge, {
|
|
46
35
|
label: startCase(statusLabel),
|
|
47
36
|
state: colorStateMap[status],
|
|
@@ -51,16 +40,16 @@ export var mockColumns = [
|
|
|
51
40
|
{
|
|
52
41
|
key: "address",
|
|
53
42
|
title: "Address",
|
|
54
|
-
render:
|
|
55
|
-
|
|
56
|
-
return nickname ?
|
|
43
|
+
render: (appointment) => {
|
|
44
|
+
const { address: { nickname, address }, } = appointment;
|
|
45
|
+
return nickname ? `${nickname} (${address})` : address;
|
|
57
46
|
},
|
|
58
47
|
},
|
|
59
48
|
{
|
|
60
49
|
title: "Type",
|
|
61
50
|
dataIndex: "job_subtype",
|
|
62
|
-
render:
|
|
63
|
-
|
|
51
|
+
render: (jobSubtype) => {
|
|
52
|
+
const colorStateMap = {
|
|
64
53
|
delivery: "info",
|
|
65
54
|
pickup: "success",
|
|
66
55
|
};
|
|
@@ -72,8 +61,10 @@ export var mockColumns = [
|
|
|
72
61
|
},
|
|
73
62
|
];
|
|
74
63
|
// Note: it's important that we don't show the Ant Design sorting since it controlled via the table controls
|
|
75
|
-
export
|
|
76
|
-
|
|
64
|
+
export const mockColumnsWithSortDisabled = mockColumns.map((column) => ({
|
|
65
|
+
...column,
|
|
66
|
+
}));
|
|
67
|
+
export const mockDataSource = {
|
|
77
68
|
appointments: [
|
|
78
69
|
{
|
|
79
70
|
id: "1",
|
|
@@ -11,18 +11,4 @@ export declare const getGenesisClass: ({ colors, borderRadius, sizing, typograph
|
|
|
11
11
|
typography: any;
|
|
12
12
|
components: any;
|
|
13
13
|
}, $isMainContentCell: any) => string;
|
|
14
|
-
export declare const Table:
|
|
15
|
-
children?: import("react").ReactNode | undefined;
|
|
16
|
-
} & import("react").RefAttributes<import("rc-table").Reference>, "ref"> & {
|
|
17
|
-
ref?: ((instance: import("rc-table").Reference | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<import("rc-table").Reference> | null | undefined;
|
|
18
|
-
}, StyledTableProps<any>>> & string & Omit<import("antd/es/table/interface").RefTable & {
|
|
19
|
-
displayName?: string;
|
|
20
|
-
SELECTION_COLUMN: typeof import("antd/es/table/hooks/useSelection").SELECTION_COLUMN;
|
|
21
|
-
EXPAND_COLUMN: typeof import("rc-table").EXPAND_COLUMN;
|
|
22
|
-
SELECTION_ALL: typeof import("antd/es/table/hooks/useSelection").SELECTION_ALL;
|
|
23
|
-
SELECTION_INVERT: typeof import("antd/es/table/hooks/useSelection").SELECTION_INVERT;
|
|
24
|
-
SELECTION_NONE: typeof import("antd/es/table/hooks/useSelection").SELECTION_NONE;
|
|
25
|
-
Column: <RecordType extends import("antd/es/_util/type").AnyObject>(_: import("antd").TableColumnProps<RecordType>) => null;
|
|
26
|
-
ColumnGroup: <RecordType extends import("antd/es/_util/type").AnyObject>(_: import("antd/es/table/ColumnGroup").ColumnGroupProps<RecordType>) => null;
|
|
27
|
-
Summary: typeof import("rc-table").Summary;
|
|
28
|
-
}, keyof import("react").Component<any, {}, any>>;
|
|
14
|
+
export declare const Table: any;
|
|
@@ -1,20 +1,64 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
1
|
import styled from "@gobolt/genesis/utils/styled";
|
|
6
2
|
import { Table as AntTable } from "antd";
|
|
7
|
-
export
|
|
3
|
+
export const getGenesisClass = ({ colors, borderRadius, sizing, typography, components }, $isMainContentCell) => {
|
|
8
4
|
// Log the hovered color and the entire tableCell object
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
return `
|
|
6
|
+
&.ant-table-wrapper {
|
|
7
|
+
// Add your custom styles here
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.ant-table {
|
|
11
|
+
// Add your custom table styles here
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.ant-table-cell {
|
|
15
|
+
font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
|
|
16
|
+
color: ${$isMainContentCell
|
|
11
17
|
? colors.onsurface.copy
|
|
12
|
-
: colors.onsurface["copy-light"]
|
|
18
|
+
: colors.onsurface["copy-light"]} !important;
|
|
19
|
+
background-color: ${components.tableCell.surface} !important;
|
|
20
|
+
transition: background-color 0.2s ease;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ant-table-tbody > tr:hover > td,
|
|
24
|
+
.ant-table-tbody > tr:hover > .ant-table-cell {
|
|
25
|
+
background-color: ${components.tableCell.hover} !important;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.ant-table-cell-selected {
|
|
29
|
+
background-color: ${components.tableCell.selected} !important;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.ant-table-thead > tr > th {
|
|
33
|
+
// Add your custom header styles here
|
|
34
|
+
font-family: 'Inter', sans-serif;
|
|
35
|
+
font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
|
|
36
|
+
font-weight: 400;
|
|
37
|
+
color: ${$isMainContentCell
|
|
13
38
|
? colors.onsurface.copy
|
|
14
|
-
: colors.onsurface["copy-light"]
|
|
39
|
+
: colors.onsurface["copy-light"]} !important;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ant-table-tbody > tr {
|
|
43
|
+
// Add your custom row styles here
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ant-table-tbody > tr > td {
|
|
47
|
+
// Add your custom cell styles here
|
|
48
|
+
font-family: 'Inter', sans-serif;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
color: ${colors.onsurface["copy-light"]};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.ant-table-tbody > tr.ant-table-row-selected > td,
|
|
54
|
+
.ant-table-tbody > tr.ant-table-row-selected > .ant-table-cell {
|
|
55
|
+
background-color: ${components.tableCell.selected} !important;
|
|
56
|
+
color: #fff !important;
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
15
59
|
};
|
|
16
|
-
export
|
|
17
|
-
|
|
60
|
+
export const Table = styled(AntTable) `
|
|
61
|
+
${({ theme, $isMainContentCell }) => {
|
|
18
62
|
return getGenesisClass(theme, $isMainContentCell);
|
|
19
|
-
}
|
|
20
|
-
|
|
63
|
+
}}
|
|
64
|
+
`;
|
|
@@ -1,127 +1,33 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
49
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
50
|
-
if (!m) return o;
|
|
51
|
-
var i = m.call(o), r, ar = [], e;
|
|
52
|
-
try {
|
|
53
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
54
|
-
}
|
|
55
|
-
catch (error) { e = { error: error }; }
|
|
56
|
-
finally {
|
|
57
|
-
try {
|
|
58
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
59
|
-
}
|
|
60
|
-
finally { if (e) throw e.error; }
|
|
61
|
-
}
|
|
62
|
-
return ar;
|
|
63
|
-
};
|
|
64
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
65
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
66
|
-
if (ar || !(i in from)) {
|
|
67
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
68
|
-
ar[i] = from[i];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
|
-
};
|
|
73
|
-
var __values = (this && this.__values) || function(o) {
|
|
74
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
75
|
-
if (m) return m.call(o);
|
|
76
|
-
if (o && typeof o.length === "number") return {
|
|
77
|
-
next: function () {
|
|
78
|
-
if (o && i >= o.length) o = void 0;
|
|
79
|
-
return { value: o && o[i++], done: !o };
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
83
|
-
};
|
|
84
1
|
import { useState, useEffect, useCallback } from "react";
|
|
85
2
|
// Function to sort data by field and order
|
|
86
|
-
|
|
3
|
+
const sortData = (data, sorter) => {
|
|
87
4
|
// Handle case when no sorting is applied
|
|
88
5
|
if (!sorter || (Array.isArray(sorter) && sorter.length === 0)) {
|
|
89
|
-
return
|
|
6
|
+
return [...data];
|
|
90
7
|
}
|
|
91
8
|
// Handle multiple sorters
|
|
92
9
|
if (Array.isArray(sorter)) {
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return sort.order === "ascend" ? -1 : 1;
|
|
105
|
-
if (aValue > bValue)
|
|
106
|
-
return sort.order === "ascend" ? 1 : -1;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
110
|
-
finally {
|
|
111
|
-
try {
|
|
112
|
-
if (sorter_1_1 && !sorter_1_1.done && (_a = sorter_1.return)) _a.call(sorter_1);
|
|
113
|
-
}
|
|
114
|
-
finally { if (e_1) throw e_1.error; }
|
|
10
|
+
return [...data].sort((a, b) => {
|
|
11
|
+
for (const sort of sorter) {
|
|
12
|
+
if (!sort.field)
|
|
13
|
+
continue;
|
|
14
|
+
const field = sort.field;
|
|
15
|
+
const aValue = a[field];
|
|
16
|
+
const bValue = b[field];
|
|
17
|
+
if (aValue < bValue)
|
|
18
|
+
return sort.order === "ascend" ? -1 : 1;
|
|
19
|
+
if (aValue > bValue)
|
|
20
|
+
return sort.order === "ascend" ? 1 : -1;
|
|
115
21
|
}
|
|
116
22
|
return 0;
|
|
117
23
|
});
|
|
118
24
|
}
|
|
119
25
|
// Handle single sorter
|
|
120
26
|
if (sorter.field) {
|
|
121
|
-
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
|
|
27
|
+
const field = sorter.field;
|
|
28
|
+
return [...data].sort((a, b) => {
|
|
29
|
+
const aValue = a[field];
|
|
30
|
+
const bValue = b[field];
|
|
125
31
|
if (sorter.order === "ascend") {
|
|
126
32
|
if (aValue < bValue)
|
|
127
33
|
return -1;
|
|
@@ -139,7 +45,7 @@ var sortData = function (data, sorter) {
|
|
|
139
45
|
return 0;
|
|
140
46
|
});
|
|
141
47
|
}
|
|
142
|
-
return
|
|
48
|
+
return [...data];
|
|
143
49
|
};
|
|
144
50
|
/*
|
|
145
51
|
Example of disableRowSelection function which can be passed to the useTable hook
|
|
@@ -148,71 +54,59 @@ const disableRowSelection = (record: any) => ({
|
|
|
148
54
|
name: record.status.toString(),
|
|
149
55
|
});
|
|
150
56
|
*/
|
|
151
|
-
|
|
57
|
+
const defaultRowSelection = (record) => ({
|
|
152
58
|
disabled: false, // Add your disable logic here
|
|
153
59
|
name: record.id,
|
|
154
|
-
});
|
|
155
|
-
export
|
|
156
|
-
|
|
157
|
-
|
|
60
|
+
});
|
|
61
|
+
export const useTable = (useTableConfig) => {
|
|
62
|
+
const [isLoading, setLoading] = useState(true);
|
|
63
|
+
const { columns, filters = null, fetchUrl = "/table/data", fetchOptions = {
|
|
158
64
|
method: "POST",
|
|
159
65
|
headers: {
|
|
160
66
|
"Content-Type": "application/json",
|
|
161
67
|
},
|
|
162
68
|
body: JSON.stringify(filters),
|
|
163
|
-
}
|
|
69
|
+
}, selectionType = "checkbox", simulateDelay = 0, disableRowSelection = defaultRowSelection, disableAutoFetch = false, dataSource: initialDataSource = [], } = useTableConfig;
|
|
164
70
|
// State to hold the original data and the current data
|
|
165
|
-
|
|
166
|
-
|
|
71
|
+
const [originalData, setOriginalData] = useState(initialDataSource);
|
|
72
|
+
const [data, setData] = useState({
|
|
167
73
|
dataSource: initialDataSource,
|
|
168
|
-
columns
|
|
74
|
+
columns,
|
|
169
75
|
error: null,
|
|
170
|
-
})
|
|
171
|
-
|
|
76
|
+
});
|
|
77
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
|
172
78
|
// Load initial data
|
|
173
|
-
useEffect(
|
|
79
|
+
useEffect(() => {
|
|
174
80
|
// If auto-fetch is disabled and we have initial data, skip fetching
|
|
175
81
|
if (disableAutoFetch && initialDataSource.length > 0) {
|
|
176
82
|
setLoading(false);
|
|
177
83
|
return;
|
|
178
84
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
dataSource: [],
|
|
205
|
-
columns: columns,
|
|
206
|
-
error: error_1 instanceof Error ? error_1 : new Error(String(error_1)),
|
|
207
|
-
});
|
|
208
|
-
return [3 /*break*/, 5];
|
|
209
|
-
case 4:
|
|
210
|
-
setLoading(false);
|
|
211
|
-
return [7 /*endfinally*/];
|
|
212
|
-
case 5: return [2 /*return*/];
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}); };
|
|
85
|
+
const fetchData = async () => {
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch(fetchUrl, fetchOptions);
|
|
88
|
+
const result = await response.json();
|
|
89
|
+
const sourceData = result.data || [];
|
|
90
|
+
setOriginalData(sourceData);
|
|
91
|
+
setData({
|
|
92
|
+
dataSource: sourceData,
|
|
93
|
+
columns,
|
|
94
|
+
error: null,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Error fetching table data:", error);
|
|
99
|
+
// Fallback to static data
|
|
100
|
+
setData({
|
|
101
|
+
dataSource: [],
|
|
102
|
+
columns,
|
|
103
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
setLoading(false);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
216
110
|
if (simulateDelay > 0) {
|
|
217
111
|
setTimeout(fetchData, simulateDelay);
|
|
218
112
|
}
|
|
@@ -220,19 +114,28 @@ export var useTable = function (useTableConfig) {
|
|
|
220
114
|
fetchData();
|
|
221
115
|
}
|
|
222
116
|
}, [fetchOptions, disableAutoFetch, initialDataSource]);
|
|
223
|
-
|
|
117
|
+
const handleRowSelection = useCallback((selectedRowKeys, selectedRows) => {
|
|
224
118
|
console.log("Row Selected:", selectedRowKeys, selectedRows);
|
|
225
119
|
setSelectedRows(selectedRows);
|
|
226
120
|
}, []);
|
|
227
121
|
// Function to manually update data source (for external data fetching)
|
|
228
|
-
|
|
122
|
+
const updateDataSource = useCallback((newDataSource) => {
|
|
229
123
|
setOriginalData(newDataSource);
|
|
230
|
-
setData(
|
|
124
|
+
setData((prev) => ({
|
|
125
|
+
...prev,
|
|
126
|
+
dataSource: newDataSource,
|
|
127
|
+
}));
|
|
231
128
|
}, []);
|
|
232
|
-
|
|
129
|
+
const rowSelection = {
|
|
233
130
|
type: selectionType,
|
|
234
131
|
onChange: handleRowSelection,
|
|
235
132
|
getCheckboxProps: disableRowSelection,
|
|
236
133
|
};
|
|
237
|
-
return
|
|
134
|
+
return {
|
|
135
|
+
...data,
|
|
136
|
+
isLoading,
|
|
137
|
+
rowSelection,
|
|
138
|
+
selectedRows,
|
|
139
|
+
updateDataSource,
|
|
140
|
+
};
|
|
238
141
|
};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import TableControls from "../Table/TableControls";
|
|
3
3
|
import Table from "../Table";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var dataSource = tableData.dataSource, columns = tableData.columns, rowSelection = tableData.rowSelection;
|
|
4
|
+
const TableWithControls = ({ tableData, tableControlsData, onChange, }) => {
|
|
5
|
+
const { primaryTableRowData, secondaryTableRowData } = tableControlsData;
|
|
6
|
+
const { dataSource, columns, rowSelection } = tableData;
|
|
8
7
|
// handle changes from the table controls
|
|
9
|
-
|
|
8
|
+
const onTableControlsChange = (event) => {
|
|
10
9
|
onChange(event);
|
|
11
10
|
};
|
|
12
11
|
// handle changes from the table
|
|
13
|
-
|
|
12
|
+
const onTableChange = (pagination, filters, sorter) => {
|
|
14
13
|
onChange({
|
|
15
14
|
event: "tableChange",
|
|
16
|
-
payload: { pagination
|
|
15
|
+
payload: { pagination, filters, sorter },
|
|
17
16
|
});
|
|
18
17
|
};
|
|
19
18
|
return (_jsxs(_Fragment, { children: [_jsx(TableControls, { primaryTableRowData: primaryTableRowData, secondaryTableRowData: secondaryTableRowData, onChange: onTableControlsChange }), _jsx(Table, { dataSource: dataSource, columns: columns, rowSelection: rowSelection, onChange: onTableChange })] }));
|