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 Pages: Dynamic Frame title as per active view for Pages and Templates editor pages #61983

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
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
33 changes: 20 additions & 13 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,28 @@ function useView( postType ) {
isCustom === 'false' &&
DEFAULT_VIEWS[ postType ].find(
( { slug } ) => slug === activeView
)?.view;
);
if ( isCustom === 'false' && layout ) {
return {
...defaultView,
type: layout,
layout: {
...( DEFAULT_CONFIG_PER_VIEW_TYPE[ layout ] || {} ),
view: {
...defaultView?.view,
type: layout,
layout: {
...( DEFAULT_CONFIG_PER_VIEW_TYPE[ layout ] || {} ),
},
},
};
}
return defaultView;
}, [ isCustom, activeView, layout, postType ] );
const [ view, setView ] = useState( selectedDefaultView );
const [ view, setView ] = useState( selectedDefaultView?.view );

useEffect( () => {
if ( selectedDefaultView ) {
setView( selectedDefaultView );
if ( selectedDefaultView?.view ) {
setView( selectedDefaultView.view );
}
}, [ selectedDefaultView ] );
}, [ selectedDefaultView?.view ] );
const editedViewRecord = useSelect(
( select ) => {
if ( isCustom !== 'true' ) {
Expand Down Expand Up @@ -141,12 +144,16 @@ function useView( postType ) {
);

if ( isCustom === 'false' ) {
return [ view, setDefaultViewAndUpdateUrl ];
return [ view, setDefaultViewAndUpdateUrl, selectedDefaultView?.title ];
} else if ( isCustom === 'true' && customView ) {
return [ customView, setCustomView ];
return [ customView, setCustomView, selectedDefaultView?.title ];
}
// Loading state where no the view was not found on custom views or default views.
return [ DEFAULT_VIEWS[ postType ][ 0 ].view, setDefaultViewAndUpdateUrl ];
return [
DEFAULT_VIEWS[ postType ][ 0 ].view,
setDefaultViewAndUpdateUrl,
DEFAULT_VIEWS[ postType ][ 0 ].title,
];
}

// See https://github.com/WordPress/gutenberg/issues/55886
Expand Down Expand Up @@ -203,7 +210,7 @@ function FeaturedImage( { item, viewType } ) {

export default function PagePages() {
const postType = 'page';
const [ view, setView ] = useView( postType );
const [ view, setView, viewTitle ] = useView( postType );
const history = useHistory();

const onSelectionChange = useCallback(
Expand Down Expand Up @@ -494,7 +501,7 @@ export default function PagePages() {

return (
<Page
title={ __( 'Pages' ) }
title={ viewTitle }
actions={
addNewLabel && (
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export default function PageTemplates() {
return (
<Page
className="edit-site-page-templates"
title={ __( 'Templates' ) }
title={ 'all' === activeView ? __( 'All templates' ) : activeView }
actions={ <AddNewTemplate /> }
>
<DataViews
Expand Down
Loading