UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

47 lines (46 loc) 2.19 kB
"use strict"; 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 ChooseCredential = (props) => { const listRef = (0, react_1.useRef)(null); const integration = (0, store_1.useIntegrationState)(); const credentials = (0, store_1.useCredentialsState)(); const configuration = (0, store_1.useConfigurationState)(); const fetchCredentials = (0, react_1.useCallback)(() => { if (integration.current) { (0, integrationsPlatform_1.getCredentials)(integration.current.id) .then(incomingCredentials => { // Order Credentials by id credentials.current = incomingCredentials.sort((a, b) => a.id - b.id); }) .catch(() => { /* TODO */ }); } }, []); (0, react_1.useEffect)(() => { fetchCredentials(); if (listRef.current) { listRef.current.focus(); listRef.current.key(['escape'], function () { props.close(); }); listRef.current.on('select', (_list, index) => { configuration.credentialId = credentials.current.at(index)?.id; configuration.credentialPayload = undefined; props.close(); }); } return () => { if (listRef.current) { listRef.current.free(); } }; }, [listRef]); return ((0, jsx_runtime_1.jsx)("box", { label: (0, styles_1.paneTitle)('choose a credential'), 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: credentials.current.map(credential => [credential.id, credential.scope].join(' - ')), scrollbar: styles_1.scrollbar, scrollable: true, keys: true, style: styles_1.unfocusedList }) })); }; exports.default = ChooseCredential;