feat: add admin options for entities and app shell

Introduced `BkndAdminEntitiesOptions` and `BkndAdminAppShellOptions` for advanced customization of entity actions, headers, footers, and app shell user menu. Updated related components, hooks, and types for seamless integration with the new configuration options.
This commit is contained in:
dswbx
2025-09-19 11:36:31 +02:00
parent 95d114ea68
commit 26d1f2b583
15 changed files with 234 additions and 35 deletions

View File

@@ -13,6 +13,10 @@ import { EntityForm } from "ui/modules/data/components/EntityForm";
import { useEntityForm } from "ui/modules/data/hooks/useEntityForm";
import { s } from "bknd/utils";
import { notifications } from "@mantine/notifications";
import { useEntityAdminOptions } from "ui/options";
import { Dropdown } from "ui/components/overlay/Dropdown";
import { TbDots } from "react-icons/tb";
import { IconButton } from "ui/components/buttons/IconButton";
export function DataEntityCreate({ params }) {
const { $data } = useBkndData();
@@ -23,6 +27,7 @@ export function DataEntityCreate({ params }) {
} else if (entity.type === "system") {
return <Message.NotAllowed description={`Entity "${params.entity}" cannot be created.`} />;
}
const options = useEntityAdminOptions(entity, "create");
const [error, setError] = useState<string | null>(null);
useBrowserTitle(["Data", entity.label, "Create"]);
@@ -71,7 +76,16 @@ export function DataEntityCreate({ params }) {
<AppShell.SectionHeader
right={
<>
{options.actions?.context && (
<Dropdown position="bottom-end" items={options.actions.context}>
<IconButton Icon={TbDots} />
</Dropdown>
)}
<Button onClick={goBack}>Cancel</Button>
{options.actions?.primary?.map(
(button, key) =>
button && <Button {...button} type="button" key={key} variant="primary" />,
)}
<Form.Subscribe
selector={(state) => [state.canSubmit, state.isSubmitting]}
children={([canSubmit, isSubmitting]) => (
@@ -96,6 +110,7 @@ export function DataEntityCreate({ params }) {
/>
</AppShell.SectionHeader>
<AppShell.Scrollable key={entity.name}>
{options.header}
{error && (
<div className="flex flex-row dark:bg-red-950 bg-red-100 p-4">
<b className="mr-2">Create failed: </b> {error}
@@ -110,6 +125,7 @@ export function DataEntityCreate({ params }) {
action="create"
className="flex flex-grow flex-col gap-3 p-3"
/>
{options.footer}
</AppShell.Scrollable>
</>
);