import { ContentObjectTypeItem } from '@vertesia/common'; import { Button, Popover, PopoverContent, PopoverTrigger, SelectList } from '@vertesia/ui/core'; import clsx from 'clsx'; import { EllipsisVertical, X } from 'lucide-react'; import { useState } from "react"; import { useUITranslation } from '../../../../i18n/index.js'; import { DocumentSelection, useDocumentSelection } from "../DocumentSelectionProvider.js"; import { DocumentUploadModal } from "../upload/DocumentUploadModal.js"; import { ExportPropertiesAction } from "./actions/ExportPropertiesAction"; import { StartWorkflowAction } from "./actions/StartWorkflowComponent"; import { ObjectsActionContextProvider } from "./ObjectsActionContext"; import { useObjectsActionContext } from "./ObjectsActionHooks"; import { ObjectsActionSpec } from "./ObjectsActionSpec"; interface SelectionActionsProps { type?: ContentObjectTypeItem; } export function SelectionActions({ type }: SelectionActionsProps) { const selection = useDocumentSelection(); const size = selection.size(); const plural = size > 1 ? "s" : ""; const hasSelection = selection?.hasSelection(); const hasSingleSelection = selection?.isSingleSelection(); const onClearSelection = () => { selection?.removeAll(); }; return (
{hasSelection && !hasSingleSelection &&
{size} document{plural} selected
} {/* StartWorkflowButton must be inside the context */} {hasSelection && }
) } // Wrapper component that accesses the context interface ActionsWrapperProps { selection: DocumentSelection; } function ActionsWrapper({ }: ActionsWrapperProps) { return ; } export function UploadObjectsButton({ collectionId, allowFolders = true }: { collectionId?: string, allowFolders?: boolean }) { const { t } = useUITranslation(); const [files, setFiles] = useState([]); const [isOpen, setIsOpen] = useState(false); const onClose = () => { setIsOpen(false); setFiles([]); } return ( <> { if (result && result.success) { setFiles([]); } }} allowFolders={allowFolders} > ); } function StartWorkflowButton() { const ctx = useObjectsActionContext(); const { t } = useUITranslation(); const selection = ctx.params.selection; const hasSelection = selection.hasSelection(); return ( hasSelection && ) } function optionLayout(option: ObjectsActionSpec) { return { label: option.name, className: clsx('flex-1 px-2 py-2 hover:bg-accent nowrap', option.destructive ? 'text-destructive' : ''), }; } interface SelectionActionsPopoverProps { children: React.ReactNode; selection: DocumentSelection; } function SelectionActionsPopover({ selection, children }: SelectionActionsPopoverProps) { const context = useObjectsActionContext(); const executeAction = (action: ObjectsActionSpec) => { context.run(action.id); }; return ( {children} ) } interface PopoverBodyProps { executeAction: (action: ObjectsActionSpec) => void; selection: DocumentSelection; } function PopoverBody({ executeAction, selection }: PopoverBodyProps) { const context = useObjectsActionContext(); const _executeAction = (action: ObjectsActionSpec) => { executeAction(action); } const _selection = selection?.hasSelection() ? context.actions.filter((action: ObjectsActionSpec) => !action.hideInList) : [ExportPropertiesAction]; return (
); }