@logilab/cwelements
Version:
Library of reusable React components for building web application with cubicweb
115 lines (114 loc) • 3.92 kB
TypeScript
import * as React from 'react';
import { providers } from '@logilab/cwclientlibjs';
import { ProvidersContext } from './commons';
/**
* Base interface for components for an entity relation
*/
export declare class EntityRelation<P extends EntityRelationProps = EntityRelationProps, S extends EntityRelationState = EntityRelationState> 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 relation components
*/
export interface EntityRelationProps {
/**
* The entity
*/
entity: providers.Entity;
/**
* The shema for the relation
*/
relation: providers.EntityRelationSchema;
/**
* Whether the entity is the relation's subject
*/
entityIsSubject: boolean;
/**
* Whether to enable the edition of the relations
*/
editable: boolean;
/**
* The CSS class name(s) for the component in normal conditions
*/
className: string;
/**
* Handler of events when the user click on a link to an entity
*/
onClickGotoTarget: (eid: number) => void;
/**
* Handler fo events when the user wants to edit the relation
*/
onClickEdit: (relation: providers.EntityRelationSchema) => void;
/**
* Gets the target link for the specified entity
* @param eid The entity
*/
getTargetLink: (eid: number) => string;
/**
* 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 title for the relation
* @param component The current component (this)
*/
renderTitle: (component: EntityRelation) => JSX.Element;
/**
* Renders the edit button for the relation
* @param component The current component (this)
*/
renderEditButton: (component: EntityRelation) => JSX.Element;
/**
* Renders a particular related entity
* @param component The current component (this)
* @param eid The EID fo the related entity
* @param index The index in the list of related entities
*/
renderRelationItem: (component: EntityRelation, eid: number, index: number) => JSX.Element;
/**
* Renders the set of related entities
* @param component The current component (this)
*/
renderRelationValues: (component: EntityRelation) => JSX.Element | null;
/**
* Renders the component
* @param component The current component (this)
*/
render: (component: EntityRelation) => JSX.Element;
}
/**
* State for the relation components
*/
export interface EntityRelationState {
/**
* The EID of the related entities
*/
values: number[];
/**
* The displayable names of the related entities
*/
displays: JSX.Element[];
}
/**
* The values for the default parameters of relations components
*/
export declare const ENTITY_RELATION_DEFAULT_PROPS: {
editable: boolean;
className: string;
onClickGotoTarget: (eid: number) => void;
onClickEdit: (relation: providers.EntityRelationSchema) => void;
getTargetLink: (eid: number) => string;
renderDisplayValue: (entity: providers.Entity, schema: providers.EntitySchema) => JSX.Element;
renderTitle: (component: EntityRelation) => JSX.Element;
renderEditButton: (component: EntityRelation) => JSX.Element;
renderRelationItem: (component: EntityRelation, eid: number, index: number) => JSX.Element;
renderRelationValues: (component: EntityRelation) => JSX.Element;
render: (component: EntityRelation) => JSX.Element;
};