UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

42 lines (41 loc) 2.21 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReferenceListsTableCode = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const formik_1 = require("formik"); const react_1 = require("react"); const react_intl_1 = require("react-intl"); const useAsync_1 = __importDefault(require("react-use/esm/useAsync")); const select_1 = __importDefault(require("../../../../components/formio/select")); const context_1 = require("../../../../context"); const utils_1 = require("./utils"); function isTableOptions(options) { return options !== undefined; } /** * The `ReferenceListsTableCode` component is used to specify the code of the table * in Reference lists API for which the items will be fetched */ const ReferenceListsTableCode = () => { var _a; const intl = (0, react_intl_1.useIntl)(); const { values } = (0, formik_1.useFormikContext)(); const service = (_a = values === null || values === void 0 ? void 0 : values.openForms) === null || _a === void 0 ? void 0 : _a.service; const { getReferenceListsTables } = (0, react_1.useContext)(context_1.BuilderContext); const { value: options, loading, error, } = (0, useAsync_1.default)(async () => { if (!service) { return []; } return await getReferenceListsTables(service); }, [service]); if (error) { throw error; } const _options = isTableOptions(options) ? (0, utils_1.transformItems)(options, intl) : []; return ((0, jsx_runtime_1.jsx)(select_1.default, { name: "openForms.code", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'cLzsxn', defaultMessage: [{ type: 0, value: "Reference lists table code" }] }), tooltip: intl.formatMessage({ id: "YObTjL", defaultMessage: [{ type: 0, value: "The code of the table from which the options will be retrieved." }] }), isLoading: loading, options: _options, valueProperty: "value", required: true })); }; exports.ReferenceListsTableCode = ReferenceListsTableCode; exports.default = exports.ReferenceListsTableCode;