@sassoftware/vi-api
Version:
Types used in the SAS Visual Investigator API
309 lines (308 loc) • 11.9 kB
TypeScript
import { PageDataChange, PageModeChange } from "../control/events";
import { Relationship } from "../svi-datahub";
import { QueryMode } from "../svi-sand";
import { ControlContainer, VIObject } from "../object/object-api";
import { PageModel, PageModelObjectData } from "../page-model/page-model-api";
import { SearchObject, SearchQuery } from "../search/client/client-search-api";
import { HandleType, MinMaxDates, TimeSliderContextMenuHideOptions, TimeSliderEventDates, TimeSliderRange, TimeSliderRangeChangedEvent } from "../time-slider";
import { PageModeEvent } from "../control";
export interface SearchAndSelectWithPreviewInputBindings {
initialQuery?: string;
additionalModes?: QueryMode[];
objectTypeFilter?: string[];
}
export interface SearchAndSelectWithPreviewBindings extends SearchAndSelectWithPreviewInputBindings {
onSearchItemSelected: (selectedItem: SearchObject | null) => void;
onSearchItemDoubleClicked?: (selectedItem: SearchObject) => void;
}
export interface PageViewerApi {
save: () => Promise<void>;
isDirty: () => boolean;
isValid: () => Promise<boolean>;
}
export type PageViewerBindings = CreateObjectPageBindings | EditObjectPageBindings | ViewObjectPageBindings | StaticDataPageBindings | PageBindings;
export declare enum PageViewerBindingsType {
CreateObject = "CREATE",
EditObject = "EDIT",
ViewObject = "VIEW",
StaticData = "STATIC"
}
/**
* Component bindings to configure a page viewer for creating a new object.
*/
export interface CreateObjectPageBindings extends CommonPageViewerBindings {
bindingsType: PageViewerBindingsType.CreateObject;
/** Page context to use. */
eventName: PageModeEvent.CREATE;
/** Entity type of the object. */
docType: string;
/** Temporary ID to use for the unsaved object. */
tempCreateId?: string;
/** Initial values to populate the pageModel data. */
initialCreateData?: Record<string, any>;
/**
* Optionally provide a pageModel using window.sas.vi.pageModel.createFromObject.
* The pageModel type must match docType.
* The pageModel data will be populated with initialCreateData.
* The pageModel can be used to inspect current data and validity
* but the reference to this model will be broken if a new template is to be loaded due to a mode transition or other condition.
* Prefer using setApi and onChange to interact with the page.
*/
pageModel?: PageModel;
}
/**
* Component bindings to configure a page viewer for editing an existing object.
*/
export interface EditObjectPageBindings extends CommonPageViewerBindings {
bindingsType: PageViewerBindingsType.EditObject;
/** Page context to use. */
eventName: PageModeEvent.EDIT;
/** Entity type of the object. */
docType: string;
/** Object ID */
docId: string;
/** Use the given page template by UUID regardless of page context. */
templateUuid?: string;
/**
* Optionally provide a pageModel using window.sas.vi.pageModel.createFromObject.
* The pageModel type must match docType.
* The pageModel data will be populated using the loaded object response from the given docType and docId.
* The pageModel can be used to inspect current data and validity
* but the reference to this model will be broken if a new template is to be loaded due to a mode transition or other condition.
* Prefer using setApi and onChange to interact with the page.
*/
pageModel?: PageModel;
}
/**
* Component bindings to configure a page viewer for a read-only view of an existing object.
*/
export interface ViewObjectPageBindings extends CommonPageViewerBindings {
bindingsType: PageViewerBindingsType.ViewObject;
/** Page context to use. */
eventName: PageModeEvent.OPEN | PageModeEvent.INSPECT | PageModeEvent.SUMMARY;
/** Entity type of the object. */
docType: string;
/** Object ID */
docId: string;
/** Use the given page template by UUID regardless of page context. */
templateUuid?: string;
}
/**
* Component bindings to configure a page viewer for a read-only view of static object data.
*/
export interface StaticDataPageBindings extends CommonPageViewerBindings {
bindingsType: PageViewerBindingsType.StaticData;
/** Object data to create the page response. */
staticDocumentData: VIObject;
}
export interface CommonPageViewerBindings {
/** Show the page toolbar. This contains the toolbar actions associated with the object's Entity type. */
showToolbar?: boolean;
/**
* Assign the given CSS classes to the page viewer's container.
* This is the element which encompasses the main document view and the toolbar.
*/
containerClass?: string;
/** If true, the page viewer will fill its parent element's height. */
fitToContainerHeight?: boolean;
/**
* Assign the given CSS classes to the page viewer's main section.
* This is the element which displays the main document, excluding toolbar.
*/
pageClass?: string;
/**
* Enable workspace and insight tabs to be rendered.
*/
enableSheets?: boolean;
/**
* A callback which is called when the page viewer is initialized.
* It provides an API which can be used to check the page viewer state and save the document.
*/
setApi?: (api: PageViewerApi) => void;
/** A callback which is called when the page viewer dirty state changes. */
onDirty?: (isDirty: boolean) => void;
/** A callback which is called when the pageModel's mode or data changes. */
onChange?: (change: PageDataChange | PageModeChange) => void;
}
/** @deprecated use {@link PageViewerBindings} */
export interface PageBindings {
bindingsType?: never;
docId?: string;
docType?: string;
eventName?: string;
templateUuid?: string;
showToolbar?: boolean;
tempCreateId?: string;
containerClass?: string;
fitToContainerHeight?: boolean;
pageClass?: string;
enableSheets?: string;
pageModel?: PageModel;
staticDocumentData?: Record<string, any>;
initialCreateData?: Record<string, any>;
setApi?: (api: PageViewerApi) => void;
mainTab?: string;
onDirty?: (isDirty: boolean) => void;
onChange?: (change: PageDataChange | PageModeChange) => void;
}
export interface PagePreviewBindings {
templateUuid: string;
}
export interface ControlCollectionBindings {
controlContainer?: ControlContainer;
pageModel?: PageModel;
root?: boolean;
}
/**
* Defines the bindings for managing relationship details in a component.
*/
export interface RelationshipDetailsBindings {
/**
* Defines the identifier of the target object type that the relationship references.
*/
targetObjectTypeName: string;
/**
* Defines the display label of the target object type.
*/
targetObjectTypeLabel: string;
/**
* Defines the identifier of the parent object type that owns the relationship.
*/
parentObjectTypeName: string;
/**
* Specifies the user-friendly label of the parent object type.
*/
parentObjectTypeLabel: string;
/**
* Represents the list of reasons that define the purpose or context of the relationship.
*/
linkReasons: Relationship[];
/**
* Represents the currently selected item in the relationship, if applicable.
* Contains an object with `id` and `type` fields to identify the selected item.
*/
selectedItem?: {
id: string;
type: string;
};
/**
* Fields that are read-only and cannot be modified by the user within the relationships properties panel
*/
readOnlyFields?: string[];
/**
* Fields that are hidden and cannot be seen by the user within the relationships properties panel
*/
hiddenFields?: string[];
/**
* Contains the data for a new page model, if applicable.
* Includes a `PageModelObjectData` object to represent the model structure.
*/
newPageModel?: {
model: PageModelObjectData;
};
/**
* Callback invoked when a link reason is selected.
* @param linkReason - The selected link reason.
*/
onLinkReasonSelected: (linkReason: Relationship) => void;
/**
* Represents the current field values of the relationship as key-value pairs.
*/
relationshipValues?: Record<string, any>;
/**
* Represents the initial field values used to populate the related object during creation.
*/
initialCreateData?: Record<string, any>;
/**
* Callback to set the API for the page viewer.
* Provides a `PageViewerAPI` instance to the component.
* @param api - The `PageViewerAPI` instance.
*/
setApi?: (api: PageViewerApi) => void;
/**
* Callback invoked when the related page changes.
* Triggered by events such as data updates or mode transitions.
* @param change - The event describing the change, either `PageDataChange` or `PageModeChange`.
*/
onRelatedPageChange?: (change: PageDataChange | PageModeChange) => void;
/**
* Callback invoked when the relationship values are updated.
* Provides both the current and previous values for comparison.
* @param current - The updated relationship values.
* @param previous - The previous relationship values, if available.
*/
onRelationshipValuesChange?: (current: Record<string, any>, previous?: Record<string, any>) => void;
}
export interface SearchInputInputBindings {
entityName: string;
queryBuilderId?: string;
showQueryBuilder?: boolean;
queryText?: string;
autoFocus?: boolean;
queryBuilderOkButtonLabel?: string;
queryModel?: QueryBuilderModel;
performSearch?: boolean;
}
export interface QueryBuilderModel {
manualQueryString?: string;
model: QueryBuilderEntityModel[];
}
export interface QueryBuilderEntityModel {
entity: string;
queries: QueryBuilderItem[];
singleChildSearch?: boolean;
}
export interface QueryBuilderItem {
booleanValue?: boolean | string;
boost?: number;
dateTimeValue?: string | Date;
dateValue?: string | Date;
exclude?: boolean;
field?: string;
fromDateTimeValue?: string | Date;
fromDateValue?: string | Date;
fromNumericValue?: number;
numericValue?: number;
operator?: string;
phonetic?: boolean;
previousField?: string;
proximity?: number;
rangeValidationError?: boolean;
referenceValue?: string;
relationshipField?: boolean;
relationshipTypeValue?: string;
relativeDateDatetimeNumericValue?: number;
relativeDateDatetimeUnitsValue?: string;
stringValidationError?: boolean;
synonym?: boolean;
textValue?: string;
toDateTimeValue?: string | Date;
toDateValue?: string | Date;
toNumericValue?: number;
userGroupValue?: Array<{
id: string;
type: string;
}>;
}
export interface SearchInputBindings extends SearchInputInputBindings {
onSearch?: (model: SearchQuery) => void;
onValueChange?: (val: string) => void;
}
export interface TimeSliderInputBindings {
timeSliderId: string;
timeSliderDates: TimeSliderEventDates;
viewRange: TimeSliderRange;
handleType?: HandleType;
isReadOnly?: boolean;
sliderWidth?: number;
disableSwitchHandleType?: boolean;
contextMenuHideOptions: TimeSliderContextMenuHideOptions;
minMaxDates?: MinMaxDates;
}
export interface TimeSliderBindings extends TimeSliderInputBindings {
rangeChangeEvent?: (rangeChangedEvent: TimeSliderRangeChangedEvent) => void;
handleTypeChange?: (handleType: HandleType) => void;
onLoad?: () => void;
close?: () => void;
}
export type SviComponentBindings = ControlCollectionBindings | RelationshipDetailsBindings | SearchInputBindings | PageViewerBindings | PagePreviewBindings | SearchAndSelectWithPreviewBindings | TimeSliderBindings;