@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
38 lines (37 loc) • 2.01 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 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");
function isPluginOptions(options) {
return options !== undefined;
}
/**
* Fetch the available validator plugins and display them in a multiselect.
*
* This requires an async function `getPrefillPlugins` to be provided to the
* BuilderContext which is responsible for retrieving the list of available plugins.
*
* If a fetch error occurs, it is thrown during rendering - you should provide your
* own error boundary to catch this.
*/
const PrefillPluginSelect = () => {
const intl = (0, react_intl_1.useIntl)();
const { values } = (0, formik_1.useFormikContext)();
const { getPrefillPlugins } = (0, react_1.useContext)(context_1.BuilderContext);
const { value: options, loading, error, } = (0, useAsync_1.default)(async () => await getPrefillPlugins(values.type || ''), []);
if (error) {
throw error;
}
const tooltip = intl.formatMessage({ id: "YmWeGZ", defaultMessage: [{ type: 0, value: "Select the plugin to use for the prefill functionality." }] });
const _options = isPluginOptions(options) ? options : [];
return ((0, jsx_runtime_1.jsx)(select_1.default, { name: "prefill.plugin", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'ce1N0I', defaultMessage: [{ type: 0, value: "Plugin" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: _options, valueProperty: "id", emptyValue: "" }));
};
exports.default = PrefillPluginSelect;