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: Fix default layouts in the pages data views #63427

Merged
merged 1 commit into from
Jul 11, 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
46 changes: 4 additions & 42 deletions packages/edit-site/src/components/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Page from '../page';
import { default as Link, useLink } from '../routes/link';
import {
useDefaultViews,
DEFAULT_CONFIG_PER_VIEW_TYPE,
defaultLayouts,
} from '../sidebar-dataviews/default-views';
import {
LAYOUT_GRID,
Expand All @@ -62,24 +62,6 @@ import { usePrevious } from '@wordpress/compose';
const { usePostActions } = unlock( editorPrivateApis );
const { useLocation, useHistory } = unlock( routerPrivateApis );
const EMPTY_ARRAY = [];
const defaultLayouts = {
[ LAYOUT_TABLE ]: {
layout: {
'featured-image': {
width: '1%',
},
title: {
maxWidth: 300,
},
},
},
[ LAYOUT_GRID ]: {
layout: {},
},
[ LAYOUT_LIST ]: {
layout: {},
},
};

const getFormattedDate = ( dateToDisplay ) =>
dateI18n(
Expand All @@ -103,9 +85,7 @@ function useView( postType ) {
return {
...defaultView,
type: layout,
layout: {
...( DEFAULT_CONFIG_PER_VIEW_TYPE[ layout ] || {} ),
},
layout: defaultLayouts[ layout ]?.layout,
};
}
return defaultView;
Expand Down Expand Up @@ -144,9 +124,7 @@ function useView( postType ) {

return {
...storedView,
layout: {
...( DEFAULT_CONFIG_PER_VIEW_TYPE[ storedView?.type ] || {} ),
},
layout: defaultLayouts[ storedView?.type ]?.layout,
};
}, [ editedViewRecord?.content ] );

Expand Down Expand Up @@ -587,22 +565,6 @@ export default function PostList( { postType } ) {
[ postTypeActions, editAction ]
);

const onChangeView = useCallback(
( newView ) => {
if ( newView.type !== view.type ) {
newView = {
...newView,
layout: {
...DEFAULT_CONFIG_PER_VIEW_TYPE[ newView.type ],
},
};
}

setView( newView );
},
[ view.type, setView ]
);

const [ showAddPostModal, setShowAddPostModal ] = useState( false );

const openModal = () => setShowAddPostModal( true );
Expand Down Expand Up @@ -648,7 +610,7 @@ export default function PostList( { postType } ) {
data={ records || EMPTY_ARRAY }
isLoading={ isLoadingMainEntities || isLoadingAuthors }
view={ view }
onChangeView={ onChangeView }
onChangeView={ setView }
selection={ selection }
setSelection={ setSelection }
onSelectionChange={ onSelectionChange }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,31 @@ import {
OPERATOR_IS_ANY,
} from '../../utils/constants';

export const DEFAULT_CONFIG_PER_VIEW_TYPE = {
export const defaultLayouts = {
[ LAYOUT_TABLE ]: {
primaryField: 'title',
layout: {
primaryField: 'title',
styles: {
'featured-image': {
width: '1%',
},
title: {
maxWidth: 300,
},
},
},
},
[ LAYOUT_GRID ]: {
mediaField: 'featured-image',
primaryField: 'title',
layout: {
mediaField: 'featured-image',
primaryField: 'title',
},
},
[ LAYOUT_LIST ]: {
primaryField: 'title',
mediaField: 'featured-image',
layout: {
primaryField: 'title',
mediaField: 'featured-image',
},
},
};

Expand All @@ -51,9 +65,7 @@ const DEFAULT_POST_BASE = {
direction: 'desc',
},
fields: [ 'title', 'author', 'status' ],
layout: {
...DEFAULT_CONFIG_PER_VIEW_TYPE[ LAYOUT_LIST ],
},
layout: defaultLayouts[ LAYOUT_LIST ].layout,
};

export function useDefaultViews( { postType } ) {
Expand Down
Loading