@curveball/browser
Version:
Automatic API browser generator. A middleware that turns your JSON responses into HTML if accessed by a browser.
31 lines • 1.53 kB
JavaScript
import * as React from 'react';
import { TemplatedLinks } from './forms/templated-links.js';
import { ActionForm } from './forms/ketting-action.js';
import { ButtonForm } from './forms/ketting-action-button.js';
export function Forms(props) {
const forms = TemplatedLinks(props);
const buttonForms = [];
for (const action of props.resourceState.actions()) {
// Some actions can be expressed as a single button, instaed of a full form.
if (action.fields.some(field => field.type !== 'hidden')) {
forms.push(React.createElement(ActionForm, { action: action, csrfToken: props.csrfToken }));
}
else {
buttonForms.push(React.createElement(ButtonForm, { action: action, csrfToken: props.csrfToken }));
}
}
if (!forms.length && !buttonForms.length) {
return null;
}
/*
if (Object.keys(props.resourceState.data).length === 0 && forms.length === 1) {
// If there are 0 data properties, and exactly 1 action we render a page more
// focused on the single form. We skip the 'forms' header and just the form
// title instead.
}*/
return React.createElement(React.Fragment, null,
React.createElement("h2", { key: "-1" }, "Actions"),
React.createElement("ul", { className: "button-actions" }, buttonForms.map((form, index) => React.createElement("li", { key: index }, form))),
forms.map((form, index) => React.createElement("span", { key: index }, form)));
}
//# sourceMappingURL=forms.js.map