@@ -29,8 +29,8 @@ import MenuGroup from '../common/menu/MenuGroup';
2929import MenuItemButton from '../common/menu/MenuItemButton' ;
3030import EditorWorkflowToolbarButtons from './EditorWorkflowToolbarButtons' ;
3131
32- import type { WorkflowStatus } from '@staticcms/core/constants/publishModes' ;
3332import type { CollectionWithDefaults , EditorPersistOptions } from '@staticcms/core' ;
33+ import type { WorkflowStatus } from '@staticcms/core/constants/publishModes' ;
3434import type { FC , MouseEventHandler } from 'react' ;
3535
3636import './EditorToolbar.css' ;
@@ -41,6 +41,7 @@ export const classes = generateClassNames('EditorToolbar', [
4141 'more-menu-button' ,
4242 'more-menu-label-icon' ,
4343 'preview-toggle' ,
44+ 'discard-button' ,
4445 'delete-button' ,
4546 'publish-button' ,
4647 'publish-button-icon' ,
@@ -419,14 +420,34 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
419420 disabled = { disabled }
420421 />
421422 ) : null }
422- { canDelete ? (
423+ { hasChanged ? (
424+ < IconButton
425+ icon = { TrashIcon }
426+ key = "discard-button"
427+ title = { t ( 'editor.editorToolbar.discardChanges' ) }
428+ color = "warning"
429+ variant = "text"
430+ onClick = { handleDiscardDraft }
431+ rootClassName = { classes [ 'discard-button' ] }
432+ aria-label = "discard chnages"
433+ disabled = { disabled }
434+ />
435+ ) : canDelete &&
436+ ( ! useOpenAuthoring || hasUnpublishedChanges ) &&
437+ ( ! useWorkflow || workflowDeleteLabel ) ? (
423438 < IconButton
424439 icon = { TrashIcon }
425440 key = "delete-button"
426- title = { t ( 'editor.editorToolbar.deleteEntry' ) }
441+ title = { useWorkflow ? t ( workflowDeleteLabel ! ) : t ( 'editor.editorToolbar.deleteEntry' ) }
427442 color = "error"
428443 variant = "text"
429- onClick = { onDelete }
444+ onClick = {
445+ useWorkflow &&
446+ workflowDeleteLabel &&
447+ workflowDeleteLabel !== 'editor.editorToolbar.deletePublishedEntry'
448+ ? onDeleteUnpublishedChanges
449+ : onDelete
450+ }
430451 rootClassName = { classes [ 'delete-button' ] }
431452 aria-label = "delete"
432453 disabled = { disabled }
0 commit comments