@unito/integration-debugger
Version:
The Unito Integration Debugger
53 lines (52 loc) • 2.53 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styles_1 = require("../../styles");
const stepChecks_1 = __importDefault(require("../../services/stepChecks"));
const store_1 = require("../../store");
const StepChecksModal = (props) => {
const configuration = (0, store_1.useConfigurationState)();
const debuggerState = (0, store_1.useDebuggerState)();
const listRef = (0, react_1.useRef)(null);
const sortedChecks = Object.entries(stepChecks_1.default).sort(([_keyA, checkA], [_keyB, checkB]) => checkA.label.localeCompare(checkB.label));
const options = sortedChecks.map(([key, check]) => {
const selected = (configuration.stepCheckKeys?.findIndex(activated => activated === key) ?? -1) >= 0;
return `[${selected ? 'x' : ' '}] ${check.label} (${key})`;
});
(0, react_1.useEffect)(() => {
if (listRef.current) {
listRef.current.focus();
listRef.current.key(['escape'], function () {
props.close();
});
listRef.current.on('select', async (_list, index) => {
const check = sortedChecks.map(([k, _v]) => k).at(index) ?? '';
let newStepCheckKeys;
if (configuration.stepCheckKeys?.includes(check)) {
newStepCheckKeys = configuration.stepCheckKeys.filter(c => c !== check);
}
else {
newStepCheckKeys = configuration.stepCheckKeys?.concat([check]);
}
configuration.stepCheckKeys = newStepCheckKeys;
debuggerState.stepCheckKeys = newStepCheckKeys;
});
}
return () => {
if (listRef.current) {
listRef.current.free();
}
};
}, [listRef]);
return ((0, jsx_runtime_1.jsx)("box", { label: (0, styles_1.paneTitle)('Choose checks to perform'), top: "center", left: "center", width: 70, height: 15, border: styles_1.paneBorder, style: styles_1.pane, children: (0, jsx_runtime_1.jsx)("list", { ref: listRef, items: options, keys: true, style: {
selected: {
bg: 'blue',
bold: true,
},
} }) }));
};
exports.default = StepChecksModal;
;