-
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
Fix: DataViews: Active page is not highlighted properly in list view. #62378
Fix: DataViews: Active page is not highlighted properly in list view. #62378
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +144 B (+0.01%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
Should this be backported? If so, please add the |
const { | ||
params: { postId }, | ||
} = useLocation(); | ||
const [ postIdToSelect, setPostIdToSelect ] = useState(); |
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.
Can we use postId as default value here to avoid initial re-rendering?
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.
Yes, good catch the code was updated 👍
packages/dataviews/src/dataviews.tsx
Outdated
onSelectionChange?: ( items: Item[] ) => void; | ||
} | ||
|
||
const defaultGetItemId = ( item: AnyItem ) => item.id; | ||
const defaultGetItemId = ( item: AnyItem ) => item.id + ''; |
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.
Is this needed?
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.
Yes it is needed, it is making sure the ID returned is a string, in some cases, it was an integer that made the comparisons fail. The selections have a type of string[] and previously many times it was an integer array.
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.
our types, say it's always a string. So if we were actually using typescript in the consuming side we'd see the error. So maybe instead of changing the default getting we could provide ( item: AnyItem ) => item.id.toString()
as a prop for the case where the id is integer no?
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.
Hi @youknowriad I applied your suggestion.
Flaky tests detected in 1d9d2d1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9418340439
|
@@ -266,6 +278,20 @@ export default function PagePages() { | |||
totalPages, | |||
} = useEntityRecords( 'postType', postType, queryArgs ); | |||
|
|||
useEffect( () => { |
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.
Isn't this a duplicate of the effect above? Also the code feels a bit fragile to me to be honest. Do we expect all dataviews to have this same logic. It's not really straightforward. Is there a way to improve this?
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.
It is not the same effect as above. Above, when the page gets a postId in the URL parameter, we set that ID as something to be part of the selection. We cannot select it immediately because the items may still be loading.
In this effect, if things are loaded and an item should be selected, we update the selection.
It looks fragile but seems to work well. Previously, I tried other ideas, but they ended up not working all the time or being even more complex. I am not sure how we can simplify this further. What I can do is put the effects and the state inside a hook that we can reuse in other places if needed (and that way, at least the logic is joined in a specific place).
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 made this change to extract the logic in a specific hook.
1d9d2d1
to
a28b020
Compare
I did a quick test and I am seeing the same issue for the templates (missing indicator of the active template when the list layout is used), and this is not solved by this PR. Is there a separate issue for that? |
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.
The templates screen also uses the list view and faces the same issue — it'd be nice to have a follow-up for that as well.
Thank you for the reviews @carolinan and @oandregal. I will follow up with something similar for the templates.
We are showing aria-pressed="true" do you think we should include other additional aria information? If so I'm happy to iterate on this. |
The element that includes the information about the page in the list layout is not a button and does not have |
…#62378) Co-authored-by: jorgefilipecosta <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: carolinan <[email protected]>
I just cherry-picked this PR to the wp/6.6-rc-1 branch to get it included in the next release: e3097e2 |
…#62378) Co-authored-by: jorgefilipecosta <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: carolinan <[email protected]>
Fixes: #60708.
This PR adds a "controlled" mode for the selection in the DataViews component (passing the selection as a prop) as suggested by @youknowriad.
Adds logic to make the current link in the URL the selection. For this to work we needed some logic to avoid race conditions e.g.: we should only include the selection if the items are loaded otherwise dataviews code automatically removes the selection.
We also had some cases where the selection id were integers instead of strings and we missed a usage getItemId.
Testing Instructions
Go to http://localhost:7888/site-wp-dev/wp-admin/site-editor.php?postType=page&postId=1246 (1246 needs to be a valid page id)
Verify the active page is highlighted properly.