UNPKG

sccoreui

Version:

ui-sccore

655 lines (654 loc) 44.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deepClone = exports.handleCheckboxClick = exports.getGroupIds = exports.handleUncheckedState = exports.handleCheckedState = exports.updateGroupState = exports.determineConditions = exports.updateRecords = exports.autoGroupColumnDef = exports.fillOperation = exports.updateCells = exports.getCheckedStatus = exports.sortColumns = exports.parseIfNeeded = exports.applyDefaultFilters = exports.isComponentDisable = exports.initialCheckBoxData = void 0; const tslib_1 = require("tslib"); const react_1 = tslib_1.__importDefault(require("react")); const constants_1 = require("./constants"); const type_1 = require("../types/type"); // initial checkbox data exports.initialCheckBoxData = { allBoxChecked: false, isIndeterminate: false, includedRecords: [], excludedRecords: [], headerCheckBoxStatus: constants_1.GRID_CHECKBOX_STATUS.NEUTRAL, }; const isComponentDisable = (state) => { return state === type_1.VisibilityState.DISABLE; }; exports.isComponentDisable = isComponentDisable; const applyDefaultFilters = (defaultFilters) => { const filters = defaultFilters === null || defaultFilters === void 0 ? void 0 : defaultFilters.map((item) => { const obj = { logicalOperator: item === null || item === void 0 ? void 0 : item.logicalOperator, selectedColumn: item === null || item === void 0 ? void 0 : item.columnName, selectedOperation: item === null || item === void 0 ? void 0 : item.condition, value: item === null || item === void 0 ? void 0 : item.value, }; return obj; }); return filters; }; exports.applyDefaultFilters = applyDefaultFilters; const isValidJsonString = (str) => { try { JSON.parse(str); return true; } catch (error) { return false; } }; const parseIfNeeded = (value) => { if (isValidJsonString(value)) { return JSON.parse(value); } else { return value; } }; exports.parseIfNeeded = parseIfNeeded; const sortColumns = (columns) => { const sortedColumns = columns === null || columns === void 0 ? void 0 : columns.sort((a, b) => { (a.body = a.cellRenderer), // Update the rederer key to avoid recursion (b.body = b.cellRenderer); // Update the rederer key to avoid recursion if (!a.seq) return 1; if (!b.seq) return -1; return a.seq - b.seq; }); return sortedColumns; }; exports.sortColumns = sortColumns; // Give checkbox checked status const getCheckedStatus = (row, featureDetails, GRID_CHECKBOX_STATUS, setFeatureDetails) => { const { allBoxChecked, excludedRecords, includedRecords, headerCheckBoxStatus, } = featureDetails.checkBoxSelection; if (allBoxChecked) { return !excludedRecords.includes(row); } else { if (headerCheckBoxStatus === GRID_CHECKBOX_STATUS.NEUTRAL && (row === null || row === void 0 ? void 0 : row.isSelected)) { if (!includedRecords.includes(row)) { includedRecords.push(row); setFeatureDetails((prev) => (Object.assign(Object.assign({}, prev), { checkBoxSelection: Object.assign(Object.assign({}, prev.checkBoxSelection), { includedRecords: [...includedRecords] }) }))); } return true; } return includedRecords.includes(row); } }; exports.getCheckedStatus = getCheckedStatus; const updateCells = (updatedRowData, setUpdateRowData, api) => { if (!api) return; // Find the row node by ID const rowNode = api.getRowNode(updatedRowData.id); if (rowNode) { // Update the row data rowNode.setData(updatedRowData); // Optionally, you can refresh the grid api.refreshCells({ rowNodes: [rowNode], force: true }); // Reset the update flag setUpdateRowData({ shouldUpdate: false, rowData: null }); } }; exports.updateCells = updateCells; // Fill data in grid through drag const fillOperation = (params, api, editedRecords, setEditedRecords) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g; const { finalRange } = params; const { startRow, endRow, columns, // startColumn } = finalRange; const columnDetails = columns[0].colDef; const parentRowData = (_c = api.getDisplayedRowAtIndex((_b = (_a = params === null || params === void 0 ? void 0 : params.initialRange) === null || _a === void 0 ? void 0 : _a.startRow) === null || _b === void 0 ? void 0 : _b.rowIndex)) === null || _c === void 0 ? void 0 : _c.data; // Get current updated rows const currentUpdatedRows = []; // Collect all selected rows for (let i = startRow.rowIndex; i <= endRow.rowIndex; i++) { // Get the row node const rowNode = api.getDisplayedRowAtIndex(i); if (!rowNode) continue; // Skip if rowNode is undefined const rowData = rowNode === null || rowNode === void 0 ? void 0 : rowNode.data; // Check if rowData exists and update the field if (rowData && rowNode.id != (parentRowData === null || parentRowData === void 0 ? void 0 : parentRowData.id)) { // Skip edit for same values if ((rowData === null || rowData === void 0 ? void 0 : rowData[columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field]) === (parentRowData === null || parentRowData === void 0 ? void 0 : parentRowData[columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field])) continue; // If Dragged cell is grouped only group headers should edit vice versa to child cells if (((_d = rowData === null || rowData === void 0 ? void 0 : rowData.orgHierarchy) === null || _d === void 0 ? void 0 : _d.length) !== ((_e = parentRowData === null || parentRowData === void 0 ? void 0 : parentRowData.orgHierarchy) === null || _e === void 0 ? void 0 : _e.length)) continue; // if( rowData?.[columnDetails?.field] == EMPTY_RECORD || rowData?.type !== parentRowData?.type || !rowData?.[columnDetails?.field] ){ // continue // } rowData[columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field] = parentRowData[columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field]; if (rowData === null || rowData === void 0 ? void 0 : rowData.edited) { rowData === null || rowData === void 0 ? void 0 : rowData.edited.push(columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field); } else { rowData.edited = []; rowData === null || rowData === void 0 ? void 0 : rowData.edited.push(columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field); } const schemaForEdit = { row: rowData, field: [], isCustomAttribute: columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.isCustomAttribute, }; if (!((_f = schemaForEdit === null || schemaForEdit === void 0 ? void 0 : schemaForEdit.field) === null || _f === void 0 ? void 0 : _f.includes(columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field))) { (_g = schemaForEdit === null || schemaForEdit === void 0 ? void 0 : schemaForEdit.field) === null || _g === void 0 ? void 0 : _g.push(columnDetails === null || columnDetails === void 0 ? void 0 : columnDetails.field); } currentUpdatedRows.push(schemaForEdit); // Update the row rowNode.setData(rowData); } } const mergeArraysData = mergeArrays(currentUpdatedRows, editedRecords); if (setEditedRecords) { setEditedRecords(mergeArraysData); } // Refresh the cells to show the updated data api.refreshCells({ force: true }); }); exports.fillOperation = fillOperation; // Merge previous updated arrays and current updated arrays const mergeArrays = (currentUpdatedRows, updatedRecords) => { const mergedMap = new Map(); // Add all entries from arr1 to the map currentUpdatedRows === null || currentUpdatedRows === void 0 ? void 0 : currentUpdatedRows.forEach((item) => { mergedMap.set(item.row.id, Object.assign({}, item)); }); // Merge entries from arr2 to the map updatedRecords === null || updatedRecords === void 0 ? void 0 : updatedRecords.forEach((item) => { const existing = mergedMap.get(item.row.id); if (existing) { // Merge row fields Object.assign(existing.row, item.row); // Merge field arrays, avoiding duplicates existing.field = Array.from(new Set([...existing.field, ...item.field])); } else { mergedMap.set(item.row.id, Object.assign({}, item)); } }); // Convert map back to array return Array.from(mergedMap.values()); }; const autoGroupColumnDef = (isTreeEnable, headerName, groupField, GroupHeaderComponent, headerCheckboxRenderer, enableCheckboxForGroupHeader, displayGroupCount, rowGroupColumnWidth, ChildRendererForGroup, HeaderRendererForGroup) => { if (isTreeEnable) { return { headerName: headerName ? headerName : "Group", minWidth: rowGroupColumnWidth || 300, // cellRenderer:(params)=> params.data?.name , cellRendererParams: { suppressCount: true, }, }; } else { return { field: groupField || "group", headerComponent: enableCheckboxForGroupHeader ? () => headerCheckboxRenderer("", GroupHeaderComponent) : GroupHeaderComponent, cellRenderer: "agGroupCellRenderer", minWidth: rowGroupColumnWidth || 300, cellRendererParams: (params) => { var _a; // Render custom component for all group childs if (!params.node.group && ChildRendererForGroup) { return { suppressCount: true, innerRenderer: ChildRendererForGroup, }; } // Render checkbox for specific group header if ((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.group) { return { suppressCount: false, checkbox: false, innerRenderer: HeaderRendererForGroup, }; } // Return specific params for group rows to use default rendering return { suppressCount: typeof displayGroupCount === "boolean" ? !displayGroupCount : true, }; }, }; } }; exports.autoGroupColumnDef = autoGroupColumnDef; // function to update the records based on checkbox state // This function determines how to update `includedRecords` and `excludedRecords` // depending on whether all checkboxes are checked or not (`allBoxChecked` state) const updateRecords = (rowData, featureDetails, gridData) => { var _a, _b, _c; const { excludedRecords, includedRecords, allBoxChecked } = featureDetails.checkBoxSelection; let newExcludedRecords = [...excludedRecords]; let newIncludedRecords = [...includedRecords]; // When all checkboxes are checked if (allBoxChecked) { // Update excluded records: add or remove the current rowData newExcludedRecords = (excludedRecords === null || excludedRecords === void 0 ? void 0 : excludedRecords.includes(rowData)) ? excludedRecords === null || excludedRecords === void 0 ? void 0 : excludedRecords.filter((item) => (item === null || item === void 0 ? void 0 : item.id) !== (rowData === null || rowData === void 0 ? void 0 : rowData.id)) : [...excludedRecords, rowData]; // Check if all records are excluded; reset if so if ((newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) === ((_a = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _a === void 0 ? void 0 : _a.length)) { return exports.initialCheckBoxData; } // Otherwise, update the excluded records and indeterminate state else { return Object.assign(Object.assign({}, featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection), { excludedRecords: newExcludedRecords, isIndeterminate: (newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) > 0 }); } } // When not all checkboxes are checked else { // Update included records: add or remove the current rowData newIncludedRecords = (includedRecords === null || includedRecords === void 0 ? void 0 : includedRecords.includes(rowData)) ? includedRecords === null || includedRecords === void 0 ? void 0 : includedRecords.filter((item) => { if ((item === null || item === void 0 ? void 0 : item.id) !== (rowData === null || rowData === void 0 ? void 0 : rowData.id)) { return item; } else { rowData.isSelected = false; // Set isSelected to false if removing the row return false; // Exclude this item from the new array } }) : [...includedRecords, rowData]; // Add rowData if it's not already included // Check if all records are included; reset if so if ((newIncludedRecords === null || newIncludedRecords === void 0 ? void 0 : newIncludedRecords.length) === ((_b = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _b === void 0 ? void 0 : _b.length)) { return { excludedRecords: [], includedRecords: [], isIndeterminate: false, allBoxChecked: true, }; } // Check if all records are excluded; reset if so else if ((newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) === ((_c = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _c === void 0 ? void 0 : _c.length)) { return exports.initialCheckBoxData; } // Otherwise, update the included records else { return Object.assign(Object.assign({}, featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection), { includedRecords: newIncludedRecords }); } } }; exports.updateRecords = updateRecords; // Utility function to determine conditions for updating group states // Based on various flags and states, determines whether to add or remove group IDs const determineConditions = (isChecked, allBoxChecked, isEveryParentGroupInclude, isEverySuperParentGroupInclude, isSomeParentGroupExcluded, isSomeSuperParentGroupExcluded) => ({ addParent: (!allBoxChecked && isChecked && isEveryParentGroupInclude) || (allBoxChecked && isChecked && !isSomeParentGroupExcluded), addSuperParent: (!allBoxChecked && isChecked && isEverySuperParentGroupInclude) || (allBoxChecked && isChecked && !isSomeSuperParentGroupExcluded), removeParent: (!allBoxChecked && !isChecked && !isEveryParentGroupInclude) || (allBoxChecked && !isChecked && isSomeParentGroupExcluded), removeSuperParent: (!allBoxChecked && !isChecked && !isEverySuperParentGroupInclude) || (allBoxChecked && !isChecked && isSomeSuperParentGroupExcluded), }); exports.determineConditions = determineConditions; // Function to update the selected groups in the state // Takes the group ID and a boolean flag `add` to decide whether to add or remove the group ID const updateSelectedGroup = (id, add, setSelectedGroup) => { setSelectedGroup((prev) => { if (add) { // If `add` is true, add the group ID if it does not already exist in the state if (!prev.includes(id)) { return [...prev, id]; } } else { // If `add` is false, remove the group ID from the state return prev.filter((groupId) => groupId !== id); } return prev; }); }; // function to update the selected groups in the state // Manages adding or removing group IDs based on the grouping column count and conditions const updateGroupState = (groupingColumns, parentId, superParentId, conditions, setSelectedGroup) => { const { addParent, addSuperParent, removeParent, removeSuperParent } = conditions; // Handle logic when there are 2 grouping columns if (groupingColumns === 2) { if (addSuperParent) updateSelectedGroup(superParentId, true, setSelectedGroup); // Add super parent group ID if (addParent) { updateSelectedGroup(parentId, true, setSelectedGroup); } // Add parent group ID if (removeSuperParent) updateSelectedGroup(superParentId, false, setSelectedGroup); // Remove super parent group ID if (removeParent) updateSelectedGroup(parentId, false, setSelectedGroup); // Remove parent group ID } // Handle logic when there is 1 grouping column else if (groupingColumns === 1) { if (addParent) { updateSelectedGroup(parentId, true, setSelectedGroup); // Add parent ID } if (removeParent) { updateSelectedGroup(parentId, false, setSelectedGroup); // Remove parent group ID } } }; exports.updateGroupState = updateGroupState; // ------------------------------------- group header checkbox ------------------------------------------- // Utility function to gather all child and parent data for a group const gatherGroupData = (params) => { var _a, _b, _c, _d; const groupData = (_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.allLeafChildren) === null || _b === void 0 ? void 0 : _b.map((childNode) => childNode === null || childNode === void 0 ? void 0 : childNode.data); const parentGroupData = (_d = (_c = params === null || params === void 0 ? void 0 : params.node.parent) === null || _c === void 0 ? void 0 : _c.allLeafChildren) === null || _d === void 0 ? void 0 : _d.map((childNode) => childNode === null || childNode === void 0 ? void 0 : childNode.data); return { groupData, parentGroupData }; }; // Utility function to handle checked state updates const handleCheckedState = (params, featureDetails, gridData, setFeatureDetails, setSelectedGroup, groupingColumns) => { const { excludedRecords, includedRecords, allBoxChecked } = featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection; const { groupData, parentGroupData } = gatherGroupData(params); let newExcludedRecords = [...excludedRecords]; let newIncludedRecords = [...includedRecords]; // newExcludedRecords.filter((item) => item?.id !== group.id) // Update records based on the checkbox state groupData.forEach((group) => { var _a, _b; if (allBoxChecked) { newExcludedRecords = (newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.includes(group)) ? newExcludedRecords.filter((item) => (item === null || item === void 0 ? void 0 : item.id) !== group.id) : newExcludedRecords; } else if (!((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.leafGroup) && ((_b = params === null || params === void 0 ? void 0 : params.node) === null || _b === void 0 ? void 0 : _b.level) === 0) { newIncludedRecords = newIncludedRecords.includes(group) ? newIncludedRecords : [...newIncludedRecords, group]; } else { newIncludedRecords = newIncludedRecords.includes(group) ? newIncludedRecords : [...newIncludedRecords, group]; } }); updateCheckboxData(newIncludedRecords, newExcludedRecords, gridData, featureDetails, setFeatureDetails, allBoxChecked); // const isParent = determineParentGroupState(parentGroupData, newIncludedRecords, newExcludedRecords, allBoxChecked, groupData); handleGroupSelection(params, setSelectedGroup, groupingColumns, newIncludedRecords, newExcludedRecords, parentGroupData, allBoxChecked); }; exports.handleCheckedState = handleCheckedState; // Utility function to handle unchecked state updates const handleUncheckedState = (params, featureDetails, gridData, setFeatureDetails, setSelectedGroup, groupingColumns) => { const { excludedRecords, includedRecords, allBoxChecked } = featureDetails.checkBoxSelection; const { groupData, parentGroupData } = gatherGroupData(params); let newExcludedRecords = [...excludedRecords]; let newIncludedRecords = [...includedRecords]; // Update records based on the checkbox state groupData.forEach((group) => { if (allBoxChecked) { newExcludedRecords = newExcludedRecords.includes(group) ? newExcludedRecords : [...newExcludedRecords, group]; } else { newIncludedRecords = newIncludedRecords.includes(group) ? newIncludedRecords.filter((item) => { if (item.id !== group.id) group.isSelected = false; return item.id !== group.id; }) : [...newIncludedRecords, group]; } }); updateCheckboxData(newIncludedRecords, newExcludedRecords, gridData, featureDetails, setFeatureDetails, allBoxChecked); const isEveryParentGroupInclude = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.every((parent) => newIncludedRecords.some((included) => (included === null || included === void 0 ? void 0 : included.id) === (parent === null || parent === void 0 ? void 0 : parent.id))); const isParent = determineParentGroupState(parentGroupData, newIncludedRecords, newExcludedRecords, allBoxChecked); handleGroupDeselection(params, setSelectedGroup, groupingColumns, isParent, isEveryParentGroupInclude); }; exports.handleUncheckedState = handleUncheckedState; // Utility function to update checkbox data in the state const updateCheckboxData = (newIncludedRecords, newExcludedRecords, gridData, featureDetails, setFeatureDetails, allBoxChecked) => { var _a, _b, _c, _d; if ((newIncludedRecords === null || newIncludedRecords === void 0 ? void 0 : newIncludedRecords.length) === 0 && ((_a = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _a === void 0 ? void 0 : _a.length) === 0 && !allBoxChecked) { setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: Object.assign(Object.assign({}, featureDetails.checkBoxSelection), { excludedRecords: [], includedRecords: [], isIndeterminate: false, allBoxChecked: false }) })); } else if ((newIncludedRecords === null || newIncludedRecords === void 0 ? void 0 : newIncludedRecords.length) === ((_b = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _b === void 0 ? void 0 : _b.length) && (newIncludedRecords === null || newIncludedRecords === void 0 ? void 0 : newIncludedRecords.length) > 0) { setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: Object.assign(Object.assign({}, featureDetails.checkBoxSelection), { excludedRecords: [], includedRecords: [], isIndeterminate: false, allBoxChecked: true }) })); } else if ((newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) === 0 && ((_c = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _c === void 0 ? void 0 : _c.length) === 0 && allBoxChecked) { setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: Object.assign(Object.assign({}, featureDetails.checkBoxSelection), { excludedRecords: [], includedRecords: [], isIndeterminate: false, allBoxChecked: true }) })); } else if ((newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) === ((_d = gridData === null || gridData === void 0 ? void 0 : gridData.rowData) === null || _d === void 0 ? void 0 : _d.length) && (newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) > 0) { setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: Object.assign(Object.assign({}, featureDetails.checkBoxSelection), { excludedRecords: [], includedRecords: [], isIndeterminate: false, allBoxChecked: false }) })); } else { setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: Object.assign(Object.assign({}, featureDetails.checkBoxSelection), { excludedRecords: newExcludedRecords, includedRecords: newIncludedRecords, isIndeterminate: featureDetails.checkBoxSelection.allBoxChecked ? true : featureDetails.checkBoxSelection.isIndeterminate }) })); } }; // Utility function to determine parent group inclusion or exclusion states const determineParentGroupState = (parentGroupData, newIncludedRecords, newExcludedRecords, allBoxChecked) => { const isAnyParentGroupInclude = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.every((parent) => newIncludedRecords.some((included) => included.id === parent.id)); const isAnyParentGroupExcluded = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.some((parent) => newExcludedRecords.some((excluded) => excluded.id === parent.id)); return allBoxChecked ? isAnyParentGroupExcluded : isAnyParentGroupInclude; }; // Utility function to handle group selection logic for checked state const handleGroupSelection = (params, setSelectedGroup, groupingColumns, newIncludedRecords, newExcludedRecords, parentGroupData, allBoxChecked) => { var _a, _b, _c, _d, _e, _f, _g, _h; const isEverySuperParentGroupInclude = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.every((parent) => newIncludedRecords.some((included) => (included === null || included === void 0 ? void 0 : included.id) === (parent === null || parent === void 0 ? void 0 : parent.id))); // const isAnyParentGroupInclude = groupData?.some((parent) => // newIncludedRecords.some((included) => included?.id === parent?.id) // ); const isEverySuperParentGroupExcluded = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.every((parent) => newExcludedRecords.some((excluded) => (excluded === null || excluded === void 0 ? void 0 : excluded.id) === (parent === null || parent === void 0 ? void 0 : parent.id))); if (groupingColumns === 2 && !((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.leafGroup) && ((_b = params === null || params === void 0 ? void 0 : params.node) === null || _b === void 0 ? void 0 : _b.level) === 0) { (_d = (_c = params === null || params === void 0 ? void 0 : params.node) === null || _c === void 0 ? void 0 : _c.childrenAfterGroup) === null || _d === void 0 ? void 0 : _d.forEach((childNode) => { setSelectedGroup((prev) => prev.includes(childNode.id) ? prev : [...prev, childNode.id]); }); setSelectedGroup((prev) => prev.includes(params.node.id) ? prev : [...prev, params.node.id]); } else if (((_e = params === null || params === void 0 ? void 0 : params.node) === null || _e === void 0 ? void 0 : _e.leafGroup) && ((_f = params === null || params === void 0 ? void 0 : params.node) === null || _f === void 0 ? void 0 : _f.level) === 1 && !allBoxChecked) { setSelectedGroup((prev) => prev.includes(params.node.id) ? prev : [...prev, params.node.id]); if (isEverySuperParentGroupInclude) { setSelectedGroup((prev) => { var _a, _b, _c, _d; return prev.includes((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id) ? prev : [...prev, (_d = (_c = params === null || params === void 0 ? void 0 : params.node) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.id]; }); } } else if (((_g = params === null || params === void 0 ? void 0 : params.node) === null || _g === void 0 ? void 0 : _g.leafGroup) && ((_h = params === null || params === void 0 ? void 0 : params.node) === null || _h === void 0 ? void 0 : _h.level) === 1 && allBoxChecked) { setSelectedGroup((prev) => prev.includes(params.node.id) ? prev : [...prev, params.node.id]); if (isEverySuperParentGroupExcluded || (newExcludedRecords === null || newExcludedRecords === void 0 ? void 0 : newExcludedRecords.length) === 0) { setSelectedGroup((prev) => { var _a, _b, _c, _d; return prev.includes((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id) ? prev : [...prev, (_d = (_c = params === null || params === void 0 ? void 0 : params.node) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.id]; }); } } else { setSelectedGroup((prev) => { var _a, _b; return prev.includes((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.id) ? prev : [...prev, (_b = params === null || params === void 0 ? void 0 : params.node) === null || _b === void 0 ? void 0 : _b.id]; }); } }; // Utility function to handle group deselection logic for unchecked state const handleGroupDeselection = (params, setSelectedGroup, groupingColumns, isParent, isEveryParentGroupInclude) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; if (groupingColumns === 2 && !((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.leafGroup) && ((_b = params === null || params === void 0 ? void 0 : params.node) === null || _b === void 0 ? void 0 : _b.level) === 0) { (_d = (_c = params === null || params === void 0 ? void 0 : params.node) === null || _c === void 0 ? void 0 : _c.childrenAfterGroup) === null || _d === void 0 ? void 0 : _d.forEach((childNode) => { setSelectedGroup((prev) => prev === null || prev === void 0 ? void 0 : prev.filter((id) => id !== (childNode === null || childNode === void 0 ? void 0 : childNode.id))); }); setSelectedGroup((prev) => prev === null || prev === void 0 ? void 0 : prev.filter((id) => { var _a; return id !== ((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.id); })); } else if (((_e = params === null || params === void 0 ? void 0 : params.node) === null || _e === void 0 ? void 0 : _e.leafGroup) && ((_f = params === null || params === void 0 ? void 0 : params.node) === null || _f === void 0 ? void 0 : _f.level) === 1 && !isEveryParentGroupInclude) { // Handle cases where current node is a leaf group at level 1 setSelectedGroup((prev) => { if (prev === null || prev === void 0 ? void 0 : prev.includes(params.node.id)) { return prev === null || prev === void 0 ? void 0 : prev.filter((id) => { var _a; return id !== ((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.id); }); } return prev; }); setSelectedGroup((prev) => { var _a, _b; if (prev === null || prev === void 0 ? void 0 : prev.includes((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id)) { return prev === null || prev === void 0 ? void 0 : prev.filter((id) => { var _a, _b; return id !== ((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id); }); } return prev; }); } else if (((_g = params === null || params === void 0 ? void 0 : params.node) === null || _g === void 0 ? void 0 : _g.leafGroup) && ((_h = params === null || params === void 0 ? void 0 : params.node) === null || _h === void 0 ? void 0 : _h.level) === 1 && !isParent) { setSelectedGroup((prev) => { if (prev === null || prev === void 0 ? void 0 : prev.includes(params.node.id)) { return prev === null || prev === void 0 ? void 0 : prev.filter((id) => { var _a; return id !== ((_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.id); }); } return prev; }); setSelectedGroup((prev) => { var _a, _b; if (prev === null || prev === void 0 ? void 0 : prev.includes((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id)) { return prev === null || prev === void 0 ? void 0 : prev.filter((id) => { var _a, _b; return id !== ((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id); }); } return prev; }); } else if (((_j = params === null || params === void 0 ? void 0 : params.node) === null || _j === void 0 ? void 0 : _j.leafGroup) && ((_k = params === null || params === void 0 ? void 0 : params.node) === null || _k === void 0 ? void 0 : _k.level) === 1 && isParent) { setSelectedGroup((prev) => { var _a, _b; if (prev.includes((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id)) { return prev.filter((id) => { var _a, _b; return id !== ((_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id); }); } return prev; }); } else { setSelectedGroup((prev) => prev.filter((id) => id !== params.node.id)); } }; // ------------------------------------- group header checkbox ------------------------------------------- // iterating over eachnode and return first and second group ids const getGroupIds = (gridRef) => { var _a, _b; const firstGroupIds = []; const secondGroupIds = []; (_b = (_a = gridRef === null || gridRef === void 0 ? void 0 : gridRef.current) === null || _a === void 0 ? void 0 : _a.api) === null || _b === void 0 ? void 0 : _b.forEachNode((node) => { if (node === null || node === void 0 ? void 0 : node.group) { if ((node === null || node === void 0 ? void 0 : node.level) === 0) { // Store the ID of the first level group firstGroupIds === null || firstGroupIds === void 0 ? void 0 : firstGroupIds.push(node === null || node === void 0 ? void 0 : node.id); } else if ((node === null || node === void 0 ? void 0 : node.level) === 1) { // Store the ID of the second level group secondGroupIds === null || secondGroupIds === void 0 ? void 0 : secondGroupIds.push(node === null || node === void 0 ? void 0 : node.id); } } }); return { firstGroupIds, secondGroupIds }; }; exports.getGroupIds = getGroupIds; const handleCheckboxClick = (e, params, featureDetails, gridData, setFeatureDetails, groupingColumns, setSelectedGroup, selectColumns) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const isChecked = e.checked; const { data: rowData } = params; // Update checkbox data and set the updated state const updatedCheckBoxData = (0, exports.updateRecords)(rowData, featureDetails, gridData); selectColumns(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: updatedCheckBoxData })); setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { checkBoxSelection: updatedCheckBoxData })); // Gather parent and super parent group data for condition checks const parentGroupData = (_c = (_b = (_a = params === null || params === void 0 ? void 0 : params.node) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.childrenAfterGroup) === null || _c === void 0 ? void 0 : _c.map((childNode) => childNode === null || childNode === void 0 ? void 0 : childNode.data); const superParentData = (_g = (_f = (_e = (_d = params === null || params === void 0 ? void 0 : params.node) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.parent) === null || _f === void 0 ? void 0 : _f.allLeafChildren) === null || _g === void 0 ? void 0 : _g.map((children) => children === null || children === void 0 ? void 0 : children.data); // Determine if all or any parent groups are included/excluded const isEveryParentGroupInclude = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.every((parent) => { var _a; return (_a = updatedCheckBoxData === null || updatedCheckBoxData === void 0 ? void 0 : updatedCheckBoxData.includedRecords) === null || _a === void 0 ? void 0 : _a.some((included) => (included === null || included === void 0 ? void 0 : included.id) === (parent === null || parent === void 0 ? void 0 : parent.id)); }); // const isEveryParentGroupExcluded = parentGroupData?.every((parent) => // updatedCheckBoxData?.excludedRecords?.some( // (excluded) => excluded?.id === parent?.id // ) // ); const isSomeParentGroupExcluded = parentGroupData === null || parentGroupData === void 0 ? void 0 : parentGroupData.some((parent) => { var _a; return (_a = updatedCheckBoxData === null || updatedCheckBoxData === void 0 ? void 0 : updatedCheckBoxData.excludedRecords) === null || _a === void 0 ? void 0 : _a.some((excluded) => (excluded === null || excluded === void 0 ? void 0 : excluded.id) === (parent === null || parent === void 0 ? void 0 : parent.id)); }); // const isEverySuperParentGroupExcluded = superParentData?.every((parent) => // updatedCheckBoxData?.excludedRecords?.some( // (excluded) => excluded?.id === parent?.id // ) // ); const isSomeSuperParentGroupExcluded = superParentData === null || superParentData === void 0 ? void 0 : superParentData.some((parent) => { var _a; return (_a = updatedCheckBoxData === null || updatedCheckBoxData === void 0 ? void 0 : updatedCheckBoxData.excludedRecords) === null || _a === void 0 ? void 0 : _a.some((excluded) => (excluded === null || excluded === void 0 ? void 0 : excluded.id) === (parent === null || parent === void 0 ? void 0 : parent.id)); }); const isEverySuperParentGroupInclude = superParentData === null || superParentData === void 0 ? void 0 : superParentData.every((parent) => { var _a; return (_a = updatedCheckBoxData === null || updatedCheckBoxData === void 0 ? void 0 : updatedCheckBoxData.includedRecords) === null || _a === void 0 ? void 0 : _a.some((included) => (included === null || included === void 0 ? void 0 : included.id) === (parent === null || parent === void 0 ? void 0 : parent.id)); }); // Determine the conditions to update group state const conditions = (0, exports.determineConditions)(isChecked, updatedCheckBoxData.allBoxChecked, isEveryParentGroupInclude, isEverySuperParentGroupInclude, isSomeParentGroupExcluded, isSomeSuperParentGroupExcluded); // Update group state based on determined conditions (0, exports.updateGroupState)(groupingColumns, (_j = (_h = params === null || params === void 0 ? void 0 : params.node) === null || _h === void 0 ? void 0 : _h.parent) === null || _j === void 0 ? void 0 : _j.id, (_m = (_l = (_k = params === null || params === void 0 ? void 0 : params.node) === null || _k === void 0 ? void 0 : _k.parent) === null || _l === void 0 ? void 0 : _l.parent) === null || _m === void 0 ? void 0 : _m.id, conditions, setSelectedGroup); }; exports.handleCheckboxClick = handleCheckboxClick; const deepClone = (obj) => { var _a, _b, _c; // If the input is not an object or is null, return the value itself (primitive types are returned directly) if (obj === null || typeof obj !== "object") { return obj; } // Handle Date objects by creating a new Date instance with the same value if (obj instanceof Date) { return new Date(obj); } // Handle RegExp objects by creating a new RegExp instance with the same pattern and flags if (obj instanceof RegExp) { return new RegExp(obj); } // Handle React JSX elements // If the object is a valid React element, clone it along with its props and children if (react_1.default.isValidElement(obj)) { const element = obj; // Explicitly assert type to ReactElement // Recursively clone all child elements, if any const clonedChildren = ((_a = element === null || element === void 0 ? void 0 : element.props) === null || _a === void 0 ? void 0 : _a.children) ? (_b = react_1.default.Children) === null || _b === void 0 ? void 0 : _b.map((_c = element === null || element === void 0 ? void 0 : element.props) === null || _c === void 0 ? void 0 : _c.children, (child) => (0, exports.deepClone)(child)) : undefined; // Set to undefined if no children exist // Return a cloned React element with its props and recursively cloned children return react_1.default.cloneElement(element, Object.assign({}, element === null || element === void 0 ? void 0 : element.props), // Spread the existing props clonedChildren // Include cloned children ); } // Handle Arrays // Recursively clone each element in the array if (Array.isArray(obj)) { return obj === null || obj === void 0 ? void 0 : obj.map(exports.deepClone); } // Handle Objects // Recursively clone each property in the object const clonedObj = {}; // Create a new empty object to hold cloned properties for (const key in obj) { // Use hasOwnProperty to avoid cloning inherited properties if (Object.prototype.hasOwnProperty.call(obj, key)) { clonedObj[key] = (0, exports.deepClone)(obj[key]); // Recursively clone each property } } // Return the fully cloned object return clonedObj; }; exports.deepClone = deepClone;