ar-design 0.4.7 → 0.4.9
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.
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import "../../../assets/css/components/data-display/chip/chip.css";
|
|
4
4
|
import Utils from "../../../libs/infrastructure/shared/Utils";
|
|
5
|
-
const Chip = ({ variant = "outlined", color = "light", border = { radius: "sm" }, text, icon }) => {
|
|
5
|
+
const Chip = ({ variant = "outlined", color = "light", customColor, border = { radius: "sm" }, text, icon, }) => {
|
|
6
6
|
let _chipClassName = ["ar-chip"];
|
|
7
7
|
_chipClassName.push(...Utils.GetClassName(variant, undefined, color, border, undefined, undefined, undefined));
|
|
8
|
-
return (React.createElement("div", { className: _chipClassName.map((c) => c).join(" ")
|
|
8
|
+
return (React.createElement("div", { className: _chipClassName.map((c) => c).join(" "), ...(customColor && {
|
|
9
|
+
style: {
|
|
10
|
+
backgroundColor: customColor,
|
|
11
|
+
color: "var(--black)",
|
|
12
|
+
},
|
|
13
|
+
}) },
|
|
9
14
|
icon?.element && React.createElement("span", null, icon?.element),
|
|
10
15
|
React.createElement("span", null, text)));
|
|
11
16
|
};
|
|
@@ -44,6 +44,9 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
44
44
|
const _searchTimeOut = useRef(null);
|
|
45
45
|
// refs -> Filter
|
|
46
46
|
const _filterButton = useRef([]);
|
|
47
|
+
// refs -> Selection
|
|
48
|
+
const _selectionItems = useRef([]);
|
|
49
|
+
const lastSentRef = useRef([]);
|
|
47
50
|
// variables
|
|
48
51
|
const _subrowOpenAutomatically = config.subrow?.openAutomatically ?? false;
|
|
49
52
|
const _subrowSelector = config.subrow?.selector ?? "subitems";
|
|
@@ -52,7 +55,6 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
52
55
|
const _tableClassName = ["ar-table", "scroll"];
|
|
53
56
|
// states
|
|
54
57
|
const [selectAll, setSelectAll] = useState(false);
|
|
55
|
-
const [selectionItems, setSelectionItems] = useState([]);
|
|
56
58
|
const [showSubitems, setShowSubitems] = useState({});
|
|
57
59
|
const [rowHeights, setRowHeights] = useState([]);
|
|
58
60
|
// states -> File
|
|
@@ -76,6 +78,8 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
76
78
|
const [totalRecords, setTotalRecords] = useState(0);
|
|
77
79
|
const [currentPage, setCurrentPage] = useState(1);
|
|
78
80
|
const [selectedPerPage, setSelectedPerPage] = useState(pagination?.perPage ?? 10);
|
|
81
|
+
// states -> Selection
|
|
82
|
+
const [_, setTriggerForRender] = useState(false);
|
|
79
83
|
// states -> Mobil
|
|
80
84
|
const [isMobile, setIsMobile] = useState(false);
|
|
81
85
|
// hooks
|
|
@@ -371,11 +375,18 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
371
375
|
_tBodyTR.current[index] = element;
|
|
372
376
|
}, style: { ..._rowColor }, ...(onDnD && data.length > 1 ? { className: "draggable", draggable: true } : {}) },
|
|
373
377
|
selections && (React.createElement("td", { className: "flex justify-content-center sticky-left", "data-sticky-position": "left" },
|
|
374
|
-
React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), variant: "filled", color: "green", checked:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
378
|
+
React.createElement(Checkbox, { key: Date.now(), ref: (element) => (_checkboxItems.current[index] = element), variant: "filled", color: "green", checked: _selectionItems.current.some((selectionItem) => trackBy?.(selectionItem) === trackBy?.(item)), onChange: (event) => {
|
|
379
|
+
const key = trackBy?.(item);
|
|
380
|
+
if (event.target.checked) {
|
|
381
|
+
if (!_selectionItems.current.some((_item) => trackBy?.(_item) === key)) {
|
|
382
|
+
_selectionItems.current = [..._selectionItems.current, item];
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
_selectionItems.current = _selectionItems.current.filter((_item) => trackBy?.(_item) !== key);
|
|
387
|
+
}
|
|
388
|
+
selections(_selectionItems.current);
|
|
389
|
+
setTriggerForRender((prev) => !prev);
|
|
379
390
|
} }))),
|
|
380
391
|
isHasSubitems && _subrowButton ? (React.createElement("td", null, item[_subrowSelector] && (React.createElement("div", { className: "subitem-open-button-wrapper" },
|
|
381
392
|
React.createElement("span", { className: `subitem-open-button ${(showSubitems[index] && "opened") ?? ""}`, onClick: () => {
|
|
@@ -464,17 +475,16 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
464
475
|
}, [getData, columns, showSubitems, rowHeights]);
|
|
465
476
|
// useEffects
|
|
466
477
|
useEffect(() => {
|
|
467
|
-
if (
|
|
468
|
-
|
|
469
|
-
if (previousSelections && previousSelections.length > 0) {
|
|
470
|
-
const validSelections = data.filter((item) => previousSelections.some((selected) => trackBy?.(selected) === trackBy?.(item)));
|
|
471
|
-
setSelectionItems(validSelections);
|
|
478
|
+
if (!previousSelections || previousSelections.length === 0) {
|
|
479
|
+
_selectionItems.current = [];
|
|
472
480
|
return;
|
|
473
481
|
}
|
|
474
|
-
|
|
475
|
-
|
|
482
|
+
const validSelections = data.filter((item) => previousSelections.some((selected) => trackBy?.(selected) === trackBy?.(item)));
|
|
483
|
+
// Gereksiz overwrite’i engelle
|
|
484
|
+
if (!Utils.DeepEqual(_selectionItems.current, validSelections)) {
|
|
485
|
+
_selectionItems.current = validSelections;
|
|
476
486
|
}
|
|
477
|
-
}, [previousSelections, data]);
|
|
487
|
+
}, [previousSelections, data, trackBy]);
|
|
478
488
|
useEffect(() => {
|
|
479
489
|
if (config?.isServerSide && searchedParams) {
|
|
480
490
|
const searchRecord = {};
|
|
@@ -517,14 +527,17 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
517
527
|
pagination.onChange?.(1, selectedPerPage);
|
|
518
528
|
}, [checkboxSelectedParams]);
|
|
519
529
|
useEffect(() => {
|
|
520
|
-
if (typeof selections
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
530
|
+
if (typeof selections !== "function")
|
|
531
|
+
return;
|
|
532
|
+
const payload = _selectionItems.current.map((item) => ({
|
|
533
|
+
...item,
|
|
534
|
+
trackByValue: trackBy?.(item),
|
|
535
|
+
}));
|
|
536
|
+
if (!Utils.DeepEqual(payload, lastSentRef.current)) {
|
|
537
|
+
lastSentRef.current = payload;
|
|
538
|
+
selections(payload);
|
|
526
539
|
}
|
|
527
|
-
}, [
|
|
540
|
+
}, [selections, trackBy]);
|
|
528
541
|
useEffect(() => {
|
|
529
542
|
// Filter Content alanı re-render işlemi.
|
|
530
543
|
if (filterCurrentColumn && filterCurrentDataType) {
|