hi-tm 0.10.4 → 0.10.6
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.
|
@@ -300,73 +300,114 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
300
300
|
// }
|
|
301
301
|
// };
|
|
302
302
|
// Function to determine if a row has any descendants selected (not just direct children)
|
|
303
|
+
// const isIndeterminate = (rowId: number): boolean => {
|
|
304
|
+
// // Find the row in the data
|
|
305
|
+
// const findRow = (
|
|
306
|
+
// rows: TableRowData[] | undefined,
|
|
307
|
+
// id: number
|
|
308
|
+
// ): TableRowData | null => {
|
|
309
|
+
// if (!rows) return null;
|
|
310
|
+
// for (const row of rows) {
|
|
311
|
+
// if (row.id === id) return row;
|
|
312
|
+
// if (row.hasChildren && row.childRows) {
|
|
313
|
+
// const found = findRow(row.childRows, id);
|
|
314
|
+
// if (found) return found;
|
|
315
|
+
// }
|
|
316
|
+
// }
|
|
317
|
+
// return null;
|
|
318
|
+
// };
|
|
319
|
+
// const row = findRow(rows!, rowId);
|
|
320
|
+
// // If row has no children, it can't be indeterminate
|
|
321
|
+
// if (
|
|
322
|
+
// !row ||
|
|
323
|
+
// !row.hasChildren ||
|
|
324
|
+
// !row.childRows ||
|
|
325
|
+
// row.childRows.length === 0
|
|
326
|
+
// ) {
|
|
327
|
+
// return false;
|
|
328
|
+
// }
|
|
329
|
+
// // Check if the row itself is selected
|
|
330
|
+
// const isRowSelected = selectedRows.includes(rowId);
|
|
331
|
+
// // Recursively check if any descendant is selected
|
|
332
|
+
// const hasSelectedDescendant = (children: TableRowData[]): boolean => {
|
|
333
|
+
// for (const child of children) {
|
|
334
|
+
// // If any child is selected
|
|
335
|
+
// if (selectedRows.includes(child.id)) {
|
|
336
|
+
// return true;
|
|
337
|
+
// }
|
|
338
|
+
// // Check grandchildren if they exist
|
|
339
|
+
// if (
|
|
340
|
+
// child.hasChildren &&
|
|
341
|
+
// child.childRows &&
|
|
342
|
+
// child.childRows.length > 0
|
|
343
|
+
// ) {
|
|
344
|
+
// if (hasSelectedDescendant(child.childRows)) {
|
|
345
|
+
// return true;
|
|
346
|
+
// }
|
|
347
|
+
// }
|
|
348
|
+
// }
|
|
349
|
+
// return false;
|
|
350
|
+
// };
|
|
351
|
+
// // Check if all descendants are selected
|
|
352
|
+
// const areAllDescendantsSelected = (children: TableRowData[]): boolean => {
|
|
353
|
+
// for (const child of children) {
|
|
354
|
+
// // If any child is not selected
|
|
355
|
+
// if (!selectedRows.includes(child.id)) {
|
|
356
|
+
// return false;
|
|
357
|
+
// }
|
|
358
|
+
// // Check grandchildren if they exist
|
|
359
|
+
// if (
|
|
360
|
+
// child.hasChildren &&
|
|
361
|
+
// child.childRows &&
|
|
362
|
+
// child.childRows.length > 0
|
|
363
|
+
// ) {
|
|
364
|
+
// if (!areAllDescendantsSelected(child.childRows)) {
|
|
365
|
+
// return false;
|
|
366
|
+
// }
|
|
367
|
+
// }
|
|
368
|
+
// }
|
|
369
|
+
// return true;
|
|
370
|
+
// };
|
|
371
|
+
// const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
372
|
+
// const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
373
|
+
// // Indeterminate if some but not all descendants are selected
|
|
374
|
+
// // Or if the parent is not selected but some children are
|
|
375
|
+
// return (
|
|
376
|
+
// (hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected)
|
|
377
|
+
// );
|
|
378
|
+
// };
|
|
303
379
|
const isIndeterminate = (rowId) => {
|
|
304
|
-
//
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
!row.childRows ||
|
|
324
|
-
row.childRows.length === 0) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
// Check if the row itself is selected
|
|
328
|
-
const isRowSelected = selectedRows.includes(rowId);
|
|
329
|
-
// Recursively check if any descendant is selected
|
|
330
|
-
const hasSelectedDescendant = (children) => {
|
|
331
|
-
for (const child of children) {
|
|
332
|
-
// If any child is selected
|
|
333
|
-
if (selectedRows.includes(child.id)) {
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
// Check grandchildren if they exist
|
|
337
|
-
if (child.hasChildren &&
|
|
338
|
-
child.childRows &&
|
|
339
|
-
child.childRows.length > 0) {
|
|
340
|
-
if (hasSelectedDescendant(child.childRows)) {
|
|
380
|
+
// ذخیره نتایج برای هر ردیف تا دوباره محاسبه نشه
|
|
381
|
+
const memo = new Map();
|
|
382
|
+
const checkIndeterminate = (row) => {
|
|
383
|
+
if (!row.childRows?.length)
|
|
384
|
+
return false;
|
|
385
|
+
if (memo.has(row.id))
|
|
386
|
+
return memo.get(row.id);
|
|
387
|
+
let total = 0;
|
|
388
|
+
let selected = 0;
|
|
389
|
+
for (const child of row.childRows) {
|
|
390
|
+
total += 1;
|
|
391
|
+
if (selectedRows.includes(child.id))
|
|
392
|
+
selected += 1;
|
|
393
|
+
// بررسی بازگشتی فرزندان
|
|
394
|
+
if (child.childRows?.length) {
|
|
395
|
+
const childIndeterminate = checkIndeterminate(child);
|
|
396
|
+
if (childIndeterminate) {
|
|
397
|
+
// اگر هر descendant indeterminate بود، خود row هم indeterminate است
|
|
398
|
+
memo.set(row.id, true);
|
|
341
399
|
return true;
|
|
342
400
|
}
|
|
343
401
|
}
|
|
344
402
|
}
|
|
345
|
-
|
|
403
|
+
const isIndet = selected > 0 && selected < total;
|
|
404
|
+
memo.set(row.id, isIndet);
|
|
405
|
+
return isIndet;
|
|
346
406
|
};
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (!selectedRows.includes(child.id)) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
// Check grandchildren if they exist
|
|
355
|
-
if (child.hasChildren &&
|
|
356
|
-
child.childRows &&
|
|
357
|
-
child.childRows.length > 0) {
|
|
358
|
-
if (!areAllDescendantsSelected(child.childRows)) {
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return true;
|
|
364
|
-
};
|
|
365
|
-
const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
366
|
-
const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
367
|
-
// Indeterminate if some but not all descendants are selected
|
|
368
|
-
// Or if the parent is not selected but some children are
|
|
369
|
-
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
407
|
+
const row = rows?.find((r) => r.id === rowId);
|
|
408
|
+
if (!row)
|
|
409
|
+
return false;
|
|
410
|
+
return checkIndeterminate(row);
|
|
370
411
|
};
|
|
371
412
|
// Function to check if a row is selected
|
|
372
413
|
const isSelected = (rowId) => {
|
|
@@ -73,7 +73,6 @@ interface ModernTableHeaderProps {
|
|
|
73
73
|
}) => void;
|
|
74
74
|
hasSelect?: boolean;
|
|
75
75
|
hasCheckbox?: boolean;
|
|
76
|
-
hasSelectAll?: boolean;
|
|
77
76
|
onCheckboxClick?: (checked: boolean) => void;
|
|
78
77
|
onClickHandlerColumn?: (params: {
|
|
79
78
|
name: string;
|
|
@@ -102,5 +101,5 @@ interface ModernTableHeaderProps {
|
|
|
102
101
|
isMobileView?: boolean;
|
|
103
102
|
mobileViewGridClassName?: string;
|
|
104
103
|
}
|
|
105
|
-
declare const ModernTableHeader: ({ columns, sortIcon, hasSelect, hasCheckbox,
|
|
104
|
+
declare const ModernTableHeader: ({ columns, sortIcon, hasSelect, hasCheckbox, onCheckboxClick, onClickHandlerColumn, filterHandler, onSelectAllClick, FilterIcon, onFilterClick, onSortingClick, onPinClick, onFilterButtonClick, gridClassName, containerClassName, isMobileView, mobileViewGridClassName, }: ModernTableHeaderProps) => React.JSX.Element;
|
|
106
105
|
export default ModernTableHeader;
|
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
const react_1 = __importStar(require("react"));
|
|
41
41
|
const image_1 = __importDefault(require("next/image"));
|
|
42
|
-
const ModernTableHeader = ({ columns = [], sortIcon, hasSelect = false, hasCheckbox = false,
|
|
42
|
+
const ModernTableHeader = ({ columns = [], sortIcon, hasSelect = false, hasCheckbox = false, onCheckboxClick, onClickHandlerColumn, filterHandler, onSelectAllClick, FilterIcon, onFilterClick, onSortingClick, onPinClick, onFilterButtonClick, gridClassName, containerClassName, isMobileView, mobileViewGridClassName, }) => {
|
|
43
43
|
const [activeFilterColumn, setActiveFilterColumn] = (0, react_1.useState)(null);
|
|
44
44
|
const [clickedColumn, setClickedColumn] = (0, react_1.useState)(null);
|
|
45
45
|
const [arrowDir, setArrowDir] = (0, react_1.useState)(false);
|
|
@@ -50,12 +50,6 @@ const ModernTableHeader = ({ columns = [], sortIcon, hasSelect = false, hasCheck
|
|
|
50
50
|
const [checkedPins, setCheckedPins] = (0, react_1.useState)({});
|
|
51
51
|
const modalFilterRef = (0, react_1.useRef)(null);
|
|
52
52
|
const filterIconRef = (0, react_1.useRef)(null);
|
|
53
|
-
// const handleCheckboxChange = () => {
|
|
54
|
-
// const newCheckedState = !isChecked;
|
|
55
|
-
// setIsChecked(newCheckedState);
|
|
56
|
-
// onCheckboxClick?.(newCheckedState);
|
|
57
|
-
// onSelectAllClick?.(newCheckedState);
|
|
58
|
-
// };
|
|
59
53
|
const handleCheckboxChange = () => {
|
|
60
54
|
const newCheckedState = !isChecked;
|
|
61
55
|
setIsChecked(newCheckedState);
|
|
@@ -178,11 +172,6 @@ const ModernTableHeader = ({ columns = [], sortIcon, hasSelect = false, hasCheck
|
|
|
178
172
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
179
173
|
};
|
|
180
174
|
}, [isFilterClicked]);
|
|
181
|
-
(0, react_1.useEffect)(() => {
|
|
182
|
-
if (hasSelectAll !== undefined) {
|
|
183
|
-
setIsChecked(hasSelectAll);
|
|
184
|
-
}
|
|
185
|
-
}, [hasSelectAll]);
|
|
186
175
|
return (react_1.default.createElement("div", { className: `group ${containerClassName ? containerClassName : ""} max-lg:hidden grid w-full border-b border-t border-black/15 `, style: {
|
|
187
176
|
gridTemplateColumns: isMobileView && mobileViewGridClassName
|
|
188
177
|
? mobileViewGridClassName
|