-
Notifications
You must be signed in to change notification settings - Fork 26.3k
docs(docs-infra): Add query as an url query param to the api reference #57062
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
Conversation
|
@JeanMeche As discussed on Discord. I did not yet add the functionality to also add the |
f630316 to
8cc0992
Compare
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
422c380 to
a47abd7
Compare
a47abd7 to
a01292b
Compare
|
Deployed adev-preview for a36ffb925a4cefe8e98290c88cf0ec0e0ac6e596 to: https://ng-dev-previews-fw--pr-angular-angular-57062-adev-prev-l6eqpwhp.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
a01292b to
07b9e79
Compare
|
@JeanMeche You mentioned the developer preview and experimental references yesterday. The current UI (input and toggle for While re-thinking the UI is a bit out of scope for this PR, I do wonder if we shouldn't already include a Just thinking out loud here, curious how you feel about this. Edit: I just had a look and it might be a bit more involved (existing interfaces, tests need to be updated) to get the |
|
Changed the PR to draft as I want to extract the angular/adev/src/app/features/update/update.component.ts Lines 186 to 190 in fab673a
|
Do that in another follow-up refactoring PR if this is approved. Adding more to your current PR will make it more difficult to review and be approved. Using the |
|
Do you have examples of web pages with search that update the query as you're typing in the search input? I'm not convinced that this is a common or good user experience. |
It was the default behavior in the AIO API reference: https://v17.angular.io/api |
Right, but that's not on its own a reason to do the same for the new docs site. Only if we decide it's a valuable feature that provides good UX. What are the scenarios in which you would want to share a link to a filtered API page with the query as opposed to the API you were looking for? |
Would it be better if the param was only updated once the user was done typing? I would have to convert the signal to an observable and add a debounce maybe? My use case involves the Angular Community Discord bot. It allows to search API references but it has a limit on how many results it can display. So when there are more than 10 results I want to direct users to https://angular.dev/api?query= |
|
@atscott This is actually not the first time this feature was discussed. You mentioned here that the url should be replaced: #52979 (comment) and in that PR there's no mention that this feature was not desirable (The actual feature was later removed from that PR due to issues getting it merged and is what lead me to create this PR) |
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
Sure, but that doesn't at all mean I can't ask the question here. |
07b9e79 to
a0e4077
Compare
Didn't mean to imply that you couldn't/shouldn't ask. Just wanted to provide additional information. |
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
a0e4077 to
fe31e82
Compare
adev/src/app/features/references/api-reference-list/api-reference-list.component.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.spec.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.spec.ts
Outdated
Show resolved
Hide resolved
adev/src/app/features/references/api-reference-list/api-reference-list.component.spec.ts
Outdated
Show resolved
Hide resolved
|
Apologies for the mess with the rebase. I'm not sure what went wrong. Thank you @JeanMeche for helping out. |
| @@ -108,12 +116,23 @@ export class AppComponent implements OnInit { | |||
| private focusFirstHeadingOnRouteChange(): void { | |||
| this.router.events | |||
| .pipe( | |||
| filter((e): e is NavigationEnd => e instanceof NavigationEnd), | |||
| filter((e): e is RoutesRecognized => e instanceof RoutesRecognized), | |||
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 isn't quite right. Guards and resolvers will delay the navigation and the focus will happen before the new route is rendered. On option might be a switchMap to a NavigationEnd after filtering on the condition that's in the subscription
e06a086 to
a36ffb9
Compare
adev/src/app/app.component.ts
Outdated
| return this.router.events.pipe( | ||
| filter((e): e is NavigationEnd => e instanceof NavigationEnd), | ||
| // Skip first emission, cause on the initial load we would like to `Skip to main content` popup when it's focused | ||
| skip(1), |
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 skip(1) doesn't belong here actually. It should probably be changed to a skipUntil(router.events.filter(e => e instanceof NavigationEnd)) at the top of this pipe.
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 struggling to get it to work with skipUntil. Once I add it, the filter that checks same route navigation no longer works. Did I add it in the wrong place, or am I missing something else?
private focusFirstHeadingOnRouteChange(): void {
this.router.events
.pipe(
filter((e): e is RoutesRecognized => e instanceof RoutesRecognized),
filter((e) => {
// do not set focus when only fragments or queryParams change
const tree = createUrlTreeFromSnapshot(e.state.root, []);
return this.router.isActive(tree, {
paths: 'exact',
matrixParams: 'exact',
fragment: 'ignored',
queryParams: 'ignored',
});
}),
switchMap(() => {
return this.router.events.pipe(
skipUntil(
this.router.events.pipe(
filter((e): e is NavigationEnd => e instanceof NavigationEnd),
),
),
);
}),
)
.subscribe(() => {
this.focusFirstHeading();
});
}Also I saw 19a1296. I assume that is a temporary solution and this is still 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.
Did I add it in the wrong place
Yes, it needs to go at the very top, before RoutesRecognized,
I assume that is a temporary solution and this is still needed?
Yes, it's temporary
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.
Apologies, i've been distracted with some other things. I've placed the skipUntil on top and it's working as expected now. Is there anything else that needs to be done to land this fix?
cc. @JeanMeche
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've placed the skipUntil on top and it's working as expected now. Is there anything else that needs to be done to land this fix?
Yes, the filter was changed to look for RoutesRecognized but needs to be reverted back to NavigationEnd.
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.
Or rather, what the comment in the review says: after filtering, it needs to wait for NavigationEnd still so switchMapping to NavigationEnd should work.
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.
When I add a switchMap, this.focusFirstHeading(); is always called. If the filter returns false (same route navigation) it correctly ignores the switchMap, but there's still an emission that triggers the method call in the subscribe. This does not happen when I remove the switchMap and I'm not sure what I'm doing wrong.
this.router.events
.pipe(
skipUntil(
this.router.events.pipe(filter((e): e is NavigationEnd => e instanceof NavigationEnd)),
),
filter((e): e is RoutesRecognized => e instanceof RoutesRecognized),
filter((e) => {
// do not set focus when only fragments or queryParams change
const tree = createUrlTreeFromSnapshot(e.state.root, []);
return !this.router.isActive(tree, {
paths: 'exact',
matrixParams: 'exact',
fragment: 'ignored',
queryParams: 'ignored',
});
}),
switchMap(() => {
return this.router.events.pipe(
filter((e): e is NavigationEnd => e instanceof NavigationEnd),
);
}),
)
.subscribe(() => {
this.focusFirstHeading();
});As an alternative you mentioned that RoutesRecognized should be reverted back to NavigationEnd, but I was only able to get the filter to work correctly with the ActivatedRouteSnapshot available on RoutesRecognized.state.root. Is there another snapshot besides ActivatedRoute that I could use?
e.g. This will never call the this.focusFirstHeading() method, even when there is a route change:
this.router.events
.pipe(
skipUntil(
this.router.events.pipe(filter((e): e is NavigationEnd => e instanceof NavigationEnd)),
),
filter((e): e is NavigationEnd => e instanceof NavigationEnd),
filter(() => {
// do not set focus when only fragments or queryParams change
const tree = createUrlTreeFromSnapshot(this.activatedRoute.snapshot, []);
return !this.router.isActive(tree, {
paths: 'exact',
matrixParams: 'exact',
fragment: 'ignored',
queryParams: 'ignored',
});
}),
)
.subscribe(() => {
this.focusFirstHeading();
});…arams changes setting heading focus when query params change, causes the api overview input to lose focus on every character entered. while staying on the same route, re-setting focus does not make sense
a36ffb9 to
6c6f780
Compare
|
This is already implemented. |

add an url query param to to perform a search on api references directly via the url
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently it's not possible to add a queryParam to https://angular.dev/api to link directly to a specific result set. This is possible on AIO.
Issue Number: N/A
What is the new behavior?
This brings the behavior inline with the old AIO API reference search. It's possible to directly link to a result set (e.g. https://angular.dev/api?query=inject). When searching via the input on the overview page, the search value will also be added to the queryParam.
Does this PR introduce a breaking change?
Other information