@unito/integration-debugger
Version:
The Unito Integration Debugger
122 lines (121 loc) • 5.73 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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 CrawlerDriver = __importStar(require("../../services/crawlerDriver"));
const styles_1 = require("../../styles");
const store_1 = require("../../store");
const payloadPane_1 = __importDefault(require("./payloadPane"));
const ChooseOperation = (props) => {
const listRef = (0, react_1.useRef)(null);
const debuggerState = (0, store_1.useDebuggerState)();
const configuration = (0, store_1.useConfigurationState)();
const options = [
CrawlerDriver.Operation.GetItem,
CrawlerDriver.Operation.GetCollection,
CrawlerDriver.Operation.GetBlob,
CrawlerDriver.Operation.GetCredentialAccount,
CrawlerDriver.Operation.CreateItem,
CrawlerDriver.Operation.UpdateItem,
];
const [openTextBox, setOpenTextBox] = (0, react_1.useState)(false);
const [selectedOperation, setSelectedOperation] = (0, react_1.useState)(CrawlerDriver.Operation.CreateItem);
(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 startingOperation = options.at(index) ?? CrawlerDriver.Operation.GetItem;
if ([CrawlerDriver.Operation.CreateItem, CrawlerDriver.Operation.UpdateItem].includes(startingOperation)) {
setSelectedOperation(startingOperation);
setOpenTextBox(true);
}
else {
await debuggerState.goto({
credentialId: configuration.current.credentialId,
integrationUrl: configuration.current.integrationUrl,
credentialPayload: configuration.current.credentialPayload,
secretsPayload: configuration.current.secretsPayload,
startingPath: props.path ? props.path : configuration.current.graphRelativeUrl, // '' => fallback.
startingOperation,
stepCheckKeys: configuration.current.stepCheckKeys,
});
props.close();
}
});
}
return () => {
if (listRef.current) {
listRef.current.free();
}
};
}, [listRef]);
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: openTextBox ? ((0, jsx_runtime_1.jsx)(payloadPane_1.default, { close: props.close, path: props.path, startingOperation: selectedOperation })) : ((0, jsx_runtime_1.jsx)("box", { label: (0, styles_1.paneTitle)('Choose the operation type'), top: "center", left: "center", width: 40, height: 10, 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,
},
} }) })) }));
};
const ChoosePath = (props) => {
const inputRef = (0, react_1.useRef)(null);
(0, react_1.useEffect)(() => {
if (inputRef.current) {
inputRef.current.focus();
inputRef.current.on('submit', path => {
props.setPath(path);
});
}
}, [inputRef]);
return ((0, jsx_runtime_1.jsx)("box", { label: (0, styles_1.paneTitle)('Go to'), top: "center", left: "center", width: 70, height: 3, border: styles_1.paneBorder, style: styles_1.pane, children: (0, jsx_runtime_1.jsx)("textbox", { ref: inputRef, keys: true, inputOnFocus: true }) }));
};
const GotoModal = (props) => {
const [path, setPath] = (0, react_1.useState)(null);
let view;
if (path === null) {
view = (0, jsx_runtime_1.jsx)(ChoosePath, { close: props.close, setPath: setPath });
}
else {
view = (0, jsx_runtime_1.jsx)(ChooseOperation, { close: props.close, path: path });
}
return view;
};
exports.default = GotoModal;
;