UNPKG

@logilab/cwelements

Version:

Library of reusable React components for building web application with cubicweb

124 lines (123 loc) 5.45 kB
import * as React from 'react'; import { providers } from '@logilab/cwclientlibjs'; import { EntityRelationsSpecification, EntityRelationsChanges } from './EntityRelationsEditor'; /** * Applies changes to a list entities * @param entities A list of entities * @param changes The list of changes to apply */ export declare function applyChanges(entities: providers.Entity[], changes: EntityRelationsChanges[]): providers.Entity[]; /** * Gets the already related entities, taking into account a stack of changes * @param specification The specification * @param limit The maximum number of items to retrieve * @param changes The stack of changes to be applied */ export declare function lookupEntitiesRelatedWithChanges(specification: EntityRelationsSpecification, limit: number, changes: EntityRelationsChanges[]): Promise<providers.Entity[]>; /** * Loads a list of rows [x, t] where x an eid and t is the eid of the entity's type as the result of a lookup * @param specification The original specification for the relatable entities * @param rows The [x, t] rows */ export declare function lookupLoadFromResults(specification: EntityRelationsSpecification, rows: [number, number][]): Promise<providers.Entity[]>; /** * Lookups relatable entities with the specified criteria * @param specification The original specification for the related entities * @param fieldName The name of the field to use as a criteria * @param value The value to look for int he field * @param limit The maximum number of results */ export declare function lookupEntitiesByField(specification: EntityRelationsSpecification, fieldName: string, value: string, limit: number): Promise<providers.Entity[]>; /** * Gets the already related entities * @param specification The specification * @param limit The maximum number of items to retrieve */ export declare function lookupEntitiesRelated(specification: EntityRelationsSpecification, limit: number): Promise<providers.Entity[]>; /** * The parameters for the component responsible for getting the input for looking for related entities */ export interface EntityRelationsLookupProps { /** * The specification for the related entities */ specification: EntityRelationsSpecification; /** * The CSS class name(s) for the component */ className: string; /** * The limit when looking up relatable entities */ lookupLimitRelatable: number; /** * The limit when looking up already related entities */ lookupLimitRelated: number; /** * Handles event when the selection is currently loading the entities */ onLookupLoading: () => void; /** * Handles event when relatable candidates have been found * @param result The result of the lookup */ onLookupResult: (result: providers.Entity[]) => void; } /** * The parameters for the component responsible for getting the input for looking for related entities */ export interface DefaultEntityRelationsLookupProps extends EntityRelationsLookupProps { /** * Lookups relatable entities using the specified input * @param specification The specification for the related entities * @param input The current input string * @param lookupLimit The limit to the number of entities to retrieve when looking them up */ lookupRelatableEntities: (specification: EntityRelationsSpecification, input: string, lookupLimit: number) => Promise<providers.Entity[]>; /** * Lookups already related entities * @param specification The specification for the related entities * @param lookupLimit The limit to the number of entities to retrieve when looking them up */ lookupRelatedEntities: (specification: EntityRelationsSpecification, lookupLimit: number) => Promise<providers.Entity[]>; } /** * The state for the component responsible for getting the input for looking for related entities */ export interface DefaultEntityRelationsLookupState { /** * The current input string */ input: string; } /** * The default props for the component responsible for getting the input for looking for related entities */ export declare const DEFAULT_ENTITY_RELATIONS_LOOKUP_DEFAULT_PROPS: { className: string; lookupLimitRelatable: number; lookupLimitRelated: number; lookupRelatableEntities: (specification: EntityRelationsSpecification, input: string, lookupLimit: number) => Promise<providers.Entity[]>; lookupRelatedEntities: typeof lookupEntitiesRelated; }; /** * The component responsible for getting the input for looking for related entities */ export declare class DefaultEntityRelationsLookup extends React.Component<DefaultEntityRelationsLookupProps, DefaultEntityRelationsLookupState> { static defaultProps: { className: string; lookupLimitRelatable: number; lookupLimitRelated: number; lookupRelatableEntities: (specification: EntityRelationsSpecification, input: string, lookupLimit: number) => Promise<providers.Entity[]>; lookupRelatedEntities: typeof lookupEntitiesRelated; }; state: DefaultEntityRelationsLookupState; timeout: number | undefined; _isMounted: boolean; constructor(props: Readonly<DefaultEntityRelationsLookupProps>); componentDidMount(): void; componentWillUnmount(): void; onInputChanged(event: React.ChangeEvent<HTMLInputElement>): void; render(): JSX.Element; }