-
-
Notifications
You must be signed in to change notification settings - Fork 2k
docs(www): add version picker to side menu #5040
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
✅ Deploy Preview for ngrx-site-v19 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
timdeschryver
left a comment
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 @DuskoPeric !
| ], | ||
| }) | ||
| export class VersionNavigationComponent { | ||
| private versionInfoService = inject(VersionInfoService); | ||
| private elementRef = inject(ElementRef); | ||
|
|
||
| public versions = toSignal(this.versionInfoService.getVersions(), { | ||
| initialValue: [] as NavigationNode[], | ||
| }); | ||
|
|
||
| public currentVersion = this.versionInfoService.getCurrentVersion(); | ||
| public isVisible = signal(false); | ||
|
|
||
| @HostListener('document:click', ['$event']) | ||
| onDocumentClick(event: Event): void { | ||
| if (!this.elementRef.nativeElement.contains(event.target as Node)) { | ||
| this.isVisible.set(false); | ||
| } | ||
| } | ||
|
|
||
| public toggleVisibility(): void { | ||
| this.isVisible.update((visible) => !visible); | ||
| } | ||
| } |
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.
- From Angular docs:
Prefer using the host property over the decorators.
Always prefer using the host property over @HostBinding and @HostListener. These decorators exist exclusively for backwards compatibility.
-
Class members are public by default. No need to use
publicmodifier explicitly. For private fields, we can use the#prefix instead of theprivatemodifier just to make it shorter. -
Since we're loading version info eagerly, there is no need for signals (or observables that require conversion to signals).
| ], | |
| }) | |
| export class VersionNavigationComponent { | |
| private versionInfoService = inject(VersionInfoService); | |
| private elementRef = inject(ElementRef); | |
| public versions = toSignal(this.versionInfoService.getVersions(), { | |
| initialValue: [] as NavigationNode[], | |
| }); | |
| public currentVersion = this.versionInfoService.getCurrentVersion(); | |
| public isVisible = signal(false); | |
| @HostListener('document:click', ['$event']) | |
| onDocumentClick(event: Event): void { | |
| if (!this.elementRef.nativeElement.contains(event.target as Node)) { | |
| this.isVisible.set(false); | |
| } | |
| } | |
| public toggleVisibility(): void { | |
| this.isVisible.update((visible) => !visible); | |
| } | |
| } | |
| ], | |
| host: { | |
| '(document:click)': 'closeDropdownOnOutsideClick($event)', | |
| }, | |
| }) | |
| export class VersionNavigationComponent { | |
| readonly #versionInfoService = inject(VersionInfoService); | |
| readonly #elementRef = inject(ElementRef); | |
| readonly isDropdownVisible = signal(false); | |
| readonly currentVersion = this.#versionInfoService.currentVersion; | |
| readonly previousVersions = this.#versionInfoService.previousVersions; | |
| closeDropdownOnOutsideClick(event: Event): void { | |
| if (!this.#elementRef.nativeElement.contains(event.target as Node)) { | |
| this.isDropdownVisible.set(false); | |
| } | |
| } | |
| toggleDropdown(): void { | |
| this.isDropdownVisible.update((visible) => !visible); | |
| } | |
| } |
Suggested VersionInfoService implementation is in the next comment.
| import { Injectable } from '@angular/core'; | ||
| import { of } from 'rxjs'; | ||
| import versionInfoData from '../data/versionInfo.json'; | ||
|
|
||
| export interface NavigationNode { | ||
| url: string; | ||
| title: string; | ||
| } | ||
|
|
||
| export interface VersionInfo { | ||
| currentVersion: string; | ||
| docVersions: NavigationNode[]; | ||
| } | ||
|
|
||
| @Injectable({ providedIn: 'root' }) | ||
| export class VersionInfoService { | ||
| private readonly versionInfo = versionInfoData as VersionInfo; | ||
|
|
||
| getVersions() { | ||
| return of(this.versionInfo.docVersions); | ||
| } | ||
|
|
||
| getCurrentVersion(): string { | ||
| return this.versionInfo.currentVersion; | ||
| } | ||
| } |
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 can even take data from versionInfo.json directly in the VersionNavigationComponent. If you want to keep it in a service, here is the suggested implementation:
| import { Injectable } from '@angular/core'; | |
| import { of } from 'rxjs'; | |
| import versionInfoData from '../data/versionInfo.json'; | |
| export interface NavigationNode { | |
| url: string; | |
| title: string; | |
| } | |
| export interface VersionInfo { | |
| currentVersion: string; | |
| docVersions: NavigationNode[]; | |
| } | |
| @Injectable({ providedIn: 'root' }) | |
| export class VersionInfoService { | |
| private readonly versionInfo = versionInfoData as VersionInfo; | |
| getVersions() { | |
| return of(this.versionInfo.docVersions); | |
| } | |
| getCurrentVersion(): string { | |
| return this.versionInfo.currentVersion; | |
| } | |
| } | |
| import { Injectable } from '@angular/core'; | |
| import versionInfoData from '../data/versionInfo.json'; | |
| interface PreviousVersion { | |
| url: string; | |
| title: string; | |
| } | |
| interface VersionInfo { | |
| currentVersion: string; | |
| previousVersions: PreviousVersion[]; | |
| } | |
| @Injectable({ providedIn: 'root' }) | |
| export class VersionInfoService { | |
| readonly #versionInfo = versionInfoData as VersionInfo; | |
| readonly currentVersion = this.#versionInfo.currentVersion; | |
| readonly previousVersions = this.#versionInfo.previousVersions; | |
| } |
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?
The new website doesn't have version picker.
Closes #4975
What is the new behavior?
The new website has version picker.
Does this PR introduce a breaking change?