UNPKG

sccoreui

Version:

ui-sccore

50 lines (49 loc) 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const context_provider_1 = require("../context-provider"); const svg_component_1 = tslib_1.__importDefault(require("../../../directives/svg-component")); const helper_1 = require("../helper"); const utilComponents_1 = require("../utilComponents"); const FeatureSkeleton_1 = tslib_1.__importDefault(require("../../skeletons/FeatureSkeleton")); function RemoveItems(props) { var _a; const { featureDetails, conditionsToDisplay, serverSideSelectRow, gridApi } = (0, react_1.useContext)(context_provider_1.FeatureContext); const { removeCallBack, bulkRemoveComponent } = props; const isDisabled = (0, helper_1.isComponentDisable)(conditionsToDisplay.displayRemoveItems); const removeItemsCallBack = () => { if (!isDisabled && removeCallBack) { const currentFeature = Object.assign({}, featureDetails); currentFeature.checkBoxSelection.allBoxChecked, // Callback from products removeCallBack(currentFeature); } }; const checkShowRemoveIcon = (0, react_1.useMemo)(() => { var _a, _b, _c, _d; const model = (_b = (_a = gridApi === null || gridApi === void 0 ? void 0 : gridApi.current) === null || _a === void 0 ? void 0 : _a.api) === null || _b === void 0 ? void 0 : _b.getModel(); const selectedNodes = []; if (model) { const rowCount = model.getRowCount(); for (let i = 0; i < rowCount; i++) { const rowNode = model.getRow(i); if (((_c = rowNode === null || rowNode === void 0 ? void 0 : rowNode.data) === null || _c === void 0 ? void 0 : _c.isSelected) === true) { selectedNodes.push(rowNode.data); if (selectedNodes.length > 1) { break; } // ✅ This break is valid } } } return (((_d = featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection) === null || _d === void 0 ? void 0 : _d.allBoxChecked) || featureDetails.checkBoxSelection.includedRecords.length > 1 || selectedNodes.length > 1); }, [serverSideSelectRow, featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection]); if (bulkRemoveComponent) { return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: bulkRemoveComponent() }); } return (0, utilComponents_1.skeletonLoding)() ? ((0, jsx_runtime_1.jsx)(FeatureSkeleton_1.default, {})) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (serverSideSelectRow ? checkShowRemoveIcon : (((_a = featureDetails === null || featureDetails === void 0 ? void 0 : featureDetails.checkBoxSelection) === null || _a === void 0 ? void 0 : _a.allBoxChecked) || featureDetails.checkBoxSelection.includedRecords.length > 1)) ? (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `rounded_btn sc_icon_hover icon-40x40 ${isDisabled && "disabled"}`, onClick: removeItemsCallBack, title: "Remove" }, { children: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "minus-circle", color: "text-red-800", size: 18 }) })) : "" })); } exports.default = RemoveItems;