-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor workspace context menu register #207
Conversation
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Codecov Report
@@ Coverage Diff @@
## workspace #207 +/- ##
==============================================
+ Coverage 30.42% 60.79% +30.37%
==============================================
Files 2199 2991 +792
Lines 45154 58895 +13741
Branches 7023 9671 +2648
==============================================
+ Hits 13737 35804 +22067
+ Misses 30810 20991 -9819
- Partials 607 2100 +1493
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1608 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@@ -181,6 +196,17 @@ export class ChromeService { | |||
localStorage.setItem(IS_LOCKED_KEY, `${isLocked}`); | |||
}; | |||
|
|||
const collapsibleNavHeaderRender = this.collapsibleNavHeaderRender | |||
? () => | |||
this.collapsibleNavHeaderRender |
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.
Duplicate judgement on this.collapsibleNavHeaderRender
, maybe we only need one?
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.
Good point, updated now
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@@ -197,7 +196,7 @@ export function CollapsibleNav({ | |||
outsideClickCloses={false} | |||
> | |||
<EuiFlexItem className="eui-yScroll"> | |||
<CollapsibleNavHeader workspaces={workspaces} /> | |||
{collapsibleNavHeaderRender ? collapsibleNavHeaderRender() : <CollapsibleNavHeader />} |
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.
By your PR, CollapsibleNavHeader
would simply be a react component, I would suggest moving CollapsibleNavHeader
implementation to collapsible_nav.tsx
and the header file is no longer 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.
Good point, I will update
@@ -33,7 +33,7 @@ import { formatUrlWithWorkspaceId } from '../../utils'; | |||
interface Props { | |||
getUrlForApp: ApplicationStart['getUrlForApp']; | |||
basePath: HttpSetup['basePath']; | |||
observables: WorkspaceObservables; | |||
workspaces: WorkspaceObservables; |
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.
Should it be WorkspacesStart
?
export interface WorkspacesStart extends WorkspaceObservables { | ||
renderWorkspaceMenu: () => JSX.Element | null; | ||
} | ||
export type WorkspacesSetup = WorkspaceObservables; |
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.
Do we still need to export type WorkspaceObservables
?
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.
If WorkspaceObservables
is no longer needed, we can reset the code as the following:
export interface WorkspaceStart {
currentWorkspaceId$: BehaviorSubject<string>;
currentWorkspace$: BehaviorSubject<WorkspaceAttribute | null>;
workspaceList$: BehaviorSubject<WorkspaceAttribute[]>;
workspaceEnabled$: BehaviorSubject<boolean>;
}
export type WorkspaceSetup = WorkspaceStart;
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.
nice catch, this is not needed 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 will keep WorkspaceObservables
for now, should not be an issue, I think it will be needed in the future
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@@ -132,11 +134,11 @@ interface Props { | |||
navigateToUrl: InternalApplicationStart['navigateToUrl']; | |||
customNavLink$: Rx.Observable<ChromeNavLink | undefined>; | |||
logos: Logos; | |||
workspaces: WorkspacesStart; |
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.
Also need to remove this prop defined in collapsible_nav.test.tsx
@@ -407,89 +407,13 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` | |||
"observers": Array [], | |||
"thrownError": null, | |||
}, | |||
"renderWorkspaceMenu": [MockFunction], | |||
"workspaceEnabled$": BehaviorSubject { |
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 snapshot file should be updated along with test file
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.
All four snapshot files should be updated.
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@@ -94,7 +94,6 @@ export interface HeaderProps { | |||
branding: ChromeBranding; | |||
logos: Logos; | |||
survey: string | undefined; | |||
workspaces: WorkspacesStart; |
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.
Need to remove corresponding prop in header.test.tsx
@@ -5789,7 +5785,6 @@ exports[`dashboard listing renders warning when listingLimit is exceeded 1`] = ` | |||
"observers": Array [], | |||
"thrownError": null, | |||
}, | |||
"renderWorkspaceMenu": [MockFunction], | |||
"workspaceEnabled$": BehaviorSubject { |
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.
Need update?
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 PR doesn't include change of workspaceEnabled$
.
@@ -892,7 +892,6 @@ exports[`Dashboard top nav render in embed mode 1`] = ` | |||
"observers": Array [], | |||
"thrownError": null, | |||
}, | |||
"renderWorkspaceMenu": [MockFunction], | |||
"workspaceEnabled$": BehaviorSubject { |
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.
Need update?
registerCollapsibleNavHeader: (render: CollapsibleNavHeaderRender) => { | ||
this.collapsibleNavHeaderRender = render; | ||
}, | ||
}; |
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.
is it ok to set collapsibleNavHeaderRender multiple times to override previous one, or we should add a check here to let it only set it once?
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 mean if different plugins called registerCollapsibleNavHeader
with different render
, previous one will be override?
Actually I have the same concern, but it should be fine as this will only be used by workspace for now. If in the future, this is called by different plugins, we may add the check or register the render to an array, I don't know which is expected, so just leave it like this for now.
Description
Issues Resolved
Screenshot
Testing the changes
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr