import React, { PureComponent, type ReactElement } from 'react'; import { type ModelIndex, type MoveOperation } from '@deephaven/grid'; import type { dh } from '@deephaven/jsapi-types'; import memoize from 'memoizee'; import { type DragStartEvent } from '@dnd-kit/core'; import type { Key } from '@react-types/shared'; import { type Virtualizer } from '@tanstack/react-virtual'; import './VisibilityOrderingBuilder.scss'; import { type DisplayColumn } from '../../IrisGridModel'; import type IrisGridModel from '../../IrisGridModel'; import { type ColumnName } from '../../CommonTypes'; import ColumnHeaderGroup from '../../ColumnHeaderGroup'; import { type FlattenedIrisGridTreeItem, type IrisGridTreeItem, type IrisGridTreeItemData } from './sortable-tree/utilities'; import { type TreeItemRenderFnProps } from './sortable-tree/TreeItem'; export interface VisibilityOrderingBuilderProps { model: IrisGridModel; movedColumns: readonly MoveOperation[]; hiddenColumns: readonly ModelIndex[]; columnHeaderGroups: readonly ColumnHeaderGroup[]; onColumnVisibilityChanged: (columns: readonly ModelIndex[], isVisible: boolean) => void; onReset: () => void; onMovedColumnsChanged: (operations: readonly MoveOperation[], cb?: () => void) => void; onColumnHeaderGroupChanged: (groups: readonly ColumnHeaderGroup[]) => void; onFrozenColumnsChanged: (columns: readonly ColumnName[]) => void; __testRef?: React.Ref; } interface VisibilityOrderingBuilderInnerProps extends Omit { undo: () => void; redo: () => void; canUndo: boolean; canRedo: boolean; startUndoGroup: () => void; endUndoGroup: () => void; } interface VisibilityOrderingBuilderInnerState { selectedColumns: Set; lastSelectedColumn: string; isSearchModalOpen: boolean; showHiddenColumns: boolean; /** * This is used only for drag end. In React 18, it seems our rendering is causing * 1 render with just the children of this component, then updating to render with the * updated movedColumns prop. That is causing the drop animation to animate back to * the original position of the element. */ movedColumns: readonly MoveOperation[]; /** * This is used for the same reason as movedColumns above, but for dragging in/out of groups. */ columnHeaderGroups: readonly ColumnHeaderGroup[]; } declare class VisibilityOrderingBuilderInner extends PureComponent { static SORTING_OPTIONS: { readonly DSC: "DSC"; readonly ASC: "ASC"; }; static MOVE_OPTIONS: { readonly TOP: "TOP"; readonly BOTTOM: "BOTTOM"; readonly UP: "UP"; readonly DOWN: "DOWN"; }; static shouldRenderColumn(column: DisplayColumn): boolean; constructor(props: VisibilityOrderingBuilderInnerProps); componentDidMount(): void; componentDidUpdate(prevProps: VisibilityOrderingBuilderInnerProps): void; componentWillUnmount(): void; wrapperRef: React.RefObject; /** * Used to track the last focused item index to maintain focus on updates. * Cannot use name because it may change or be deleted when undoing or redoing. */ lastFocusedItemIndex: number | null; list: HTMLDivElement | null; virtualizerRef: React.RefObject>; /** * This is set by the search modal handlers since a column could be hidden * and not displayed in the list. We need to wait until the update to scroll to it. */ scrollAndFocusColumnOnUpdate: [number, string] | null; resetVisibilityOrdering(): void; resetSelection(): void; /** * Moves the currently selected columns in the direction specified. * Does not commit any changes to any state, just gets the required modifications. * * Items that are part of a selected group should not be moved separate from the group. * * Items moved to top or bottom should be removed from any groups they are within, * unless part of a group that is also selected. The highest level selected group will * be moved to the root level of the tree. * * Items moved up or down should move into and out of groups when applicable. * They should never move more than 1 depth level at a time. * * Multiple selected items should move to the top or bottom in their existing order, * but become one block of continuous columns. * * Multiple selected items moving up or down should move independently, * unless they are at the same depth and contiguous. In that case, they should * move in and out of groups together. I.e. if the 2 items above a group are selected, * and the move down button is pressed, then both items should be moved into the group. * * @param option The movement option * @returns A new copy of the movedColumns including moves required to perform the operation. * */ moveSelectedColumns(option: keyof typeof VisibilityOrderingBuilderInner.MOVE_OPTIONS): { newMoves: MoveOperation[]; groups: readonly ColumnHeaderGroup[]; }; /** * Moves the selected columns according to the option. * Commits changes to state and scrolls the list if moving to top or bottom. * * @param option The move operation */ handleMoveColumns(option: keyof typeof VisibilityOrderingBuilderInner.MOVE_OPTIONS): void; /** * Get the move operations required to recursively sort the grid * Column header groups are sorted using their name * Children of column header groups are then sorted within each group * * @param items The tree items to sort * @param option Direction of the sort * @param movedColumns The existing moved columns for the sort * Grids may use an initial move list from the model (e.g. column header groups) * Also used to recursively sort header groups * @returns The moves required to sort the grid. Includes the starting movedColumns in the array */ getSortMoves(itemsParam: readonly IrisGridTreeItem[], option: keyof typeof VisibilityOrderingBuilderInner.SORTING_OPTIONS, movedColumns: readonly MoveOperation[]): MoveOperation[]; handleSortColumns(option: keyof typeof VisibilityOrderingBuilderInner.SORTING_OPTIONS): void; /** * Handles clicking on an item in the visibility ordering list. * Adds and removes to selection as necessary based on modifier and shift keys. * Returns the columns to be added to the selection, if any. * * @param name The name of the column clicked * @param event The click event * @param showHiddenColumns If hidden columns should be included in the selection * @returns The columns to be added to the selection, if any` */ handleItemClick(name: string, event: React.MouseEvent, showHiddenColumns?: boolean): string[]; handleSearchItemClicked(item: FlattenedIrisGridTreeItem, event: React.MouseEvent): void; handleSearchSelect(items: readonly FlattenedIrisGridTreeItem[]): void; /** * Adds columns or groups to the selected column set * Groups being added will add all of their children to the selection as well * * @param columnsToBeAdded Array of column or group names to add * @param addToExisting If these should be added to the existing selection or overwrite it */ addColumnToSelected(columnsToBeAdded: string[], addToExisting: boolean): void; /** * Removes a column or group from selected columns set. * * Removing a group will deselect all of its children. * * Removing a child will deselect all parent groups. * Other children in those parents will stay selected, just not the group item. * * @param name Name of the column to remove */ removeColumnFromSelected(name: string): void; handleDragStart(id: string, event: DragStartEvent): void; handleDragEnd(from: FlattenedIrisGridTreeItem, to: FlattenedIrisGridTreeItem): void; handleGroupNameChange(group: ColumnHeaderGroup, newName: string): void; handleGroupColorChange: import("lodash").DebouncedFuncLeading<(group: ColumnHeaderGroup, color: string | undefined) => void>; handleGroupDelete(group: ColumnHeaderGroup): void; handleGroupCreate(): void; /** * Validates if a header group name is valid and not in use by any header groups or columns * @param groupName The name to validate * @returns Error message if invalid */ validateGroupName(groupName: string): string; renderItem({ value, clone, item, ref, handleProps, }: TreeItemRenderFnProps): JSX.Element; getMemoizedFirstMovableIndex: ((model: IrisGridModel, columns: readonly dh.Column[], movedColumns: readonly MoveOperation[]) => number | null) & memoize.Memoized<(model: IrisGridModel, columns: readonly dh.Column[], movedColumns: readonly MoveOperation[]) => number | null>; /** * Gets the first movable visible index */ getFirstMovableIndex(): number | null; getMemoizedLastMovableIndex: ((model: IrisGridModel, columns: readonly dh.Column[], movedColumns: readonly MoveOperation[]) => number | null) & memoize.Memoized<(model: IrisGridModel, columns: readonly dh.Column[], movedColumns: readonly MoveOperation[]) => number | null>; /** * Gets the last movable visible index */ getLastMovableIndex(): number | null; memoizedGetTreeItems: ((columns: readonly dh.Column[], movedColumns: readonly MoveOperation[], columnHeaderGroups: readonly ColumnHeaderGroup[], hiddenColumns: readonly ModelIndex[], selectedColumns: ReadonlySet, showHiddenColumns: boolean) => readonly IrisGridTreeItem[]) & memoize.Memoized<(columns: readonly dh.Column[], movedColumns: readonly MoveOperation[], columnHeaderGroups: readonly ColumnHeaderGroup[], hiddenColumns: readonly ModelIndex[], selectedColumns: ReadonlySet, showHiddenColumns: boolean) => readonly IrisGridTreeItem[]>; /** * Gets the tree items in order. Memoized for efficiency * Use this.getFlattenedTree() if a flat list is needed * @param showHiddenColumns Whether to show hidden columns in the tree. Defaults to the current state value. * @returns The tree items in order */ getTreeItems(showHiddenColumns?: boolean): readonly IrisGridTreeItem[]; memoizedGetFlattenedTree: ((treeItems: readonly IrisGridTreeItem[]) => readonly FlattenedIrisGridTreeItem[]) & memoize.Memoized<(treeItems: readonly IrisGridTreeItem[]) => readonly FlattenedIrisGridTreeItem[]>; /** * Gets the flattened tree items in order. Memoized for efficiency * @param showHiddenColumns Whether to show hidden columns in the tree. Defaults to the current state value. * @returns The flattened tree items in order */ getFlattenedTree(showHiddenColumns?: boolean): readonly FlattenedIrisGridTreeItem[]; getSelectedItemModelIndexes(columnNames: Set): ModelIndex[]; /** * Gets the selected items that are movable. * This is any item whose parent is not also selected. * * @returns The array of items whose parents are not selected */ getSelectedParentItems(): FlattenedIrisGridTreeItem[]; makeVisibilityOrderingList: ((columns: readonly DisplayColumn[], treeItems: readonly FlattenedIrisGridTreeItem[], showHiddenColumns: boolean, isDraggable: boolean) => import("react/jsx-runtime").JSX.Element[]) & memoize.Memoized<(columns: readonly DisplayColumn[], treeItems: readonly FlattenedIrisGridTreeItem[], showHiddenColumns: boolean, isDraggable: boolean) => import("react/jsx-runtime").JSX.Element[]>; renderImmovableItem: ((columnName: ColumnName) => ReactElement) & memoize.Memoized<(columnName: ColumnName) => ReactElement>; handleOverflowAction(key: Key): void; handleKeyboardShortcut(event: React.KeyboardEvent): void; handleSearchModalOpenChange(isOpen: boolean): void; render(): ReactElement; } declare const VisibilityOrderingBuilder: React.MemoExoticComponent<(props: VisibilityOrderingBuilderProps) => import("react/jsx-runtime").JSX.Element>; export default VisibilityOrderingBuilder; //# sourceMappingURL=VisibilityOrderingBuilder.d.ts.map