Skip to content
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

Merged
merged 10 commits into from
Oct 10, 2023

Conversation

ruanyl
Copy link
Owner

@ruanyl ruanyl commented Sep 28, 2023

Description

Issues Resolved

Screenshot

Testing the changes

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

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-commenter
Copy link

codecov-commenter commented Sep 28, 2023

Codecov Report

Merging #207 (21f8e03) into workspace (29ccc20) will increase coverage by 30.37%.
Report is 5 commits behind head on workspace.
The diff coverage is 58.33%.

@@              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     
Flag Coverage Δ
Linux_1 30.42% <8.33%> (+<0.01%) ⬆️
Linux_2 55.63% <58.33%> (?)
Linux_3 42.76% <8.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/core/public/chrome/chrome_service.mock.ts 100.00% <100.00%> (+18.75%) ⬆️
src/core/public/chrome/ui/header/header.tsx 75.00% <ø> (+75.00%) ⬆️
src/core/public/core_system.ts 92.04% <100.00%> (+92.04%) ⬆️
src/core/public/plugins/plugin_context.ts 44.44% <ø> (+44.44%) ⬆️
...c/core/public/workspace/workspaces_service.mock.ts 100.00% <ø> (ø)
src/core/public/workspace/workspaces_service.ts 90.00% <100.00%> (+90.00%) ⬆️
...c/core/public/chrome/ui/header/collapsible_nav.tsx 96.36% <50.00%> (+96.36%) ⬆️
src/core/public/chrome/chrome_service.tsx 86.66% <20.00%> (+85.23%) ⬆️

... 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
Copy link
Collaborator

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?

Copy link
Owner Author

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 />}
Copy link
Collaborator

@yuye-aws yuye-aws Oct 10, 2023

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

Copy link
Owner Author

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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?

Copy link
Collaborator

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;

Copy link
Owner Author

@ruanyl ruanyl Oct 10, 2023

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.

Copy link
Owner Author

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;
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Copy link
Collaborator

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;
Copy link
Collaborator

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

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@@ -5789,7 +5785,6 @@ exports[`dashboard listing renders warning when listingLimit is exceeded 1`] = `
"observers": Array [],
"thrownError": null,
},
"renderWorkspaceMenu": [MockFunction],
"workspaceEnabled$": BehaviorSubject {
Copy link
Collaborator

@yuye-aws yuye-aws Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need update?

Copy link
Owner Author

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 {
Copy link
Collaborator

@yuye-aws yuye-aws Oct 10, 2023

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;
},
};
Copy link
Collaborator

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?

Copy link
Owner Author

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.

@ruanyl ruanyl merged commit b935e36 into workspace Oct 10, 2023
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants