@logilab/cwelements
Version:
Library of reusable React components for building web application with cubicweb
172 lines (171 loc) • 6.76 kB
TypeScript
import * as React from 'react';
import { client, providers } from '@logilab/cwclientlibjs';
/**
* The timeout for validating the user's input
*/
export declare const EDITION_TIMEOUT: number;
/**
* The type of a translation function
*/
export declare type TranslateFunction = (key: string, ...args: any[]) => string;
/**
* The type of context for translations
*/
export interface TranslationContextType {
/**
* The translation function
*/
translate: TranslateFunction;
}
/**
* The default translation context
*/
export declare const TRANSLATION_CONTEXT_DEFAULT: TranslationContextType;
/**
* The context for the translation fonction
*/
export declare const TranslationContext: React.Context<TranslationContextType>;
/**
* The type of a context for entity forms
*/
export interface ProvidersContextType {
/**
* The provider of entity schemas
*/
schemaProvider: providers.EntitySchemaProvider;
/**
* The provider of entities
*/
entityProvider: providers.EntityProvider;
/**
* The RQL client to query the CubicWeb instance
*/
rqlClient?: client.RqlClient;
}
/**
* Context for entity forms
*/
export declare const ProvidersContext: React.Context<ProvidersContextType>;
/**
* Represents an error when validating the new value of an attribute
*/
export interface ValidationError {
/**
* The message to be displayed
*/
message: string;
/**
* The parameters for the message
*/
parameters?: any[];
}
/**
* Type of event handler for the update of the value of an entity's attribute
* @param entity The entity that is updated
* @param attribute The schema for the attribute
* @param required Whether the attribute is required
* @param value The value for the attribute
* @returns A validation error, or null if the value was valid
*/
export declare type AttributeValueEvent = (entity: providers.Entity, attribute: providers.EntityAttributeSchema, required: boolean, value: any, rqlClient?: client.RqlClient) => ValidationError | null;
/**
* Default attribute validation
* @param entity The entity that is updated
* @param attribute The schema for the attribute
* @param required Whether the attribute is required
* @param value The value for the attribute
* @returns A validation error, or null if the value was valid
*/
export declare function defaultAttributeValidation(entity: providers.Entity, attribute: providers.EntityAttributeSchema, required: boolean, value: any): ValidationError | null;
/**
* Builds a validation function for an integer entity attribute
* @param min The minimum of the acceptable range
* @param max The maximum of the acceptable range
*/
export declare function buildIntegerAttributeValidation(min: number | undefined, max: number | undefined): AttributeValueEvent;
/**
* Builds a validation function for a float entity attribute
* @param min The minimum of the acceptable range
* @param max The maximum of the acceptable range
*/
export declare function buildFloatAttributeValidation(min: number | undefined, max: number | undefined): AttributeValueEvent;
/**
* A validation function that checks for a positive float
*/
export declare const POSITIVE_FLOAT_VALIDATION: AttributeValueEvent;
/**
* A validation function that checks for a positive integer
*/
export declare const POSITIVE_INTEGER_VALIDATION: AttributeValueEvent;
/**
* A validation function that does not check anything
* @param entity The entity that is updated
* @param attribute The schema for the attribute
* @param required Whether the attribute is required
* @param value The value for the attribute
* @returns A validation error, or null if the value was valid
*/
export declare function noValidate(_entity: providers.Entity, _attribute: providers.EntityAttributeSchema, _required: boolean, _value: any): ValidationError | null;
/**
* Builds a validation function that cheks that a float value is within an interval
* @param attributeMin The attribute for the min value
* @param attributeMax The attribute for the max value
*/
export declare function buildValidateInterInMinMax(attributeMin: providers.EntityAttributeSchema, attributeMax: providers.EntityAttributeSchema): AttributeValueEvent;
/**
* Builds a validation function that cheks that a float is greater that another attribute
* @param otherAttribute The other attribute
*/
export declare function buildValidatePositiveGreaterThan(otherAttribute: providers.EntityAttributeSchema): AttributeValueEvent;
/**
* Builds a validation function that cheks that a float is less that another attribute
* @param otherAttribute The other attribute
*/
export declare function buildValidatePositiveLessThan(otherAttribute: providers.EntityAttributeSchema): AttributeValueEvent;
/**
* Builds a validation function for an enumerable entity attribute
* @param values The allowed values
*/
export declare function buildEnumAttributeValidation(values: any[]): AttributeValueEvent;
/**
* Gets the displayable text for a value
* @param value The value to display
* @returns The displayable text
*/
export declare function getDisplayText(value: any): string;
/**
* Compares two types based on their names
* @param namedEntity1 A named entity
* @param namedEntity2 A named Entity
* @returns 1,-1 or 0 to sort by descending alphabetical order
*/
export declare function compareNamedEntities(namedEntity1: {
name: string;
}, namedEntity2: {
name: string;
}): number;
/**
* Retrieves an named entity in the list of object given its name
* @param name The name of the entity looked for
* @param entityList The list of named entities
*/
export declare function getNamedEntityFromList<NamedEntity extends {
name: string;
}>(name: string, entityList: NamedEntity[]): NamedEntity | null;
/**
* Save the new attribute value for an entity
* @param entity The entity to modify
* @param attribute The attribute to modify
* @param required Whether the attribute is required
* @param value The new value to set
* @param rqlClient the RqlClient to use to set the new value
*/
export declare function saveNewAttributeValue(entity: providers.Entity, attribute: providers.EntityAttributeSchema, required: boolean, value: any, rqlClient?: client.RqlClient): Promise<client.RqlIoV1TransactionResponse>;
/**
* Determine if the attribute is type RichString, which means is type String and
* the entity got another String attribute with [attribute.name]_format as name.
* @param attribute The attribute to determine is a RichString
* @param attributes (optional) The other attributes available
* @returns boolean
*/
export declare function isRichString(attribute: providers.EntityAttributeSchema, attributes?: providers.EntityAttributeSchema[]): boolean;