UNPKG

@openshift-assisted/ui-lib

Version:

React component library for the Assisted Installer UI

63 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNewBundleOperators = exports.getNewOperators = void 0; const getOperatorDependencies = (operatorId, preflightRequirements, dependencies = new Set()) => { var _a, _b; const originalSize = dependencies.size; const deps = ((_b = (_a = preflightRequirements === null || preflightRequirements === void 0 ? void 0 : preflightRequirements.operators) === null || _a === void 0 ? void 0 : _a.find(({ operatorName }) => operatorName === operatorId)) === null || _b === void 0 ? void 0 : _b.dependencies) || []; deps.forEach((dep) => dependencies.add(dep)); if (originalSize !== dependencies.size) { // add deps of new deps deps.forEach((op) => { getOperatorDependencies(op, preflightRequirements, dependencies); }); } return [...dependencies]; }; const getNewOperators = (currentOperators, operatorId, preflightRequirements, add, opSpecs) => { const dependencies = getOperatorDependencies(operatorId, preflightRequirements); if (add) { const uniqueOps = new Set([...currentOperators, ...dependencies, operatorId]); return Array.from(uniqueOps); } const newOperators = currentOperators.filter((op) => op !== operatorId); // uncheck unneeded not-standalone dependencies too const notStandaloneDeps = dependencies .filter((dep) => { var _a; return (_a = opSpecs[dep]) === null || _a === void 0 ? void 0 : _a.notStandalone; }) .filter((dep) => // some other operator may still depend on the not-standalone operator newOperators.every((op) => !getOperatorDependencies(op, preflightRequirements).includes(dep))); return currentOperators.filter((op) => op !== operatorId && !notStandaloneDeps.includes(op)); }; exports.getNewOperators = getNewOperators; const getBundleOperators = (bundle, preflightRequirements) => { var _a; const bundleOperators = new Set(bundle.operators || []); (_a = bundle.operators) === null || _a === void 0 ? void 0 : _a.forEach((op) => { getOperatorDependencies(op, preflightRequirements).forEach((dep) => bundleOperators.add(dep)); }); return [...bundleOperators]; }; const getNewBundleOperators = (currentOperators, currentBundles, allBundles, newBundle, preflightRequirements, add) => { const newBundleOperators = getBundleOperators(newBundle, preflightRequirements); if (add) { return [...new Set([...currentOperators, ...newBundleOperators])]; } const newBundles = currentBundles.filter((b) => b !== newBundle.id); const operatorsToKeep = [ ...newBundles.reduce((acc, bundleId) => { const bundle = allBundles.find(({ id }) => id === bundleId); if (bundle) { const bundleOperators = getBundleOperators(bundle, preflightRequirements); bundleOperators.forEach((op) => { acc.add(op); }); } return acc; }, new Set()), ]; const operatorsToRemove = newBundleOperators.filter((op) => !operatorsToKeep.includes(op)); return currentOperators.filter((op) => !operatorsToRemove.includes(op)); }; exports.getNewBundleOperators = getNewBundleOperators; //# sourceMappingURL=utils.js.map