import React from "react"; import { canCreateEntity, canDeleteEntity, fullPathToCollectionSegments } from "../../util"; import { useAuthController, useCustomizationController, useFireCMSContext, useLargeLayout } from "../../hooks"; import { CollectionActionsProps, EntityCollection, EntityTableController, SelectionController } from "../../types"; import { AddIcon, Button, DeleteIcon, IconButton, Tooltip } from "@firecms/ui"; import { toArray } from "../../util/arrays"; import { ErrorBoundary } from "../ErrorBoundary"; export type EntityCollectionViewActionsProps> = { collection: EntityCollection; path: string; relativePath: string; parentCollectionIds: string[]; selectionEnabled: boolean; onNewClick: () => void; onMultipleDeleteClick: () => void; selectionController: SelectionController; tableController: EntityTableController; collectionEntitiesCount: number; } export function EntityCollectionViewActions>({ collection, relativePath, parentCollectionIds, onNewClick, onMultipleDeleteClick, selectionEnabled, path, selectionController, tableController, collectionEntitiesCount }: EntityCollectionViewActionsProps) { const context = useFireCMSContext(); const customizationController = useCustomizationController(); const plugins = customizationController.plugins ?? []; const authController = useAuthController(); const largeLayout = useLargeLayout(); const selectedEntities = selectionController.selectedEntities; const addButton = canCreateEntity(collection, authController, path, null) && onNewClick && (largeLayout ? : ); const multipleDeleteEnabled = canDeleteEntity(collection, authController, path, null); let multipleDeleteButton: React.ReactNode | undefined; if (selectionEnabled) { const button = largeLayout ? : ; multipleDeleteButton = {button} } const actionProps: CollectionActionsProps = { path, relativePath, parentCollectionIds, collection, selectionController, context, tableController, collectionEntitiesCount }; const actions = toArray(collection.Actions) .map((Action, i) => ( )); if (plugins) { plugins.forEach((plugin, i) => { if (plugin.collectionView?.CollectionActions) { actions.push(...toArray(plugin.collectionView?.CollectionActions) .map((Action, j) => ( ))); } }); } return ( <> {actions} {multipleDeleteButton} {addButton} ); }