Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews Quick Edit: Add the PostActions dropdown menu #64393

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions docs/reference-guides/slotfills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ export default function PostSummary( { onActionPerformed } ) {
const { isRemovedPostStatusPanel } = useSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was programmatically removed. We do
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
const { isEditorPanelRemoved, getCurrentPostType } =
const { isEditorPanelRemoved } =
select( editorStore );
return {
isRemovedPostStatusPanel: isEditorPanelRemoved( PANEL_NAME ),
postType: getCurrentPostType(),
};
}, [] );

Expand All @@ -85,11 +84,7 @@ export default function PostSummary( { onActionPerformed } ) {
<>
<VStack spacing={ 4 }>
<PostCardPanel
actions={
<PostActions
onActionPerformed={ onActionPerformed }
/>
}
onActionPerformed={ onActionPerformed }
/>
<PostFeaturedImagePanel withPanelBody={ false } />
<PostExcerptPanel />
Expand Down
36 changes: 16 additions & 20 deletions packages/editor/src/components/post-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { store as coreStore } from '@wordpress/core-data';
*/
import { unlock } from '../../lock-unlock';
import { usePostActions } from './actions';
import { store as editorStore } from '../../store';

const {
DropdownMenuV2: DropdownMenu,
Expand All @@ -27,25 +26,23 @@ const {
kebabCase,
} = unlock( componentsPrivateApis );

export default function PostActions( { onActionPerformed, buttonProps } ) {
export default function PostActions( { postType, postId, onActionPerformed } ) {
const [ isActionsMenuOpen, setIsActionsMenuOpen ] = useState( false );
const { item, permissions, postType } = useSelect( ( select ) => {
const { getCurrentPostType, getCurrentPostId } = select( editorStore );
const { getEditedEntityRecord, getEntityRecordPermissions } = unlock(
select( coreStore )
);
const _postType = getCurrentPostType();
const _id = getCurrentPostId();
return {
item: getEditedEntityRecord( 'postType', _postType, _id ),
permissions: getEntityRecordPermissions(
'postType',
_postType,
_id
),
postType: _postType,
};
}, [] );
const { item, permissions } = useSelect(
( select ) => {
const { getEditedEntityRecord, getEntityRecordPermissions } =
unlock( select( coreStore ) );
return {
item: getEditedEntityRecord( 'postType', postType, postId ),
permissions: getEntityRecordPermissions(
'postType',
postType,
postId
),
};
},
[ postId, postType ]
);
const itemWithPermissions = useMemo( () => {
return {
...item,
Expand Down Expand Up @@ -76,7 +73,6 @@ export default function PostActions( { onActionPerformed, buttonProps } ) {
onClick={ () =>
setIsActionsMenuOpen( ! isActionsMenuOpen )
}
{ ...buttonProps }
/>
}
onOpenChange={ setIsActionsMenuOpen }
Expand Down
13 changes: 11 additions & 2 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ import {
GLOBAL_POST_TYPES,
} from '../../store/constants';
import { unlock } from '../../lock-unlock';
import PostActions from '../post-actions';

export default function PostCardPanel( { postType, postId, actions } ) {
export default function PostCardPanel( {
postType,
postId,
onActionPerformed,
} ) {
const { isFrontPage, isPostsPage, title, icon, isSync } = useSelect(
( select ) => {
const { __experimentalGetTemplateInfo } = select( editorStore );
Expand Down Expand Up @@ -105,7 +110,11 @@ export default function PostCardPanel( { postType, postId, actions } ) {
</span>
) }
</Text>
{ actions }
<PostActions
postType={ postType }
postId={ postId }
onActionPerformed={ onActionPerformed }
/>
</HStack>
</div>
);
Expand Down
7 changes: 1 addition & 6 deletions packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useSelect } from '@wordpress/data';
* Internal dependencies
*/
import PluginPostStatusInfo from '../plugin-post-status-info';
import PostActions from '../post-actions';
import PostAuthorPanel from '../post-author/panel';
import PostCardPanel from '../post-card-panel';
import PostContentInformation from '../post-content-information';
Expand Down Expand Up @@ -63,11 +62,7 @@ export default function PostSummary( { onActionPerformed } ) {
<PostCardPanel
postType={ postType }
postId={ postId }
actions={
<PostActions
onActionPerformed={ onActionPerformed }
/>
}
onActionPerformed={ onActionPerformed }
/>
<PostFeaturedImagePanel withPanelBody={ false } />
<PostExcerptPanel />
Expand Down
Loading