-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4f8253
commit 4bffa01
Showing
12 changed files
with
217 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/edit-site/src/components/mosaic-view/batch-delete-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { trash } from '@wordpress/icons'; | ||
import { __, _n } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
import { useSelect, useDispatch, select as storeSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
export default function MosaicViewBatchDeleteButton() { | ||
const { selectedTemplates } = useSelect( ( select ) => { | ||
const { getSelectedTemplates } = select( editSiteStore ); | ||
return { | ||
selectedTemplates: getSelectedTemplates(), | ||
}; | ||
} ); | ||
const { revertTemplate, toggleSelectedTemplate } = useDispatch( | ||
editSiteStore | ||
); | ||
const { deleteEntityRecord } = useDispatch( coreStore ); | ||
return ( | ||
<Button | ||
onClick={ () => { | ||
if ( | ||
// eslint-disable-next-line no-alert | ||
window.confirm( | ||
_n( | ||
'Are you sure you want to delete or clear the customizations from the selected templates?', | ||
'Are you sure you want to delete or clear the customizations from the selected template?', | ||
selectedTemplates.length | ||
) | ||
) | ||
) { | ||
for ( const templateId of selectedTemplates ) { | ||
const template = storeSelect( | ||
coreStore | ||
).getEntityRecord( | ||
'postType', | ||
'wp_template', | ||
templateId | ||
); | ||
if ( template.has_theme_file ) { | ||
revertTemplate( template ); | ||
} else { | ||
deleteEntityRecord( | ||
'postType', | ||
'wp_template', | ||
templateId | ||
); | ||
} | ||
toggleSelectedTemplate( templateId ); | ||
} | ||
} | ||
} } | ||
isDestructive | ||
icon={ trash } | ||
label={ __( | ||
'Delete and remove customizations from selected templates' | ||
) } | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.