UNPKG

@hilla/react-crud

Version:

Hilla CRUD utils for React

70 lines 3.63 kB
import type { AbstractModel, DetachedModelConstructor, Value } from '@hilla/form'; import { type JSX } from 'react'; import { type AutoFormProps } from './autoform.js'; import { type AutoGridProps } from './autogrid.js'; import type { CrudService } from './crud.js'; import { type ComponentStyleProps } from './util.js'; export type AutoCrudFormProps<TModel extends AbstractModel> = Omit<Partial<AutoFormProps<TModel>>, 'disabled' | 'item' | 'model' | 'onDeleteSuccess' | 'onSubmitSuccess' | 'service'>; export type AutoCrudGridProps<TItem> = Omit<Partial<AutoGridProps<TItem>>, 'model' | 'onActiveItemChanged' | 'selectedItems' | 'service'>; export type AutoCrudProps<TModel extends AbstractModel = AbstractModel> = ComponentStyleProps & Readonly<{ /** * The service to use for fetching the data, as well saving and deleting * items. This must be a TypeScript service that has been generated by Hilla * from a backend Java service that implements the * `dev.hilla.crud.CrudService` interface. */ service: CrudService<Value<TModel>>; /** * The entity model to use for the CRUD. This determines which columns to * show in the grid, and which fields to show in the form. This must be a * Typescript model class that has been generated by Hilla from a backend * Java class. The model must match with the type of the items returned by * the service. For example, a `PersonModel` can be used with a service that * returns `Person` instances. * * By default, the grid shows columns for all properties of the model which * have a type that is supported. Use the `gridProps.visibleColumns` option * to customize which columns to show and in which order. * * By default, the form shows fields for all properties of the model which * have a type that is supported. Use the `formProps.visibleFields` * option to customize which fields to show and in which order. */ model: DetachedModelConstructor<TModel>; /** * The property to use to detect an item's ID. The item ID is required for * deleting items via the `CrudService.delete` method as well as keeping the * selection state after reloading the grid. * * By default, the component uses the property annotated with * `jakarta.persistence.Id`, or a property named `id`, in that order. * This option can be used to override the default behavior, or define the ID * property in case a class doesn't have a property matching the defaults. */ itemIdProperty?: string; /** * Props to pass to the form. See the `AutoForm` component for details. */ formProps?: AutoCrudFormProps<TModel>; /** * Props to pass to the grid. See the `AutoGrid` component for details. */ gridProps?: AutoCrudGridProps<Value<TModel>>; }>; /** * Auto CRUD is a component that provides CRUD (create, read, update, delete) * functionality based on a Java backend service. It automatically generates a * grid that shows data from the service, and a form for creating, updating and * deleting items. * * Example usage: * ```tsx * import { AutoCrud } from '@hilla/react-crud'; * import PersonService from 'Frontend/generated/endpoints'; * import PersonModel from 'Frontend/generated/com/example/application/Person'; * * <AutoCrud service={PersonService} model={PersonModel} /> * ``` */ export declare function AutoCrud<TModel extends AbstractModel>({ service, model, itemIdProperty, formProps, gridProps, style, id, className, }: AutoCrudProps<TModel>): JSX.Element; //# sourceMappingURL=autocrud.d.ts.map