Skip to content

Commit

Permalink
(Build) Lib for v5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Volokhin authored and Arthur Volokhin committed Jun 19, 2023
1 parent f76973a commit 0a4093a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 45 deletions.
72 changes: 50 additions & 22 deletions lib/admiral.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -95721,7 +95721,20 @@ function makeCreatePage(config2) {
var _a, _b, _c;
const locale2 = useLocaleProvider();
const title2 = (_b = (_a = config2.create) == null ? void 0 : _a.title) != null ? _b : "Create";
if (!!config2.form.create.fields && !((_c = config2.create) == null ? void 0 : _c.title)) {
const actionsLocale = locale2.actions;
const {
path,
form: {
create: { fields: fields2, children }
}
} = config2;
if (config2.form.create.fields && config2.form.create.children) {
console.error('Please provide "form.create.fields" or "form.create.children"');
}
if (!config2.form.create.fields && !config2.form.create.children) {
console.error('Please provide "form.create.fields" or "form.create.children"');
}
if (!config2.form.create.fields && !((_c = config2.create) == null ? void 0 : _c.title)) {
console.error('Please provide "create.title"');
}
const { getCreateFormData, create: create2 } = useDataProvider();
Expand All @@ -95731,17 +95744,17 @@ function makeCreatePage(config2) {
const submitData = useCallback$1((values2) => {
return create2(config2.resource, { data: values2 });
}, []);
const actionsLocale = locale2.actions;
const pageFormChildren = useMemo$2(() => children != null ? children : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Form.Fields, null, fields2), /* @__PURE__ */ React__default.createElement(Form.Footer, null, /* @__PURE__ */ React__default.createElement(BackButton, {
basePath: path
}, actionsLocale.back), /* @__PURE__ */ React__default.createElement(Form.Submit, null, actionsLocale.submit))), [children, fields2, path, actionsLocale]);
return /* @__PURE__ */ React__default.createElement(Page, {
title: title2
}, /* @__PURE__ */ React__default.createElement(Form, {
submitData,
redirect: config2.path,
fetchInitialData,
locale: locale2.form
}, /* @__PURE__ */ React__default.createElement(Form.Fields, null, config2.form.create.fields), /* @__PURE__ */ React__default.createElement(Form.Footer, null, /* @__PURE__ */ React__default.createElement(BackButton, {
basePath: config2.path
}, actionsLocale.back), /* @__PURE__ */ React__default.createElement(Form.Submit, null, actionsLocale.submit))));
}, pageFormChildren));
};
}
function makeUpdatePage(config2) {
Expand All @@ -95759,13 +95772,24 @@ function makeUpdatePage(config2) {
const {
path,
form: {
edit: { fields: fields2 }
edit: { fields: fields2, children }
}
} = config2;
const { title: title2 = (id2) => `Update #${id2}`, view = "page" } = config2.update || {};
if (!!config2.form.create.fields && !((_a = config2.update) == null ? void 0 : _a.title)) {
if (config2.form.edit.fields && config2.form.edit.children) {
console.error('Please provide "form.edit.fields" or "form.edit.children"');
}
if (!config2.form.edit.fields && !config2.form.edit.children) {
console.error('Please provide "form.edit.fields" or "form.edit.children"');
}
if (!config2.form.edit.fields && !((_a = config2.update) == null ? void 0 : _a.title)) {
console.error('Please provide "update.title"');
}
const pageFormChildren = useMemo$2(() => {
return children ? children : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Form.Fields, null, fields2), /* @__PURE__ */ React__default.createElement(Form.Footer, null, /* @__PURE__ */ React__default.createElement(BackButton, {
basePath: path
}, actionsLocale.back), /* @__PURE__ */ React__default.createElement(Form.Submit, null, actionsLocale.submit)));
}, [children, fields2, path, actionsLocale]);
const { state } = useLocation();
const background = state && state.background;
return view === "drawer" && !!background ? /* @__PURE__ */ React__default.createElement(UpdateDrawer, {
Expand All @@ -95780,9 +95804,7 @@ function makeUpdatePage(config2) {
submitData,
fetchInitialData,
locale: locale2.form
}, /* @__PURE__ */ React__default.createElement(Form.Fields, null, fields2), /* @__PURE__ */ React__default.createElement(Form.Footer, null, /* @__PURE__ */ React__default.createElement(BackButton, {
basePath: path
}, actionsLocale.back), /* @__PURE__ */ React__default.createElement(Form.Submit, null, actionsLocale.submit))));
}, pageFormChildren));
};
}
function UpdateDrawer({
Expand All @@ -95807,7 +95829,7 @@ function UpdateDrawer({
const {
path,
form: {
edit: { fields: fields2 }
edit: { fields: fields2, children }
}
} = config2;
const { drawer } = config2.update || {};
Expand All @@ -95826,15 +95848,8 @@ function UpdateDrawer({
var _a2, _b;
return (_b = (_a2 = drawerRef.current) == null ? void 0 : _a2.bodyElement) != null ? _b : () => document.querySelector("#root > .Theme");
}, [drawerRef.current]);
return /* @__PURE__ */ React__default.createElement(Drawer, {
ref: drawerRef,
visible,
onClose: (e2) => {
e2.stopPropagation();
setVisible(false);
},
title: title2,
footer: /* @__PURE__ */ React__default.createElement("div", {
const drawerFooter2 = useMemo$2(() => {
return !children ? /* @__PURE__ */ React__default.createElement("div", {
className: styles.drawerFooter
}, /* @__PURE__ */ React__default.createElement(Button$1, {
type: "button",
Expand All @@ -95845,7 +95860,20 @@ function UpdateDrawer({
type: "button",
onClick: onSubmit,
iconLeft: /* @__PURE__ */ React__default.createElement(FiSave, null)
}, actionsLocale.submit)),
}, actionsLocale.submit)) : null;
}, [children, onSubmit, onBack, drawer == null ? void 0 : drawer.footer]);
const drawerFormChildren = useMemo$2(() => {
return children ? children : /* @__PURE__ */ React__default.createElement(Form.Fields, null, fields2);
}, [children, fields2]);
return /* @__PURE__ */ React__default.createElement(Drawer, {
ref: drawerRef,
visible,
onClose: (e2) => {
e2.stopPropagation();
setVisible(false);
},
title: title2,
footer: drawerFooter2,
afterVisibleChange: (visible2) => {
var _a2, _b;
if (!visible2) {
Expand All @@ -95866,7 +95894,7 @@ function UpdateDrawer({
submitData,
fetchInitialData,
locale: locale2.form
}, /* @__PURE__ */ React__default.createElement(Form.Fields, null, fields2))));
}, drawerFormChildren)));
}
function createCRUD(config2) {
return {
Expand Down
34 changes: 17 additions & 17 deletions lib/admiral.umd.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions lib/admiral/crud/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export declare type CRUDActionsLocale = {
tableColumn: string;
paginationTotal: (total: number) => string;
};
declare type CRUDForm = {
fields: React.ReactNode;
children?: never;
} | {
fields?: never;
children: React.ReactNode;
};
export declare type CRUDFormCreate = CRUDForm;
export declare type CRUDFormEdit = CRUDForm;
export declare type CRUDConfig<RecordType> = {
path: string;
actions?: React.ReactNode;
Expand All @@ -34,12 +43,8 @@ export declare type CRUDConfig<RecordType> = {
tableConfig?: DataTableConfig<RecordType>;
};
form: {
create: {
fields: React.ReactNode;
};
edit: {
fields: React.ReactNode;
};
create: CRUDFormCreate;
edit: CRUDFormEdit;
};
create?: {
title?: string;
Expand All @@ -58,3 +63,4 @@ export declare type CRUDConfig<RecordType> = {
topContent?: ReactNode;
bottomContent?: ReactNode;
};
export {};

0 comments on commit 0a4093a

Please sign in to comment.