import React, { useEffect } from 'react'; import { FiltersMap } from '@wix/bex-core'; import { GridPresetProps } from './Grid.types'; import { GridState, LayoutType } from '../../state'; import { getToolbarCollectionFeaturesInitializers } from '../../state/getToolbarCollectionFeaturesInitializers'; import { ToolbarCollectionContentAutoSizer } from '../ToolbarCollectionContentAutoSizer'; import { BulkActionToolbarRenderProp } from '../BulkAction'; import { GridItemBaseProps } from './GridItemBaseProps'; import { GridPlaceholderStates } from './GridPlaceholderStates'; import { CollectionCard } from '../CollectionCard'; import { ToolbarCollection, ToolbarCollectionBaseProps, } from '../ToolbarCollection'; import { observer } from 'mobx-react-lite'; import { useToolbarCollectionSyncProps } from '../ToolbarCollection/useToolbarCollectionSyncProps'; import type { GridSectionsContent } from '../GridSections/GridSectionsContent'; import type { GroupBy, RenderSection } from '../CollectionSectionHeader'; import { GridSingleGridContent } from './GridSingleGridContent'; import { GridDragAndDrop } from '../GridDragAndDropDndKit/GridDragAndDrop'; interface GridBaseProps extends Omit, 'sticky' | 'maxSelection'>, GridItemBaseProps { dataHook?: string; /** * Adds functionality to allow visitors to reorder items manually. * For more information, see the [Drag and Drop Overview](./?path=/story/features-sort-drag-and-drop--overview). * @overrideType [GridDragAndDrop](./?path=/story/features-sort-drag-and-drop--griddraganddrop) * @external */ dragAndDrop?: typeof GridDragAndDrop; /** * Grid state instance created using [`useGridCollection`](./?path=/story/base-components-collections-grid-usegridcollection--usegridcollection). * @overrideType [GridState](./?path=/story/base-components-collections-grid-gridstate--gridstate) * @external */ state: GridState; /** * A toolbar for performing bulk actions on multiple items.

* Supported parameters:
* -`selectedValues`: [array] Items that are checked in the selection column.
* -`uncheckedValues`: [array] Items that are unchecked in the selection column.
* -`isSelectAll`: [bool] Whether **Select All** is checked.
* -`openModal`: [func] Opens a modal that contains the component from `bulkActionModal` render prop.
* -`clearSelection`: [func] Clears all selections. Call this after the action on the selected items finishes.
* -`total`: [number] Total number of items in the server.
* -`openConfirmModal`: [func] Opens a `` to confirm an action is about to be applied to the selected items.
* -`query`: [object] Current paging, sorting, and filtering. Often used together with bulk actions, such as `updateAll`.
* @external */ bulkActionToolbar?: BulkActionToolbarRenderProp; /** * Creates [grid sections](./?path=/story/features-display-grid-sections--grid-sections) that group data based on the values of a specific field. * @external * @overrideType [SectionsProp](./?path=/story/common-types--sectionsprop) */ sections?: { GridSections: typeof GridSectionsContent; groupBy: GroupBy; renderSection?: RenderSection; }; layoutType?: LayoutType; } export type GridBasePropsWithoutPreset = Omit< GridBaseProps, 'preset' | 'renderItem' >; export type GridProps = GridPresetProps< T, GridBasePropsWithoutPreset >; function _Grid(props: GridProps) { const { state, dragAndDrop, renderError, errorState = renderError && (((err, { isOnline, retry }) => renderError?.({ err, isOnline, retry })) as GridProps< T, F >['errorState']), emptyState, noResultsState, cardProps, dataHook, exportModal, importModal, sections, } = props; const { toolbar } = state; useToolbarCollectionSyncProps({ ...props, state: state.toolbar, isUsingDragAndDrop: !!dragAndDrop, isUsingBulkActionsToolbar: false, isUsingHorizontalScroll: false, isUsingFolders: false, isUsingTableVirtualization: false, }); useEffect( () => state.init({ featuresInitializers: getToolbarCollectionFeaturesInitializers(props), }), [], ); return ( {sections ? ( ) : ( )} {exportModal ?? toolbar.featuredComponents.exportModal.value} {importModal ?? toolbar.featuredComponents.importModal.value} ); } export const Grid = observer(_Grid);