@unito/integration-debugger
Version:
The Unito Integration Debugger
66 lines (65 loc) • 3.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const store_1 = require("../../store");
const integrationsPlatform_1 = require("../../services/integrationsPlatform");
const styles_1 = require("../../styles");
const ChooseIntegration = (props) => {
const listRef = (0, react_1.useRef)(null);
const integrations = (0, store_1.useIntegrationsState)();
const configuration = (0, store_1.useConfigurationState)();
const fetchIntegrations = (0, react_1.useCallback)(() => {
(0, integrationsPlatform_1.getIntegrations)()
.then(incomingIntegrations => {
// Sort integrations by name prioritising production integrations, then previews and then live-previews
const mainIntegrations = incomingIntegrations
.filter(integration => !integration.archivedAt && !integration.name.includes('-preview-'))
.sort((a, b) => a.name.localeCompare(b.name));
const previewIntegrations = incomingIntegrations
.filter(integration => !integration.archivedAt &&
integration.name.includes('-preview-') &&
!integration.name.includes('live-preview-'))
.sort((a, b) => a.name.localeCompare(b.name));
const livePreviewIntegrations = incomingIntegrations
.filter(integration => !integration.archivedAt && integration.name.includes('live-preview-'))
.sort((a, b) => a.name.localeCompare(b.name));
integrations.current = mainIntegrations.concat(previewIntegrations, livePreviewIntegrations);
})
.catch(() => {
/* TODO */
});
}, []);
(0, react_1.useEffect)(() => {
fetchIntegrations();
if (listRef.current) {
listRef.current.focus();
listRef.current.key(['escape'], function () {
props.close();
});
listRef.current.on('select', (_list, index) => {
configuration.integrationId = integrations.current.at(index)?.id;
configuration.integrationUrl = undefined;
configuration.graphRelativeUrl = undefined;
configuration.credentialAccountRelativeUrl = undefined;
configuration.webhookParsingRelativeUrl = undefined;
configuration.webhookSubscriptionsRelativeUrl = undefined;
configuration.webhookAcknowledgeRelativeUrl = undefined;
configuration.credentialId = undefined;
props.close();
});
}
return () => {
if (listRef.current) {
listRef.current.free();
}
};
}, [listRef]);
return ((0, jsx_runtime_1.jsx)("box", { label: (0, styles_1.paneTitle)('choose an integration'), top: "center", left: "center", width: 40, height: 15, border: styles_1.paneBorder, style: styles_1.pane, children: (0, jsx_runtime_1.jsx)("list", { ref: listRef, items: integrations.current.map(integration => integration.name), scrollbar: styles_1.scrollbar, scrollable: true, keys: true, style: {
selected: {
bg: 'blue',
bold: true,
},
} }) }));
};
exports.default = ChooseIntegration;
;