Skip to content

Commit

Permalink
DataViews Quick Edit: Add the PostActions dropdown menu (#64393)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
4 people authored and getdave committed Aug 14, 2024
1 parent 7362d6b commit 131f1c3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
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

0 comments on commit 131f1c3

Please sign in to comment.