import { AddIcon, CheckmarkIcon, ChevronLeftIcon, ChevronRightIcon, FolderIcon, SyncIcon, } from '@sanity/icons'; import { Box, Button, Card, Checkbox, Flex, Label, Select, Text, ThemeProvider, ToastProvider, Tooltip, } from '@sanity/ui'; import { buildTheme } from '@sanity/ui/theme'; import classNames from 'classnames'; import get from 'lodash.get'; import pluralize, { singular } from 'pluralize'; import { useMemo, useRef } from 'react'; import { Preview } from 'sanity'; import { ListItem, usePaneRouter } from 'sanity/structure'; import BulkActionsMenu from './BulkActionsMenu'; import ColumnSelector from './ColumnSelector'; import SearchField from './SearchField'; import { Options, defaultDatetimeFields, orderColumnDefault, rowsPerPage, } from './constants'; import { BulkActionsTableProvider, useBulkActionsTableContext, } from './context'; import createEmitter from './createEmitter'; import { SelectableField, getSelectableFields, } from './helpers/getSelectableFields'; import { COLUMN_SELECTOR_WIDTH, CheckboxCellTd, CheckboxCellTh, CheckboxFacade, ColumnSelectBodyCell, ColumnSelectHeadCell, Container, HiddenCheckbox, LoadingOverlay, LoadingSpinner, StatusBadge, Table as StyledTable, TableWrapper, } from './styles'; import Cell from './table/Cell'; import { TableHeadCell } from './table/TableHeadCell'; import { CellPrimitive, RowPrimitive, TableHeadPrimitive, } from './table/primitives'; import { CreateBulkActionsTableConfig } from './types'; function parentHasClass(el: HTMLElement | null, className: string): boolean { if (!el) return false; if (el.classList.contains(className)) return true; return parentHasClass(el.parentElement, className); } interface BulkActionsTableProps { options: Options; } // Type for fields that can be either real SelectableField or mock fields for built-in columns type TableField = | SelectableField | { fieldPath: string; title: string | undefined; level: number; sortable: boolean; type: string; field: { type: { name: string } }; }; const nonSchemaFields = defaultDatetimeFields.map( ({ key, title, sortable }) => ({ fieldPath: key, title, field: { type: { name: key } }, level: 0, sortable, type: key, // Add the missing type property }), ); const ActionRow = () => { const { navigateIntent } = usePaneRouter(); const { options: { type, client }, selectedIds, setSelectedIds, paginatedClient, schemaType, isSelectState, setIsSelectState, } = useBulkActionsTableContext(); return ( {isSelectState ? ( {selectedIds.size === 0 ? 'Select items' : `${selectedIds.size} item${selectedIds.size === 1 ? '' : 's'} selected`} {selectedIds.size > 0 && ( { setSelectedIds(new Set()); paginatedClient.setPage(0); paginatedClient.refresh(); }} /> )} Cancel bulk selection } delay={{ open: 400 }} padding={1} placement="bottom" portal >