qbs-react-grid 1.0.51 → 1.1.1
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/es/qbsTable/CustomTableCell.js +4 -2
- package/es/qbsTable/QbsTable.js +4 -1
- package/es/qbsTable/Toolbar.js +6 -2
- package/es/qbsTable/commontypes.d.ts +2 -0
- package/es/qbsTable/utilities/SearchInput.js +1 -1
- package/es/qbsTable/utilities/handleFormatCell.d.ts +1 -0
- package/es/qbsTable/utilities/handleFormatCell.js +46 -0
- package/es/qbsTable/utilities/menuDropDown.js +2 -1
- package/lib/qbsTable/CustomTableCell.js +4 -2
- package/lib/qbsTable/QbsTable.js +4 -1
- package/lib/qbsTable/Toolbar.js +5 -1
- package/lib/qbsTable/commontypes.d.ts +2 -0
- package/lib/qbsTable/utilities/handleFormatCell.d.ts +1 -0
- package/lib/qbsTable/utilities/handleFormatCell.js +51 -0
- package/lib/qbsTable/utilities/menuDropDown.js +2 -1
- package/package.json +1 -1
- package/src/qbsTable/CustomTableCell.tsx +4 -3
- package/src/qbsTable/QbsTable.tsx +4 -1
- package/src/qbsTable/Toolbar.tsx +4 -3
- package/src/qbsTable/commontypes.ts +2 -0
- package/src/qbsTable/utilities/SearchInput.tsx +2 -1
- package/src/qbsTable/utilities/handleFormatCell.ts +45 -0
- package/src/qbsTable/utilities/menuDropDown.tsx +1 -1
|
@@ -2,10 +2,11 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
var _excluded = ["rowData", "onChange", "checkedKeys", "dataKey", "dataTheme"],
|
|
4
4
|
_excluded2 = ["rowData", "dataKey", "expandedRowKeys", "onChange"],
|
|
5
|
-
_excluded3 = ["rowData", "renderCell", "toolTip", "dataKey", "onChange", "rowClick", "link"];
|
|
5
|
+
_excluded3 = ["rowData", "renderCell", "toolTip", "dataKey", "onChange", "rowClick", "type", "link"];
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import Cell from '../Cell';
|
|
8
8
|
import MenuDropDown from './utilities/menuDropDown';
|
|
9
|
+
import { handleCellFormat } from './utilities/handleFormatCell';
|
|
9
10
|
var CHECKBOX_LINE_HEIGHT = '36px';
|
|
10
11
|
export var CheckCell = /*#__PURE__*/React.memo(function (_ref) {
|
|
11
12
|
var rowData = _ref.rowData,
|
|
@@ -78,6 +79,7 @@ export var CustomTableCell = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
78
79
|
dataKey = _ref4.dataKey,
|
|
79
80
|
onChange = _ref4.onChange,
|
|
80
81
|
rowClick = _ref4.rowClick,
|
|
82
|
+
type = _ref4.type,
|
|
81
83
|
link = _ref4.link,
|
|
82
84
|
props = _objectWithoutPropertiesLoose(_ref4, _excluded3);
|
|
83
85
|
return /*#__PURE__*/React.createElement(Cell, _extends({}, props, {
|
|
@@ -87,5 +89,5 @@ export var CustomTableCell = /*#__PURE__*/React.memo(function (_ref4) {
|
|
|
87
89
|
return rowClick === null || rowClick === void 0 ? void 0 : rowClick(rowData);
|
|
88
90
|
},
|
|
89
91
|
className: "qbs-table-row-link"
|
|
90
|
-
}, renderCell ? (_renderCell = renderCell(rowData)) === null || _renderCell === void 0 ? void 0 : _renderCell.cell : rowData[dataKey]) : /*#__PURE__*/React.createElement(React.Fragment, null, (_renderCell2 = renderCell(rowData)) === null || _renderCell2 === void 0 ? void 0 : _renderCell2.cell));
|
|
92
|
+
}, renderCell ? (_renderCell = renderCell(rowData)) === null || _renderCell === void 0 ? void 0 : _renderCell.cell : handleCellFormat(rowData[dataKey], type)) : /*#__PURE__*/React.createElement(React.Fragment, null, renderCell ? (_renderCell2 = renderCell(rowData)) === null || _renderCell2 === void 0 ? void 0 : _renderCell2.cell : handleCellFormat(rowData[dataKey], type)));
|
|
91
93
|
});
|
package/es/qbsTable/QbsTable.js
CHANGED
|
@@ -285,7 +285,8 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
285
285
|
isVisible = _ref3.isVisible,
|
|
286
286
|
link = _ref3.link,
|
|
287
287
|
rowClick = _ref3.rowClick,
|
|
288
|
-
sortKey = _ref3.sortKey
|
|
288
|
+
sortKey = _ref3.sortKey,
|
|
289
|
+
type = _ref3.type;
|
|
289
290
|
return /*#__PURE__*/React.createElement(React.Fragment, null, isVisible && /*#__PURE__*/React.createElement(React.Fragment, null, grouped ? /*#__PURE__*/React.createElement(ColumnGroup, {
|
|
290
291
|
header: groupheader,
|
|
291
292
|
fixed: fixed,
|
|
@@ -310,6 +311,7 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
310
311
|
renderCell: child.renderCell,
|
|
311
312
|
dataKey: child.field,
|
|
312
313
|
dataTheme: dataTheme,
|
|
314
|
+
type: child.type,
|
|
313
315
|
link: child.link
|
|
314
316
|
}) : /*#__PURE__*/React.createElement(Cell, {
|
|
315
317
|
className: " " + classes.cellClass,
|
|
@@ -332,6 +334,7 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
332
334
|
renderCell: renderCell,
|
|
333
335
|
dataKey: field,
|
|
334
336
|
rowClick: rowClick,
|
|
337
|
+
type: type,
|
|
335
338
|
dataTheme: dataTheme,
|
|
336
339
|
link: link
|
|
337
340
|
}) : /*#__PURE__*/React.createElement(Cell, {
|
package/es/qbsTable/Toolbar.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
2
|
import debounce from './utilities/debounce';
|
|
3
3
|
import SearchInput from './utilities/SearchInput';
|
|
4
4
|
import { getRowDisplayRange } from './utilities/tablecalc';
|
|
@@ -21,12 +21,16 @@ var ToolBar = function ToolBar(_ref) {
|
|
|
21
21
|
onSelect = _ref.onSelect,
|
|
22
22
|
dataLength = _ref.dataLength;
|
|
23
23
|
var debouncedOnSearch = useCallback(debounce(onSearch != null ? onSearch : function () {}, 1000), [onSearch]);
|
|
24
|
+
var _useState = useState(searchValue),
|
|
25
|
+
searchParam = _useState[0],
|
|
26
|
+
setSearchParam = _useState[1];
|
|
24
27
|
var handleSearch = useCallback(function (e) {
|
|
25
28
|
if (debouncedOnSearch) {
|
|
26
29
|
debouncedOnSearch(e);
|
|
27
30
|
}
|
|
28
31
|
}, [debouncedOnSearch]);
|
|
29
32
|
var handleChange = useCallback(function (e) {
|
|
33
|
+
setSearchParam(e);
|
|
30
34
|
if (asyncSearch) {
|
|
31
35
|
handleSearch(e);
|
|
32
36
|
} else {
|
|
@@ -56,7 +60,7 @@ var ToolBar = function ToolBar(_ref) {
|
|
|
56
60
|
placeholder: "Search",
|
|
57
61
|
handleChange: handleChange,
|
|
58
62
|
handleSearch: handleSearch,
|
|
59
|
-
searchValue:
|
|
63
|
+
searchValue: searchParam
|
|
60
64
|
}), /*#__PURE__*/React.createElement("div", {
|
|
61
65
|
className: "qbs-table-primary-filter"
|
|
62
66
|
}, primaryFilter)), /*#__PURE__*/React.createElement("div", {
|
|
@@ -17,6 +17,7 @@ export interface ColumnBase {
|
|
|
17
17
|
link?: boolean;
|
|
18
18
|
rowClick?: (rowData: any) => void;
|
|
19
19
|
sortKey?: string;
|
|
20
|
+
type?: string;
|
|
20
21
|
}
|
|
21
22
|
export interface QbsColumnProps extends ColumnBase {
|
|
22
23
|
grouped?: boolean;
|
|
@@ -38,6 +39,7 @@ export interface ActionProps {
|
|
|
38
39
|
icon: React.ReactNode;
|
|
39
40
|
toolTip?: string;
|
|
40
41
|
hidden?: boolean;
|
|
42
|
+
hide?: (data: any) => boolean;
|
|
41
43
|
}
|
|
42
44
|
export interface QbsTableProps {
|
|
43
45
|
isLoading?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const handleCellFormat: (data: any, type: string) => any;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var convertDateFormat = function convertDateFormat(input, type) {
|
|
2
|
+
// Splitting the string by space to separate date and time
|
|
3
|
+
if (input && input !== null) {
|
|
4
|
+
var parts = input.split(' ');
|
|
5
|
+
var datePart = parts[0];
|
|
6
|
+
var timePart = parts.length > 1 ? " " + parts[1] : '';
|
|
7
|
+
|
|
8
|
+
// Splitting the date into [month, day, year]
|
|
9
|
+
var separator = datePart.includes('-') ? '-' : '/';
|
|
10
|
+
var dateComponents = datePart.split(separator);
|
|
11
|
+
if (dateComponents.length !== 3) {
|
|
12
|
+
// Invalid date format
|
|
13
|
+
return input;
|
|
14
|
+
}
|
|
15
|
+
var day, month, year;
|
|
16
|
+
if (dateComponents.length === 3) {
|
|
17
|
+
if (dateComponents[0].length === 4) {
|
|
18
|
+
// Format: yyyy/mm/dd
|
|
19
|
+
year = dateComponents[0];
|
|
20
|
+
month = dateComponents[1];
|
|
21
|
+
day = dateComponents[2];
|
|
22
|
+
} else {
|
|
23
|
+
// Format: mm/dd/yyyy
|
|
24
|
+
month = dateComponents[0];
|
|
25
|
+
day = dateComponents[1];
|
|
26
|
+
year = dateComponents[2];
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return input; // Invalid date format
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Rearranging to day/month/year format
|
|
33
|
+
return type === 'dateTime' ? day + "-" + month + "-" + year + " " + timePart : day + "-" + month + "-" + year;
|
|
34
|
+
} else {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export var handleCellFormat = function handleCellFormat(data, type) {
|
|
39
|
+
switch (type) {
|
|
40
|
+
case 'date':
|
|
41
|
+
case 'dateTime':
|
|
42
|
+
return convertDateFormat(data, type);
|
|
43
|
+
default:
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -41,7 +41,8 @@ var MenuDropDown = function MenuDropDown(_ref) {
|
|
|
41
41
|
}, /*#__PURE__*/React.createElement(ThreeDotIcon, null)), openMenu && /*#__PURE__*/React.createElement("div", {
|
|
42
42
|
className: 'qbs-table-qbs-table-menu-dropdown-content'
|
|
43
43
|
}, actionDropDown === null || actionDropDown === void 0 ? void 0 : actionDropDown.map(function (item) {
|
|
44
|
-
|
|
44
|
+
var _item$hide;
|
|
45
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, !(item !== null && item !== void 0 && item.hidden) && !(item !== null && item !== void 0 && (_item$hide = item.hide) !== null && _item$hide !== void 0 && _item$hide.call(item, rowData)) && /*#__PURE__*/React.createElement("a", {
|
|
45
46
|
key: item.title,
|
|
46
47
|
className: "p-2 leading-7 hover:bg-background ",
|
|
47
48
|
onClick: function onClick(e) {
|
|
@@ -8,9 +8,10 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _Cell = _interopRequireDefault(require("../Cell"));
|
|
10
10
|
var _menuDropDown = _interopRequireDefault(require("./utilities/menuDropDown"));
|
|
11
|
+
var _handleFormatCell = require("./utilities/handleFormatCell");
|
|
11
12
|
var _excluded = ["rowData", "onChange", "checkedKeys", "dataKey", "dataTheme"],
|
|
12
13
|
_excluded2 = ["rowData", "dataKey", "expandedRowKeys", "onChange"],
|
|
13
|
-
_excluded3 = ["rowData", "renderCell", "toolTip", "dataKey", "onChange", "rowClick", "link"];
|
|
14
|
+
_excluded3 = ["rowData", "renderCell", "toolTip", "dataKey", "onChange", "rowClick", "type", "link"];
|
|
14
15
|
var CHECKBOX_LINE_HEIGHT = '36px';
|
|
15
16
|
var CheckCell = /*#__PURE__*/_react["default"].memo(function (_ref) {
|
|
16
17
|
var rowData = _ref.rowData,
|
|
@@ -86,6 +87,7 @@ var CustomTableCell = /*#__PURE__*/_react["default"].memo(function (_ref4) {
|
|
|
86
87
|
dataKey = _ref4.dataKey,
|
|
87
88
|
onChange = _ref4.onChange,
|
|
88
89
|
rowClick = _ref4.rowClick,
|
|
90
|
+
type = _ref4.type,
|
|
89
91
|
link = _ref4.link,
|
|
90
92
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref4, _excluded3);
|
|
91
93
|
return /*#__PURE__*/_react["default"].createElement(_Cell["default"], (0, _extends2["default"])({}, props, {
|
|
@@ -95,6 +97,6 @@ var CustomTableCell = /*#__PURE__*/_react["default"].memo(function (_ref4) {
|
|
|
95
97
|
return rowClick === null || rowClick === void 0 ? void 0 : rowClick(rowData);
|
|
96
98
|
},
|
|
97
99
|
className: "qbs-table-row-link"
|
|
98
|
-
}, renderCell ? (_renderCell = renderCell(rowData)) === null || _renderCell === void 0 ? void 0 : _renderCell.cell : rowData[dataKey]) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, (_renderCell2 = renderCell(rowData)) === null || _renderCell2 === void 0 ? void 0 : _renderCell2.cell));
|
|
100
|
+
}, renderCell ? (_renderCell = renderCell(rowData)) === null || _renderCell === void 0 ? void 0 : _renderCell.cell : (0, _handleFormatCell.handleCellFormat)(rowData[dataKey], type)) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, renderCell ? (_renderCell2 = renderCell(rowData)) === null || _renderCell2 === void 0 ? void 0 : _renderCell2.cell : (0, _handleFormatCell.handleCellFormat)(rowData[dataKey], type)));
|
|
99
101
|
});
|
|
100
102
|
exports.CustomTableCell = CustomTableCell;
|
package/lib/qbsTable/QbsTable.js
CHANGED
|
@@ -292,7 +292,8 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
292
292
|
isVisible = _ref3.isVisible,
|
|
293
293
|
link = _ref3.link,
|
|
294
294
|
rowClick = _ref3.rowClick,
|
|
295
|
-
sortKey = _ref3.sortKey
|
|
295
|
+
sortKey = _ref3.sortKey,
|
|
296
|
+
type = _ref3.type;
|
|
296
297
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, isVisible && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, grouped ? /*#__PURE__*/_react["default"].createElement(_ColumnGroup["default"], {
|
|
297
298
|
header: groupheader,
|
|
298
299
|
fixed: fixed,
|
|
@@ -317,6 +318,7 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
317
318
|
renderCell: child.renderCell,
|
|
318
319
|
dataKey: child.field,
|
|
319
320
|
dataTheme: dataTheme,
|
|
321
|
+
type: child.type,
|
|
320
322
|
link: child.link
|
|
321
323
|
}) : /*#__PURE__*/_react["default"].createElement(_Cell["default"], {
|
|
322
324
|
className: " " + classes.cellClass,
|
|
@@ -339,6 +341,7 @@ var QbsTable = function QbsTable(_ref) {
|
|
|
339
341
|
renderCell: renderCell,
|
|
340
342
|
dataKey: field,
|
|
341
343
|
rowClick: rowClick,
|
|
344
|
+
type: type,
|
|
342
345
|
dataTheme: dataTheme,
|
|
343
346
|
link: link
|
|
344
347
|
}) : /*#__PURE__*/_react["default"].createElement(_Cell["default"], {
|
package/lib/qbsTable/Toolbar.js
CHANGED
|
@@ -28,12 +28,16 @@ var ToolBar = function ToolBar(_ref) {
|
|
|
28
28
|
onSelect = _ref.onSelect,
|
|
29
29
|
dataLength = _ref.dataLength;
|
|
30
30
|
var debouncedOnSearch = (0, _react.useCallback)((0, _debounce["default"])(onSearch != null ? onSearch : function () {}, 1000), [onSearch]);
|
|
31
|
+
var _useState = (0, _react.useState)(searchValue),
|
|
32
|
+
searchParam = _useState[0],
|
|
33
|
+
setSearchParam = _useState[1];
|
|
31
34
|
var handleSearch = (0, _react.useCallback)(function (e) {
|
|
32
35
|
if (debouncedOnSearch) {
|
|
33
36
|
debouncedOnSearch(e);
|
|
34
37
|
}
|
|
35
38
|
}, [debouncedOnSearch]);
|
|
36
39
|
var handleChange = (0, _react.useCallback)(function (e) {
|
|
40
|
+
setSearchParam(e);
|
|
37
41
|
if (asyncSearch) {
|
|
38
42
|
handleSearch(e);
|
|
39
43
|
} else {
|
|
@@ -63,7 +67,7 @@ var ToolBar = function ToolBar(_ref) {
|
|
|
63
67
|
placeholder: "Search",
|
|
64
68
|
handleChange: handleChange,
|
|
65
69
|
handleSearch: handleSearch,
|
|
66
|
-
searchValue:
|
|
70
|
+
searchValue: searchParam
|
|
67
71
|
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
68
72
|
className: "qbs-table-primary-filter"
|
|
69
73
|
}, primaryFilter)), /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -17,6 +17,7 @@ export interface ColumnBase {
|
|
|
17
17
|
link?: boolean;
|
|
18
18
|
rowClick?: (rowData: any) => void;
|
|
19
19
|
sortKey?: string;
|
|
20
|
+
type?: string;
|
|
20
21
|
}
|
|
21
22
|
export interface QbsColumnProps extends ColumnBase {
|
|
22
23
|
grouped?: boolean;
|
|
@@ -38,6 +39,7 @@ export interface ActionProps {
|
|
|
38
39
|
icon: React.ReactNode;
|
|
39
40
|
toolTip?: string;
|
|
40
41
|
hidden?: boolean;
|
|
42
|
+
hide?: (data: any) => boolean;
|
|
41
43
|
}
|
|
42
44
|
export interface QbsTableProps {
|
|
43
45
|
isLoading?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const handleCellFormat: (data: any, type: string) => any;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.handleCellFormat = void 0;
|
|
5
|
+
var convertDateFormat = function convertDateFormat(input, type) {
|
|
6
|
+
// Splitting the string by space to separate date and time
|
|
7
|
+
if (input && input !== null) {
|
|
8
|
+
var parts = input.split(' ');
|
|
9
|
+
var datePart = parts[0];
|
|
10
|
+
var timePart = parts.length > 1 ? " " + parts[1] : '';
|
|
11
|
+
|
|
12
|
+
// Splitting the date into [month, day, year]
|
|
13
|
+
var separator = datePart.includes('-') ? '-' : '/';
|
|
14
|
+
var dateComponents = datePart.split(separator);
|
|
15
|
+
if (dateComponents.length !== 3) {
|
|
16
|
+
// Invalid date format
|
|
17
|
+
return input;
|
|
18
|
+
}
|
|
19
|
+
var day, month, year;
|
|
20
|
+
if (dateComponents.length === 3) {
|
|
21
|
+
if (dateComponents[0].length === 4) {
|
|
22
|
+
// Format: yyyy/mm/dd
|
|
23
|
+
year = dateComponents[0];
|
|
24
|
+
month = dateComponents[1];
|
|
25
|
+
day = dateComponents[2];
|
|
26
|
+
} else {
|
|
27
|
+
// Format: mm/dd/yyyy
|
|
28
|
+
month = dateComponents[0];
|
|
29
|
+
day = dateComponents[1];
|
|
30
|
+
year = dateComponents[2];
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
return input; // Invalid date format
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Rearranging to day/month/year format
|
|
37
|
+
return type === 'dateTime' ? day + "-" + month + "-" + year + " " + timePart : day + "-" + month + "-" + year;
|
|
38
|
+
} else {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var handleCellFormat = function handleCellFormat(data, type) {
|
|
43
|
+
switch (type) {
|
|
44
|
+
case 'date':
|
|
45
|
+
case 'dateTime':
|
|
46
|
+
return convertDateFormat(data, type);
|
|
47
|
+
default:
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.handleCellFormat = handleCellFormat;
|
|
@@ -47,7 +47,8 @@ var MenuDropDown = function MenuDropDown(_ref) {
|
|
|
47
47
|
}, /*#__PURE__*/_react["default"].createElement(_icons.ThreeDotIcon, null)), openMenu && /*#__PURE__*/_react["default"].createElement("div", {
|
|
48
48
|
className: 'qbs-table-qbs-table-menu-dropdown-content'
|
|
49
49
|
}, actionDropDown === null || actionDropDown === void 0 ? void 0 : actionDropDown.map(function (item) {
|
|
50
|
-
|
|
50
|
+
var _item$hide;
|
|
51
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !(item !== null && item !== void 0 && item.hidden) && !(item !== null && item !== void 0 && (_item$hide = item.hide) !== null && _item$hide !== void 0 && _item$hide.call(item, rowData)) && /*#__PURE__*/_react["default"].createElement("a", {
|
|
51
52
|
key: item.title,
|
|
52
53
|
className: "p-2 leading-7 hover:bg-background ",
|
|
53
54
|
onClick: function onClick(e) {
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import Cell from '../Cell';
|
|
4
4
|
import MenuDropDown from './utilities/menuDropDown';
|
|
5
|
+
import { handleCellFormat } from './utilities/handleFormatCell';
|
|
5
6
|
|
|
6
7
|
const CHECKBOX_LINE_HEIGHT = '36px';
|
|
7
8
|
|
|
@@ -61,15 +62,15 @@ export const ExpandCell: React.FC<any> = React.memo(
|
|
|
61
62
|
)
|
|
62
63
|
);
|
|
63
64
|
export const CustomTableCell: React.FC<any> = React.memo(
|
|
64
|
-
({ rowData, renderCell, toolTip, dataKey, onChange, rowClick, link, ...props }) => {
|
|
65
|
+
({ rowData, renderCell, toolTip, dataKey, onChange, rowClick, type, link, ...props }) => {
|
|
65
66
|
return (
|
|
66
67
|
<Cell {...props} dataKey={dataKey}>
|
|
67
68
|
{link ? (
|
|
68
69
|
<a onClick={() => rowClick?.(rowData)} className="qbs-table-row-link">
|
|
69
|
-
{renderCell ? renderCell(rowData)?.cell : rowData[dataKey]}
|
|
70
|
+
{renderCell ? renderCell(rowData)?.cell : handleCellFormat(rowData[dataKey], type)}
|
|
70
71
|
</a>
|
|
71
72
|
) : (
|
|
72
|
-
<>{renderCell(rowData)?.cell}</>
|
|
73
|
+
<>{renderCell ? renderCell(rowData)?.cell : handleCellFormat(rowData[dataKey], type)}</>
|
|
73
74
|
)}
|
|
74
75
|
</Cell>
|
|
75
76
|
);
|
|
@@ -277,7 +277,8 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
277
277
|
isVisible,
|
|
278
278
|
link,
|
|
279
279
|
rowClick,
|
|
280
|
-
sortKey
|
|
280
|
+
sortKey,
|
|
281
|
+
type
|
|
281
282
|
}) => (
|
|
282
283
|
<>
|
|
283
284
|
{isVisible && (
|
|
@@ -313,6 +314,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
313
314
|
renderCell={child.renderCell}
|
|
314
315
|
dataKey={child.field}
|
|
315
316
|
dataTheme={dataTheme}
|
|
317
|
+
type={child.type}
|
|
316
318
|
link={child.link}
|
|
317
319
|
/>
|
|
318
320
|
) : (
|
|
@@ -348,6 +350,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
348
350
|
renderCell={renderCell}
|
|
349
351
|
dataKey={field}
|
|
350
352
|
rowClick={rowClick}
|
|
353
|
+
type={type}
|
|
351
354
|
dataTheme={dataTheme}
|
|
352
355
|
link={link}
|
|
353
356
|
/>
|
package/src/qbsTable/Toolbar.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { QbsTableToolbarProps } from './commontypes';
|
|
4
4
|
import debounce from './utilities/debounce';
|
|
@@ -23,7 +23,7 @@ const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
|
23
23
|
dataLength
|
|
24
24
|
}) => {
|
|
25
25
|
const debouncedOnSearch = useCallback(debounce(onSearch ?? (() => {}), 1000), [onSearch]);
|
|
26
|
-
|
|
26
|
+
const [searchParam, setSearchParam] = useState<string | undefined>(searchValue);
|
|
27
27
|
const handleSearch = useCallback(
|
|
28
28
|
(e?: string) => {
|
|
29
29
|
if (debouncedOnSearch) {
|
|
@@ -35,6 +35,7 @@ const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
|
35
35
|
|
|
36
36
|
const handleChange = useCallback(
|
|
37
37
|
(e?: string) => {
|
|
38
|
+
setSearchParam(e);
|
|
38
39
|
if (asyncSearch) {
|
|
39
40
|
handleSearch(e);
|
|
40
41
|
} else {
|
|
@@ -61,7 +62,7 @@ const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
|
61
62
|
placeholder="Search"
|
|
62
63
|
handleChange={handleChange}
|
|
63
64
|
handleSearch={handleSearch}
|
|
64
|
-
searchValue={
|
|
65
|
+
searchValue={searchParam}
|
|
65
66
|
/>
|
|
66
67
|
)}
|
|
67
68
|
<div className="qbs-table-primary-filter">{primaryFilter}</div>
|
|
@@ -18,6 +18,7 @@ export interface ColumnBase {
|
|
|
18
18
|
link?: boolean;
|
|
19
19
|
rowClick?: (rowData: any) => void;
|
|
20
20
|
sortKey?: string;
|
|
21
|
+
type?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export interface QbsColumnProps extends ColumnBase {
|
|
@@ -42,6 +43,7 @@ export interface ActionProps {
|
|
|
42
43
|
icon: React.ReactNode;
|
|
43
44
|
toolTip?: string;
|
|
44
45
|
hidden?: boolean;
|
|
46
|
+
hide?: (data: any) => boolean;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export interface QbsTableProps {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const convertDateFormat = (input: string, type?: string): string => {
|
|
2
|
+
// Splitting the string by space to separate date and time
|
|
3
|
+
if (input && input !== null) {
|
|
4
|
+
const parts = input.split(' ');
|
|
5
|
+
const datePart = parts[0];
|
|
6
|
+
const timePart = parts.length > 1 ? ` ${parts[1]}` : '';
|
|
7
|
+
|
|
8
|
+
// Splitting the date into [month, day, year]
|
|
9
|
+
const separator = datePart.includes('-') ? '-' : '/';
|
|
10
|
+
|
|
11
|
+
const dateComponents = datePart.split(separator);
|
|
12
|
+
|
|
13
|
+
if (dateComponents.length !== 3) {
|
|
14
|
+
// Invalid date format
|
|
15
|
+
return input;
|
|
16
|
+
}
|
|
17
|
+
let day, month, year;
|
|
18
|
+
if (dateComponents.length === 3) {
|
|
19
|
+
if (dateComponents[0].length === 4) {
|
|
20
|
+
// Format: yyyy/mm/dd
|
|
21
|
+
[year, month, day] = dateComponents;
|
|
22
|
+
} else {
|
|
23
|
+
// Format: mm/dd/yyyy
|
|
24
|
+
[month, day, year] = dateComponents;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
return input; // Invalid date format
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Rearranging to day/month/year format
|
|
31
|
+
return type === 'dateTime' ? `${day}-${month}-${year} ${timePart}` : `${day}-${month}-${year}`;
|
|
32
|
+
} else {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const handleCellFormat = (data: any, type: string) => {
|
|
38
|
+
switch (type) {
|
|
39
|
+
case 'date':
|
|
40
|
+
case 'dateTime':
|
|
41
|
+
return convertDateFormat(data, type);
|
|
42
|
+
default:
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -50,7 +50,7 @@ const MenuDropDown: React.FC<Props> = ({ actionDropDown, handleMenuActions, rowD
|
|
|
50
50
|
<div className={'qbs-table-qbs-table-menu-dropdown-content'}>
|
|
51
51
|
{actionDropDown?.map(item => (
|
|
52
52
|
<>
|
|
53
|
-
{!item
|
|
53
|
+
{!item?.hidden && !item?.hide?.(rowData) && (
|
|
54
54
|
<a
|
|
55
55
|
key={item.title}
|
|
56
56
|
className={`p-2 leading-7 hover:bg-background `}
|