import { SerializedEntityProps, MetaClassInfo, CommitMode, SerializedEntity } from "@cuba-platform/rest"; import { IReactComponent } from "mobx-react/dist/types/IReactComponent"; import * as React from "react"; import { DataContainer, DataContainerError, DataContainerStatus } from "./DataContext"; import { MainStore } from "../app/MainStore"; import { WithId } from "../util/metadata"; /** * Retrieves an entity instance using Generic REST API. * * @typeparam T - entity type. */ export declare class DataInstanceStore implements DataContainer { private mainStore; readonly entityName: string; /** * Retrieved entity instance. */ item?: T & Partial & WithId; /** * @inheritDoc */ status: DataContainerStatus; /** * @inheritDoc */ lastError?: DataContainerError; /** * Name of the view used to limit the entity graph. */ viewName: string; /** * Name of the ID attribute of a String ID entity. * Mandatory for String ID entities, shall be omitted otherwise. */ stringIdName?: string; /** * @inheritDoc */ changedItems: import("mobx").IObservableArray; constructor(mainStore: MainStore, entityName: string, viewName?: string, stringIdName?: string); /** * Retrieves an entity instance using the given id and view by sending a request to the REST API. * * @param id - id of an entity instance to be retrieved. */ load: (id: string) => Promise>; /** * Sets the {@link item} to the provided value. Changes {@link status} to `DONE`. * * @param item - entity instance to be set as the {@link item}. */ setItem(item: this["item"]): void; /** * Sets the {@link item} based on provided values of Ant Design {@link https://ant.design/components/form/ | Form} fields. * * @param formFields - a object representing the values of Ant Design {@link https://ant.design/components/form/ | Form} fields. */ setItemToFormFields(formFields: Partial): void; /** * Updates the {@link item} using a provided `entityPatch`, then sends a request to the REST API to persist the changes. * * @param entityPatch - a `Partial` representing the changes to be made. * @param commitMode - 'create' when creating a new entity or 'edit' when editing an existing one. * Different REST API endpoints and HTTP methods will be used depending on whether the entity is new. * IMPORTANT: * If this parameter is omitted, then the entity will be considered new if it lacks the `id` attribute. * This will produce incorrect results for String ID entities. * Therefore using this parameter is mandatory for String ID entities. * * @returns a promise that resolves to the update result returned by the REST API. */ update(entityPatch: Record, commitMode?: CommitMode): Promise; /** * Sends a request to the REST API to persist the changes made to the {@link item}. * * @param commitMode - see {@link update} * * @returns a promise that resolves to the update result returned by the REST API. */ commit: (commitMode?: CommitMode | undefined) => Promise>; /** * Transforms the {@link item} into the format expected by Ant Design {@link https://ant.design/components/form/ | Form} fields. * * @param properties - entity properties that should be included in the result. * @returns entity instance transformed into the format expected by Ant Design {@link https://ant.design/components/form/ | Form} fields. */ getFieldValues(properties: string[]): Partial<{ [prop in keyof T]: any; }>; } export interface DataInstanceOptions { /** * Whether to call the {@link DataInstanceStore.load} method immediately after the * {@link DataInstanceStore} is constructed. */ loadImmediately?: boolean; /** * See {@link DataInstanceStore.viewName} */ view?: string; /** * See {@link DataInstanceStore.stringIdName} */ stringIdName?: string; } export interface DataInstanceProps extends DataInstanceOptions { entityName: string; children: (store: Partial>) => React.ReactNode; } /** * Initialization function that instantiates a {@link DataInstanceStore}. * * @typeparam T - entity type. * * @param entityName - name of the entity to be retrieved. * @param opts - {@link DataInstanceStore} configuration. */ export declare function instance(entityName: string, opts: DataInstanceOptions): DataInstanceStore; export declare const withDataInstance: (entityName: string, opts?: DataInstanceOptions) => >(target: T) => T & import("mobx-react").IWrappedComponent; /** * A hook that returns a mutable ref object containing a {@link DataInstanceStore} * initialized with provided entity name and options. The {@link DataInstanceStore} * value will be preserved between renders. * * @typeparam T - entity type. * * @param entityName * @param opts */ export declare const useInstance: (entityName: string, opts: DataInstanceOptions) => React.MutableRefObject>; export interface DataInstanceInjected { dataInstance?: DataInstanceStore; } export declare class Instance extends React.Component> { store: DataInstanceStore; constructor(props: DataInstanceProps); render(): React.ReactNode; get childrenProps(): { item: (E & Partial & WithId) | undefined; status: DataContainerStatus; load: (id: string) => Promise>; commit: (commitMode?: CommitMode | undefined) => Promise>; }; } /** * @deprecated To be removed from public API * * @param item */ export declare function stripTemporaryIds(item: Record): Record; /** * Transforms the antd Form fields values into format expected by Instance item, which is generally the same as the format * expected by REST API, except that Instance item may have the following properties that are stripped before the commit: * - a temporary id created client-side * - read-only attributes * * @param formFields * @param entityName * @param metadata * @param stringIdName See {@link DataInstanceStore.stringIdName} */ export declare function formFieldsToInstanceItem(formFields: Record, entityName: string, metadata: MetaClassInfo[], stringIdName?: string): Record; /** * Transforms the provided `item` into the format expected by Ant Design {@link https://ant.design/components/form/ | Form} fields. * * @typeparam T - entity type. * * @param item - entity instance to be transformed. * @param entityName * @param metadata - entities metadata. * @param displayedProperties - entity properties that should be included in the result. If not provided, all properties will be included. * @param stringIdName See {@link DataInstanceStore.stringIdName} */ export declare function instanceItemToFormFields(item: Record | undefined, entityName: string, metadata: MetaClassInfo[], displayedProperties?: string[], stringIdName?: string): Record;