-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: add initial "Side by side" prototype #55343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default as DataViews } from './dataviews'; | ||
export { default as DataViews, viewTypeSupportsMap } from './dataviews'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ViewList from './view-list'; | ||
|
||
export function ViewSideBySide( props ) { | ||
// To do: change to email-like preview list. | ||
return <ViewList { ...props } />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; | |
*/ | ||
import Page from '../page'; | ||
import Link from '../routes/link'; | ||
import { DataViews } from '../dataviews'; | ||
import { DataViews, viewTypeSupportsMap } from '../dataviews'; | ||
import { default as DEFAULT_VIEWS } from './default-views'; | ||
import { | ||
useTrashPostAction, | ||
|
@@ -27,6 +27,7 @@ import { | |
viewPostAction, | ||
useEditPostAction, | ||
} from '../actions'; | ||
import SideEditor from './side-editor'; | ||
import Media from '../media'; | ||
import { unlock } from '../../lock-unlock'; | ||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
@@ -44,6 +45,8 @@ const defaultConfigPerViewType = { | |
export const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All statuses but 'trash'. | ||
|
||
export default function PagePages() { | ||
const postType = 'page'; | ||
const [ selection, setSelection ] = useState( [] ); | ||
const { | ||
params: { path, activeView = 'all' }, | ||
} = useLocation(); | ||
|
@@ -99,7 +102,7 @@ export default function PagePages() { | |
isResolving: isLoadingPages, | ||
totalItems, | ||
totalPages, | ||
} = useEntityRecords( 'postType', 'page', queryArgs ); | ||
} = useEntityRecords( 'postType', postType, queryArgs ); | ||
|
||
const { records: authors, isResolving: isLoadingAuthors } = | ||
useEntityRecords( 'root', 'user' ); | ||
|
@@ -136,7 +139,7 @@ export default function PagePages() { | |
header: __( 'Title' ), | ||
id: 'title', | ||
getValue: ( { item } ) => item.title?.rendered || item.slug, | ||
render: ( { item } ) => { | ||
render: ( { item, view: { type } } ) => { | ||
return ( | ||
<VStack spacing={ 1 }> | ||
<Heading as="h3" level={ 5 }> | ||
|
@@ -146,6 +149,14 @@ export default function PagePages() { | |
postType: item.type, | ||
canvas: 'edit', | ||
} } | ||
onClick={ ( event ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be in the "fields" config IMO and also "fields" config shouldn't depend on local state here, it should only use things passed as props. This of this "render" function as the "edit" function of blocks. It might be defined in a very different file/package... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed 😊 |
||
if ( | ||
viewTypeSupportsMap[ type ].preview | ||
) { | ||
event.preventDefault(); | ||
setSelection( [ item.id ] ); | ||
} | ||
} } | ||
> | ||
{ decodeEntities( | ||
item.title?.rendered || item.slug | ||
|
@@ -250,18 +261,45 @@ export default function PagePages() { | |
|
||
// TODO: we need to handle properly `data={ data || EMPTY_ARRAY }` for when `isLoading`. | ||
return ( | ||
<Page title={ __( 'Pages' ) }> | ||
<DataViews | ||
paginationInfo={ paginationInfo } | ||
fields={ fields } | ||
actions={ actions } | ||
data={ pages || EMPTY_ARRAY } | ||
isLoading={ | ||
isLoadingPages || isLoadingStatus || isLoadingAuthors | ||
} | ||
view={ view } | ||
onChangeView={ onChangeView } | ||
/> | ||
</Page> | ||
<> | ||
<Page title={ __( 'Pages' ) }> | ||
<DataViews | ||
paginationInfo={ paginationInfo } | ||
fields={ fields } | ||
actions={ actions } | ||
data={ pages || EMPTY_ARRAY } | ||
isLoading={ | ||
isLoadingPages || isLoadingStatus || isLoadingAuthors | ||
} | ||
view={ view } | ||
onChangeView={ onChangeView } | ||
/> | ||
</Page> | ||
{ viewTypeSupportsMap[ view.type ].preview && ( | ||
<Page> | ||
<div className="edit-site-page-pages-preview"> | ||
{ selection.length === 1 && ( | ||
<SideEditor | ||
postId={ selection[ 0 ] } | ||
postType={ postType } | ||
/> | ||
) } | ||
{ selection.length !== 1 && ( | ||
<div | ||
style={ { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
textAlign: 'center', | ||
height: '100%', | ||
} } | ||
> | ||
<p>{ __( 'Select a page to preview' ) }</p> | ||
</div> | ||
) } | ||
</div> | ||
</Page> | ||
) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this is part of the view component. Maybe a slot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a slot? Why it's not bundled in the view from the start ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it needs to be rendered into a separate Page component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so for me, it's either too early for this particular view to be implemented or we need to redesign it a bit. In the sense that instead of it being a separate page/frame, I think it should be within the same frame and just separated from the list with a light border: most applications that use this pattern do this (Mac OS notes app is the simplest example). If it needs to breakout of the "Page" component, I think it introduces too much complexity that we don't need at this stage of development for a small outcome. It starts to raise the question of whether it's a "layout" or something else more global. (The layout being just the left sidebar) cc @SaxonF There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree with it being a small outcome There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The space in between is just styling at the end of the day. The bigger reason it's separate is because there should be no "Pages" heading at the top. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand Riad's concern. I too was looking at the whole picture in terms of:
I think the line between what is abstracted by DataViews and what is up for the consumer to handle is a line likely to change as we progress, but for now I also feel we should intentionally restrict our model. Ella, do you feel it's incompatible to have the Editor inside ViewSideBySide? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcsf I don't know how you see that work? This is the view component area? How do you fit in a preview? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than a slot, not sure what solutions you all have in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not sure now. And Slot might be overkill. |
||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Editor from '../editor'; | ||
import { useInitEditedEntity } from '../sync-state-with-url/use-init-edited-entity-from-url'; | ||
|
||
export default function SideEditor( { postType, postId } ) { | ||
useInitEditedEntity( { | ||
postId, | ||
postType, | ||
} ); | ||
|
||
return <Editor />; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should rename this one "table" and the new one "list"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean here. You named it list and grid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes some sense