UNPKG

@logilab/cwelements

Version:

Library of reusable React components for building web application with cubicweb

217 lines (216 loc) 8.57 kB
import * as React from 'react'; import { client, providers } from '@logilab/cwclientlibjs'; import { AttributeValueEvent, ProvidersContext } from './commons'; import './css/EntityForm.css'; /** * Base interface for components for entity attributes */ export declare class EntityForm<P extends EntityFormProps = EntityFormProps, S extends EntityFormState = EntityFormState> extends React.Component<P, S> { static contextType: React.Context<import("./commons").ProvidersContextType>; context: React.ContextType<typeof ProvidersContext>; /** * Whether the component is currently mounted */ _isMounted: boolean; } /** * The parameters for an entity view component */ export interface EntityFormProps { /** * The timestamp on these parameters */ timestamp: number; /** * The EID of the entity of interest */ eid: number; /** * The CSS class name(s) for the component in normal conditions */ className: string; /** * Whether to enable the edition of the entity */ editable: boolean; /** * The attributes name white list to render * If this list is null then all attributes are rendered */ attributesWhiteList: string[] | null; /** * The relations name white list to render * If this list is null then all relations are rendered */ relationsWhiteList: string[] | null; /** * Handler of events when the user click on a link to an entity */ onClickGotoTarget: (eid: number) => void; /** * Handler of events when the user wants to edit the relations */ onClickEdit: (data: providers.Entity, relations: providers.EntityRelationSchema[]) => void; /** * Gets the target link for the specified entity * @param eid The entity */ getTargetLink: (eid: number) => string; /** * Handler of events when a new value input has been received */ onChangeAttribute: AttributeValueEvent; /** * Handler when an attribute has been saved in the database * if editable is true */ attributeHasBeenSaved: (entity: providers.Entity, attribute: providers.EntityAttributeSchema, value: any) => void; /** * Handler when an attribute has not been saved in the database * because of an error * if editable is true */ attributeSavingError: (entity: providers.Entity, attribute: providers.EntityAttributeSchema, value: any, error: string) => void; /** * Renders the attributes and relations of this entity * @param component The current component (this) * @param data The entity * @param schema The schema of the entity */ renderElements: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element[]; /** * Renders the attributes of this entity * @param component The current component (this) * @param data The entity * @param schema The schema of the entity */ renderAttributes: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element[]; /** * Renders an attribute of this entity * @param component The current component (this) * @param data The entity * @param attribute The schema of the attribute to be rendered */ renderAttribute: (component: EntityForm, data: providers.Entity, attribute: providers.EntityAttributeSchema) => JSX.Element; /** * Renders a group of relations of this entity * @param component The current component (this) * @param data The entity * @param relations The schema of the relations to be rendered * @param entityIsSubject Whether the entity is a subject of the relations (or an object) */ renderRelationsGroup: (component: EntityForm, data: providers.Entity, relations: providers.EntityRelationSchema[], entityIsSubject: boolean) => JSX.Element[]; /** * Gets the displayable value for the specified entity and schema * @param entity The entity that will be rendered * @param schema The schema for the entity */ renderDisplayValue: (entity: providers.Entity, schema: providers.EntitySchema) => JSX.Element; /** * Renders the entity's title * @param component The current component (this) * @param data The entity * @param schema The schema of the entity */ renderTitle: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element; /** * Renders this view when data is still loading * @param component The current component (this) */ renderLoading: (component: EntityForm) => JSX.Element; /** * Renders this view when there are no data * @param component The current component (this) */ renderNoData: (component: EntityForm) => JSX.Element; /** * Renders this view when there are no data * @param component The current component (this) */ renderOnError: (component: EntityForm) => JSX.Element; /** * Renders the loaded data * @param component The current component (this) * @param data The entity * @param schema The schema of the entity */ renderLoaded: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element; /** * Renders the component * @param component The current component (this) */ render: (component: EntityForm) => JSX.Element; } /** * The status of an entity view */ export declare enum EntityStatus { /** * The view is currently loading its data */ loading = "loading", /** * The view has attempted to load its data but there was none */ nodata = "nodata", /** * The data have been loaded and are ready */ withdata = "withdata", /** * There was an error while loading the view */ onerror = "onerror" } /** * State for an entity view component */ export interface EntityFormState { /** * The current status of the view */ status: EntityStatus; /** * The current error message, if any */ error: string | null; /** * The entity, of null when it is still being loaded */ data: providers.Entity | null; /** * The schema for the entity, or null when it is still being loaded */ schema: providers.EntitySchema | null; } /** * The defaults props for an entity view */ export declare const ENTITY_DEFAULT_PROPS: { className: string; editable: boolean; attributesWhiteList: null; relationsWhiteList: null; onClickGotoTarget: (eid: number) => void; onClickEdit: (data: providers.Entity, relations: providers.EntityRelationSchema[]) => void; getTargetLink: (eid: number) => string; renderElements: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element[]; renderAttributes: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element[]; onChangeAttribute: (entity: providers.Entity, attribute: providers.EntityAttributeSchema, required: boolean, value: any, rqlClient?: client.RqlClient | undefined) => null; renderAttribute: (component: EntityForm, data: providers.Entity, attribute: providers.EntityAttributeSchema) => JSX.Element; attributeHasBeenSaved: (entity: providers.Entity, attribute: providers.EntityAttributeSchema, value: any) => void; attributeSavingError: (entity: providers.Entity, attribute: providers.EntityAttributeSchema, value: any, error: string) => void; renderRelationsGroup: (component: EntityForm, data: providers.Entity, relations: providers.EntityRelationSchema[], entityIsSubject: boolean) => JSX.Element[]; renderDisplayValue: (entity: providers.Entity, schema: providers.EntitySchema) => JSX.Element; renderTitle: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element; renderLoading: (component: EntityForm) => JSX.Element; renderNoData: (component: EntityForm) => JSX.Element; renderOnError: (component: EntityForm) => JSX.Element; renderLoaded: (component: EntityForm, data: providers.Entity, schema: providers.EntitySchema) => JSX.Element; render: (component: EntityForm) => JSX.Element; }; /** * Groups the specified relations accord to a a criterion (by default, same name) * @param relations The relations to groups */ export declare function getRelationGroups(relations: providers.EntityRelationSchema[]): providers.EntityRelationSchema[][];