-
Notifications
You must be signed in to change notification settings - Fork 11
fix: hide navigation header if nothing underneath #1035
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8bf3da5
fix: donut chart fixes
itssharmasandeep 5599c6a
Revert "fix: donut chart fixes"
itssharmasandeep 88d3bd4
Merge branch 'main' of github.com:hypertrace/hypertrace-ui
itssharmasandeep cd18474
Merge branch 'main' of github.com:hypertrace/hypertrace-ui
itssharmasandeep 2aa1a9b
Merge branch 'main' of github.com:hypertrace/hypertrace-ui
itssharmasandeep 111e41d
Merge branch 'main' of github.com:hypertrace/hypertrace-ui
itssharmasandeep 58f01ef
fix: header should not be visible if nothing is below this
itssharmasandeep f8726d6
fix: test cases
itssharmasandeep b25a431
Merge remote-tracking branch origin/main into nav-list
itssharmasandeep cb86051
fix: creating new service
itssharmasandeep 103bb99
fix: test case
itssharmasandeep b643c90
fix: lint errors
itssharmasandeep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
projects/components/src/navigation/navigation-list-component.service.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { FeatureState, FeatureStateResolver } from '@hypertrace/common'; | ||
import { NavItemConfig, NavItemType } from '@hypertrace/components'; | ||
import { runFakeRxjs } from '@hypertrace/test-utils'; | ||
import { createServiceFactory, mockProvider } from '@ngneat/spectator/jest'; | ||
import { of } from 'rxjs'; | ||
import { NavigationListComponentService } from './navigation-list-component.service'; | ||
import { NavItemHeaderConfig } from './navigation.config'; | ||
|
||
describe('Navigation List Component Service', () => { | ||
const navItems: NavItemConfig[] = [ | ||
{ | ||
type: NavItemType.Header, | ||
label: 'header 1' | ||
}, | ||
{ | ||
type: NavItemType.Link, | ||
icon: 'icon', | ||
label: 'label-1', | ||
features: ['feature'], | ||
matchPaths: [''] | ||
}, | ||
{ | ||
type: NavItemType.Link, | ||
icon: 'icon', | ||
label: 'label-2', | ||
matchPaths: [''] | ||
}, | ||
{ | ||
type: NavItemType.Header, | ||
label: 'header 2' | ||
} | ||
]; | ||
|
||
const createService = createServiceFactory({ | ||
service: NavigationListComponentService, | ||
providers: [ | ||
mockProvider(FeatureStateResolver, { | ||
getCombinedFeatureState: jest.fn().mockReturnValue(of(FeatureState.Enabled)) | ||
}) | ||
] | ||
}); | ||
|
||
test('should return correct visibility for both headers', () => { | ||
const spectator = createService(); | ||
const resolvedItems = spectator.service.resolveFeaturesAndUpdateVisibilityForNavItems(navItems); | ||
|
||
runFakeRxjs(({ expectObservable }) => { | ||
expectObservable((resolvedItems[0] as NavItemHeaderConfig).isVisible$!).toBe('(x|)', { | ||
x: true | ||
}); | ||
expectObservable((resolvedItems[3] as NavItemHeaderConfig).isVisible$!).toBe('(x|)', { | ||
x: false | ||
}); | ||
}); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
projects/components/src/navigation/navigation-list-component.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { FeatureState, FeatureStateResolver } from '@hypertrace/common'; | ||
import { isEmpty } from 'lodash-es'; | ||
import { combineLatest, Observable, of } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { NavItemConfig, NavItemHeaderConfig, NavItemLinkConfig, NavItemType } from './navigation.config'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class NavigationListComponentService { | ||
public constructor(private readonly featureStateResolver: FeatureStateResolver) {} | ||
|
||
public resolveFeaturesAndUpdateVisibilityForNavItems(navItems: NavItemConfig[]): NavItemConfig[] { | ||
const updatedItems = this.updateLinkNavItemsVisibility(navItems); | ||
let linkItemsForThisSection: NavItemLinkConfig[] = []; | ||
for (let i = updatedItems.length - 1; i >= 0; i--) { | ||
if (updatedItems[i].type === NavItemType.Header) { | ||
(updatedItems[i] as NavItemHeaderConfig).isVisible$ = this.updateHeaderNavItemsVisibility( | ||
linkItemsForThisSection | ||
); | ||
linkItemsForThisSection = []; | ||
} else if (updatedItems[i].type === NavItemType.Link) { | ||
linkItemsForThisSection.push(updatedItems[i] as NavItemLinkConfig); | ||
} | ||
} | ||
|
||
return updatedItems; | ||
} | ||
|
||
private updateHeaderNavItemsVisibility(navItems: NavItemLinkConfig[]): Observable<boolean> { | ||
return isEmpty(navItems) | ||
? of(false) | ||
: combineLatest(navItems.map(navItem => navItem.featureState$!)).pipe( | ||
map(states => states.some(state => state !== FeatureState.Disabled)) | ||
); | ||
} | ||
|
||
private updateLinkNavItemsVisibility(navItems: NavItemConfig[]): NavItemConfig[] { | ||
return navItems.map(navItem => { | ||
if (navItem.type === NavItemType.Link) { | ||
return { | ||
...navItem, | ||
featureState$: this.featureStateResolver.getCombinedFeatureState(navItem.features ?? []) | ||
}; | ||
} | ||
|
||
return navItem; | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Color, FeatureState } from '@hypertrace/common'; | ||
import { Observable } from 'rxjs'; | ||
import { IconSize } from '../icon/icon-size'; | ||
|
||
export type NavItemConfig = NavItemLinkConfig | NavItemHeaderConfig | NavItemDividerConfig; | ||
|
||
export interface NavItemLinkConfig { | ||
type: NavItemType.Link; | ||
icon: string; | ||
iconSize?: IconSize; | ||
label: string; | ||
matchPaths: string[]; // For now, default path is index 0 | ||
features?: string[]; | ||
replaceCurrentHistory?: boolean; | ||
isBeta?: boolean; | ||
trailingIcon?: string; | ||
trailingIconTooltip?: string; | ||
trailingIconColor?: Color; | ||
featureState$?: Observable<FeatureState>; | ||
} | ||
|
||
export type FooterItemConfig = FooterItemLinkConfig; | ||
|
||
export interface FooterItemLinkConfig { | ||
url: string; | ||
label: string; | ||
icon: string; | ||
} | ||
|
||
export interface NavItemHeaderConfig { | ||
type: NavItemType.Header; | ||
label: string; | ||
isBeta?: boolean; | ||
isVisible$?: Observable<boolean>; | ||
} | ||
|
||
export interface NavItemDividerConfig { | ||
type: NavItemType.Divider; | ||
} | ||
|
||
// Must be exported to be used by AOT compiler in template | ||
export const enum NavItemType { | ||
Header = 'header', | ||
Link = 'link', | ||
Divider = 'divider', | ||
Footer = 'footer' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ooh.. @itssharmasandeep I think we still need to apply
htFeature
hereThere 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.
Nope
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.
htFeature
takes thefeatures
which arestring[]
and convert this tofeatureState
I am converting this to
featureState
in the service itself and pass here