-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve pagination documentation #9488
base: main
Are you sure you want to change the base?
Improve pagination documentation #9488
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
5f5fb89
to
389bd46
Compare
As per https://github.com/withastro/astro/blob/8d4eb95086ae79339764d02215f84f4f21b96edc/packages/astro/src/%40types/astro.ts#L2804 `page` is a generic type. As a tradeoff, `TData` name was decided to balance the documentation for TS & non-TS folks alike.
The `paginate` function's type definition was too complex to be easily explained in the documentation. Hence, this commit simplifies things by just describing the expected arguments. This makes the documentation easier to follow while still providing the necessary information.
Some parts of the docs were using `CollectionEntry<collection>` while others were using `TCollectionName`. This commit cleans things up by sticking to `TCollectionName`, making everything consistent and easier to follow.
aadb5dc
to
53fb457
Compare
@@ -459,41 +459,6 @@ const { page } = Astro.props; | |||
{page.url.last ? <a href={page.url.last}>Last</a> : null} | |||
``` | |||
|
|||
|
|||
#### Complete API reference |
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.
While I agree with not having this on the routing page, do you think we lose anything by not putting this e.g. right before all the individual reference items? I mean, yeah it's nice that they are all listed out individually, but many of these do fall into the "self-explanatory" category, so only needing to glance at this to know what all's available seems helpful? Otherwise, it's scrolling through 3 pages on my monitor to see everything.
otherwise, I might be tempted to leave something like this here, even if not claiming to be fully typed, but more to show available properties?
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.
You raise a good point. We lose the convenience of glancing at all of the available properties, & having to navigate through the wall of text in the API Reference section... I agree that most of the properties are self explanatory. I can imagine that the some users may find it inconvenient to scroll all that just to see the available properties.
Considering the repercussions, keeping that block there seems warranted even though it adds to the maintenance costs.... Although, it still irks me. 😓 Surely, we can do better....
In hindsight, I realize that the actual purpose of that code block there was to serve as an At a glance section to showcase all of the supported properties by Page
.
I was going to suggest that we simplify the type to a block which only mentions all of the available properties, but I realize that it would be much more work than simply copy-pasting the updated type from the codebase.
Should I revert back to its original state then?
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 a commit with an example of what I think could be a helpful structure to work from. What do you think?
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.
though, we did lose this text which might go in the block itself for data
array containing the page’s slice of data that you passed to the paginate() function
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 seems we are coming back to #8929 (comment) 😅 So, it's probably better to leave the block here. And, I agree with Sarah, we could replace result
which is not descriptive enough with the sentence quoted!
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 adding the description for data
property in the block would work perfectly fine.
@@ -1116,6 +1116,10 @@ The `getStaticPaths()` function should return an array of objects to determine w | |||
|
|||
It can also be used in static file endpoints for [dynamic routing](/en/guides/endpoints/#params-and-dynamic-routing). | |||
|
|||
:::tip | |||
When using TypeScript, use the [`InferGetStatic*`](/en/guides/typescript/#infer-getstaticpaths-types) type utilities to ensure type-safe access of your `params` and `props`. |
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'm a little late, I was waiting until the PR was no longer a draft to comment.
InferGetStatic
does not exist and I don't think the asterisk is understandable to everyone. It seems to me that GetStaticPaths
is enough to have both Astro.params
and Astrop.props
inferred properly. The two other helpers (InferGetStaticParamsType
and InferGetStaticPropsType
) can be useful in some cases but I don't think they are required here.
So I would suggest:
When using TypeScript, use the [`InferGetStatic*`](/en/guides/typescript/#infer-getstaticpaths-types) type utilities to ensure type-safe access of your `params` and `props`. | |
When using TypeScript, use the [`GetStaticPaths`](/en/guides/typescript/#infer-getstaticpaths-types) type utility to ensure type-safe access of your `params` and `props`. |
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 suggestion! How about the following phrasing:
When using TypeScript, follow the [Infer `getStaticPaths` types](/en/guides/typescript/#infer-getstaticpaths-types) guide to ensure type-safe access of your `params` and `props`.
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.
Why not, all types are useful. If I insisted on GetStaticPaths
it is perhaps because I find that this section of the Typescript guide seems to insist on the other two types (InferGetStaticParamsType
and InferGetStaticPropsType
) when only one (GetStaticPaths
) is enough for most cases. But that might just be my perception...
So I'm fine with your suggestion, if you think it's more helpful!
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.
After looking into it, it appears that GetStaticPaths
is sufficient for type safety. However, this raises the question of why there are additional type utilities included. Additionally, that section does not highlight the line where we add satisfies GetStaticPaths
; it only mentions the InferGetStatic*
types. It seems like there’s a new area for improvement here? Though I believe it falls outside the scope of this PR.
Considering this, I will go with your suggestion. It seems satisfactory.
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.
Um yes I think there is a missing line among those highlighted. Maybe it was forgotten because the opening parenthesis is also important in this case. As for the usefulness of the other types... I don't know. I've never used them, but no doubt some people need them. Better excess types than missing types! 😄
But you're right, it doesn't fit into this PR.
Just updated branch to re-trigger the Netlify deploy. We had some random wonkiness yesterday. |
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.
Some nitpicks about the wording. But I'm not the best person to judge so I'm not blocking the PR for that, LGTM!
@@ -494,6 +469,25 @@ interface Page<T = any> { | |||
} | |||
``` | |||
|
|||
The following example template displays current information for the page along with links to navigate between pages: |
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'm not sure template
is needed here... I feel like it makes the sentence heavier... (I don't know if it makes sense in English) but I'm not the best person to discuss the wording.
The following example template displays current information for the page along with links to navigate between pages: | |
The following example displays current information for the page along with links to navigate between pages: |
@@ -1217,28 +1221,35 @@ export async function getStaticPaths({ paginate }) { | |||
const { page } = Astro.props; | |||
``` | |||
|
|||
`paginate()` has the following arguments: | |||
- `data` - Array of data to paginate | |||
- `options` - Optional object with following properties: |
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.
- `options` - Optional object with following properties: | |
- `options` - Optional object with the following properties: |
Description (required)
Following the discussion at #9442; This PR does the following:
Page
prop.page
is a generic type. As a tradeoff,TData
TData
is of typeany
?Type
? Or in description? Should we mention it at all?TData
is generic enough...name was decided to balance the documentation for TS & non-TS folks alike.
page.data
propertygetStaticPaths
functionpaginate
function's type definition was too complex to be easily explained in the documentation. Therefore, I thought of describing the function signature in the docs instead.Page
type reference from theRouting
guideCollectionEntry<collection>
has been replaced withCollectionEntry<TCollectionName>
as specified by its documentation.Anyways. That's all. Feel free to provide any inputs!
Special thanks to @ArmandPhilippot for his detailed responses. It cleared a lot of confusion.
Related issues & labels (optional)
improve-documentation