From 48204bc0b4ccbb0c4c023cea30e1af3c9dca4040 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 12 Aug 2024 12:23:11 +0200 Subject: [PATCH 1/4] DataViews Quick Edit: Support access to quick edit from list views --- .../src/components/dataviews-actions/index.js | 30 +++++++++++++- .../edit-site/src/components/layout/router.js | 27 ++++++++++--- .../src/components/post-edit/index.js | 40 +++++++++++++++---- .../src/components/post-list/index.js | 18 ++++++--- 4 files changed, 94 insertions(+), 21 deletions(-) diff --git a/packages/edit-site/src/components/dataviews-actions/index.js b/packages/edit-site/src/components/dataviews-actions/index.js index 09b7597c6cb341..8f228f72ef63cb 100644 --- a/packages/edit-site/src/components/dataviews-actions/index.js +++ b/packages/edit-site/src/components/dataviews-actions/index.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { edit } from '@wordpress/icons'; +import { edit, settings } from '@wordpress/icons'; import { useMemo } from '@wordpress/element'; import { privateApis as routerPrivateApis } from '@wordpress/router'; @@ -41,3 +41,31 @@ export const useEditPostAction = () => { [ history ] ); }; + +export const useQuickEditPostAction = () => { + const history = useHistory(); + return useMemo( + () => ( { + id: 'quick-edit-post', + label: __( 'Quick Edit' ), + isPrimary: true, + icon: settings, + isEligible( post ) { + if ( post.status === 'trash' ) { + return false; + } + // It's eligible for all post types except theme patterns. + return post.type !== PATTERN_TYPES.theme; + }, + callback( items ) { + const post = items[ 0 ]; + history.push( { + postId: post.id, + postType: post.type, + quickEdit: true, + } ); + }, + } ), + [ history ] + ); +}; diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 3fd0cc560d9433..be3b8c0fb72905 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -78,12 +78,14 @@ export default function useLayoutAreas() { const { postType, postId, path, layout, isCustom, canvas, quickEdit } = params; const hasEditCanvasMode = canvas === 'edit'; + const history = useHistory(); useRedirectOldPaths(); // Page list if ( postType === 'page' ) { const isListLayout = layout === 'list' || ! layout; - const showQuickEdit = quickEdit && ! isListLayout; + const showQuickEdit = + quickEdit && window.__experimentalQuickEditDataViews; return { key: 'pages', areas: { @@ -94,21 +96,34 @@ export default function useLayoutAreas() { content={ } /> ), - content: , - preview: ! showQuickEdit && - ( isListLayout || hasEditCanvasMode ) && , + content: + showQuickEdit && isListLayout ? ( + { + history.push( { + postId, + postType, + } ); + } } + /> + ) : ( + + ), + preview: ( isListLayout || hasEditCanvasMode ) && , mobile: hasEditCanvasMode ? ( ) : ( ), - edit: showQuickEdit && ( + edit: showQuickEdit && ! isListLayout && ( ), }, widths: { content: isListLayout ? 380 : undefined, - edit: showQuickEdit ? 380 : undefined, + edit: showQuickEdit && ! isListLayout ? 380 : undefined, }, }; } diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index 0ec63589d97673..548fdb394e6f1c 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -6,13 +6,19 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { __, isRTL } from '@wordpress/i18n'; import { DataForm } from '@wordpress/dataviews'; import { useDispatch, useSelect } from '@wordpress/data'; import { store as coreDataStore } from '@wordpress/core-data'; -import { __experimentalVStack as VStack } from '@wordpress/components'; +import { + __experimentalVStack as VStack, + __experimentalHStack as HStack, + FlexBlock, + Button, +} from '@wordpress/components'; import { useState, useMemo, useEffect } from '@wordpress/element'; import { privateApis as editorPrivateApis } from '@wordpress/editor'; +import { chevronRight, chevronLeft } from '@wordpress/icons'; /** * Internal dependencies @@ -23,7 +29,7 @@ import { unlock } from '../../lock-unlock'; const { PostCardPanel } = unlock( editorPrivateApis ); -function PostEditForm( { postType, postId } ) { +function PostEditForm( { postType, postId, onBack } ) { const ids = useMemo( () => postId.split( ',' ), [ postId ] ); const { record } = useSelect( ( select ) => { @@ -89,9 +95,23 @@ function PostEditForm( { postType, postId } ) { return ( - { ids.length === 1 && ( - - ) } + + { onBack && ( +