// This file is part of Shadcn Admin Kit (https://github.com/marmelab/shadcn-admin-kit)
import type { EditBaseProps } from "ra-core";
import {
EditBase,
Translate,
useCreatePath,
useEditContext,
useGetRecordRepresentation,
useGetResourceLabel,
useHasDashboard,
useResourceContext,
useResourceDefinition,
} from "ra-core";
import type { ReactNode } from "react";
import { Link } from "react-router";
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbPage,
} from "@/components/admin/breadcrumb";
import { cn } from "@/lib/utils";
import { ShowButton } from "@/components/admin/show-button";
import { DeleteButton } from "./delete-button";
export interface EditProps extends EditViewProps, EditBaseProps {}
export const Edit = ({
actions,
children,
className,
disableBreadcrumb,
title,
...rest
}: EditProps) => (
{children}
);
export interface EditViewProps {
disableBreadcrumb?: boolean;
title?: ReactNode | string | false;
actions?: ReactNode;
children?: ReactNode;
className?: string;
}
export const EditView = ({
disableBreadcrumb,
title,
actions,
className,
children,
}: EditViewProps) => {
const context = useEditContext();
const resource = useResourceContext();
if (!resource) {
throw new Error(
"The EditView component must be used within a ResourceContextProvider",
);
}
const getResourceLabel = useGetResourceLabel();
const listLabel = getResourceLabel(resource, 2);
const createPath = useCreatePath();
const listLink = createPath({
resource,
type: "list",
});
const getRecordRepresentation = useGetRecordRepresentation(resource);
const recordRepresentation = getRecordRepresentation(context.record);
const { hasShow } = useResourceDefinition({ resource });
const hasDashboard = useHasDashboard();
if (context.isLoading || !context.record) {
return null;
}
return (
<>
{!disableBreadcrumb && (
{hasDashboard && (
Home
)}
{listLabel}
{recordRepresentation}
)}
{title !== undefined ? title : context.defaultTitle}
{actions ?? (
{hasShow ? : null}
)}
{children}
>
);
};