-
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: list all pages, not only those with publish and draft statuses #55476
Conversation
Size Change: +7 B (0%) Total Size: 1.66 MB
ℹ️ View Unchanged
|
54790cd
to
3ada739
Compare
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.
Thanks for the PR! I've left some small comments, and I'm wondering if we'll need to take into account some other flags from statuses like show_in_list
. I don't believe it's for now though.
}; | ||
}, [ statuses ] ); | ||
|
||
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.
I feel like this is a bit overkill, at least for now. Do you feel strongly about adding it now?
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.
We do need to update the view upon receiving the statuses, otherwise it'd have stale data. For example: what if a site has a different set of statuses from the ones we hard-coded at DEFAULT_STATUSES
?
The only thing we could remove is the DEFAULT_STATUSES
to defaultStatuses
check. I think it is still worth maintaining: it's just a single line of code, and it prevents an unnecessary double request.
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 only thing we could remove is the DEFAULT_STATUSES to defaultStatuses
That was what I was referring to, sorry for not clarifying. I mean it's useful to avoid the request, but the block with the comments it's big 😅 . Let's simplify this part then just a bit.
How about assign DEFAULT_STATUSES
with the sorted values(so no need to split->sort->join), and also sort defaultStatuses
in the useMemo
. So the comparison here is just for two strings.
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.
Done this at 78c0609
Note that I had to add another comment:
// DEFAULT_STATUSES is intentionally sorted. Items do not have spaces in between them.
// The reason for that is to match defaultStatuses because we compare both strings below (see useEffect).
const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All statuses but 'trash'.
With the previous approach, I wanted to cover against future humans (including myself) modifying ever slightly that constant, with the consequence of breaking the comparison. Perhaps I should be more optimistic about humans :)
postStatuses: | ||
statuses === null | ||
? EMPTY_OBJECT | ||
: Object.fromEntries( |
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.
statuses
were handled initially like an object
because with REST API, it was one. Now that it's an entity and we have an array, do we still need to all that? The difference would only be in getValue
for status to Array.find
.
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 have a strong opinion on doing it either way. Do you think we should update it in this PR?
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 it's simplifies the code, but no strong opinions here.
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.
Done at 1ca610c Thanks for the nudge, it does indeed simplify the code.
Flaky tests detected in 3ada739679222709050ad3cd44cd1cbbe8f03794. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6571583872
|
Feel free to address the small comments I left, or land with 🟢 CI. |
3ada739
to
1ca610c
Compare
}, | ||
} ); | ||
} | ||
}, [ defaultStatuses ] ); |
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.
There's a few things here.
- I don't think we should update the "view" programmatically. It will create an undo level...
- I don't think the initial view should depend on the REST API of the status. Can the filter be "empty" initially or fixed using a value we actually choose. If not, we shouldn't render anything and shouldn't compute the initial "view" object until the statuses are loaded (but I'd prefer to avoid this option if possible)
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 "empty" state for this filter means the endpoint will return only pages with publish
status. The filter is already fixed (DEFAULT_STATUSES
), and this effect will only set the view programmatically when the site has a different set of statuses from the default ones (very rare use case, though it can happen).
Does that alleviate your concerns?
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.
this effect will only set the view programmatically when the site has a different set of statuses from the default ones (very rare use case, though it can happen)
Not sure we should support that for the moment tbh.
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.
So, to confirm, you'd rather prevent the view from rendering until the statuses are loaded?
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.
So, to confirm, you'd rather prevent the view from rendering until the statuses are loaded?
If we really want to support the themes that change the default statuses, yes. But maybe we don't care about this for now.
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 found a way to prevent us from programatically update the view #55839
Part of #55083
Follow-up to #55270 (comment)
What?
Updates the pages page to retrieve all the pages (not only those with publish & draft status). Also lists all statuses in the states filter.
Why?
We want to show all status.
Testing Instructions
Gravacao.do.ecra.2023-10-19.as.09.30.36.mov