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 {}
/**
* A complete edit page with breadcrumb, title, and default actions.
*
* Combines data fetching, form context, and UI layout for editing records. Renders breadcrumb,
* page title, Show and Delete buttons, and wraps your form components.
*
* @see {@link https://marmelab.com/shadcn-admin-kit/docs/edit/ Edit documentation}
*
* @example
* import { Edit, SimpleForm, BooleanInput, TextInput } from "@/components/admin";
* import { required } from 'ra-core';
*
* export const CustomerEdit = () => (
*
*
*
*
*
*
*
*
*
* );
*/
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;
}
/**
* The view component for Edit pages with layout and UI.
*
* @internal
*/
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}
>
);
};