import { HoistModel, PersistOptions } from '@xh/hoist/core'; import type { GridModel } from '@xh/hoist/cmp/grid'; import { View } from '@xh/hoist/data'; /** * Configuration for a {@link GroupingChooserModel} - a control for selecting multi-level * dimension groupings, typically bound to a Cube {@link View} or {@link GridModel}. * * @see GroupingChooserModel * @see DimensionSpec */ export interface GroupingChooserConfig { /** True to accept an empty list as a valid value. */ allowEmpty?: boolean; /** * Target ({@link GridModel} or Cube {@link View}) to which this model's grouping value * should be automatically applied as it changes. When bound to a GridModel, calls * `setGroupBy()`; when bound to a View, calls `updateQuery({dimensions: ...})`. * * This is a two-way binding - changes to the target's value are reflected back into * the GroupingChooserModel automatically. */ bind?: GroupingBindTarget; /** * False (default) waits for the user to dismiss the popover before updating the * external/observable value. */ commitOnChange?: boolean; /** * Dimensions available for selection. When using GroupingChooser to create Cube queries, * it is recommended to pass the `dimensions` from the related cube (or a subset thereof). * Note that {@link CubeField} meets the `DimensionSpec` interface. * * If omitted and `bind` is provided, dimensions will be auto-populated from the target: * fields with `isDimension: true` from a GridModel's store, or from a View's associated Cube. * If provided alongside `bind`, dimensions will be validated against the target's fields. */ dimensions?: (DimensionSpec | string)[]; /** * Initial favorites as an array of dim name arrays, or a function to produce such an array. * Ignored if `persistWith.persistFavorites: false`. */ initialFavorites?: string[][] | (() => string[][]); /** Initial value as an array of dimension names, or a function to produce such an array. */ initialValue?: string[] | (() => string[]); /** Maximum number of dimensions allowed in a single grouping. */ maxDepth?: number; /** Options governing persistence. */ persistWith?: GroupingChooserPersistOptions; /** * True (default) to auto-sort dimensions by label. Set to false to show them in the order * provided in the `dimensions` config. */ sortDimensions?: boolean; } export interface GroupingChooserModelDefaults { commitOnChange?: boolean; } /** * Metadata for dimensions that are available for selection via a GroupingChooser control. * Note that {@link CubeField} instances satisfy this interface. */ export interface DimensionSpec { /** Shortname or code (almost always a `CubeField.name`). */ name: string; /** User-friendly / longer name for display. */ displayName?: string; } export interface GroupingChooserPersistOptions extends PersistOptions { /** True (default) to include value or provide value-specific PersistOptions. */ persistValue?: boolean | PersistOptions; /** True (default) to include favorites or provide favorites-specific PersistOptions. */ persistFavorites?: boolean | PersistOptions; } /** Target to which GroupingChooser value changes should be automatically synced. */ export type GroupingBindTarget = GridModel | View; /** * Model for a control that allows users to select and order a list of dimensions for use with * grouping APIs, such as Grid `groupBy` or Cube queries. * * Manages the current dimension selection, available dimensions, user-managed favorites, and * drag-and-drop reordering. Supports bidirectional binding to a {@link GridModel} or Cube * {@link View} via the `bind` config - grouping changes are automatically applied to the * target, and external changes to the target are reflected back into this model. * * Dimensions can be auto-populated from the bind target or specified explicitly. When binding * to a Cube View, {@link CubeField} instances satisfy the {@link DimensionSpec} interface. * * Supports persistence of both the current value and favorites via `persistWith`. * * @see GroupingChooser */ export declare class GroupingChooserModel extends HoistModel { /** App-level defaults for GroupingChooserModel. Instance config takes precedence. */ static defaults: GroupingChooserModelDefaults; value: string[]; favorites: string[][]; allowEmpty: boolean; bind: GroupingBindTarget; commitOnChange: boolean; maxDepth: number; persistFavorites: boolean; sortDimensions: boolean; dimensions: Record; dimensionNames: string[]; get dimensionSpecs(): DimensionSpec[]; get valueDisplayNames(): string[]; constructor({ allowEmpty, bind, commitOnChange, dimensions, initialFavorites, initialValue, maxDepth, persistWith, sortDimensions }: GroupingChooserConfig); setDimensions(dimensions: Array): void; setValue(value: string[]): void; validateValue(value: string[]): boolean; getValueLabel(value: string[]): string; getDimDisplayName(dimName: string): string; get favoritesOptions(): { value: string[]; label: string; }[]; get hasFavorites(): boolean; setFavorites(favorites: string[][]): void; addFavorite(value: string[]): void; removeFavorite(value: string[]): void; isFavorite(value: string[]): boolean; private get targetValue(); private updateTargetValue; private get targetFields(); private getDimensionsFromTarget; private ensureDimensionsValid; private initPersist; private normalizeDimensions; private createDimension; private removeUnknownDimsFromValue; }