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: in left menu, move recently viewed from top to middle #87

Merged
merged 6 commits into from
Aug 21, 2023
Merged

refactor: in left menu, move recently viewed from top to middle #87

merged 6 commits into from
Aug 21, 2023

Conversation

yuye-aws
Copy link
Collaborator

@yuye-aws yuye-aws commented Aug 16, 2023

Description

The category name has changed from "recently viewed" to "recently visited". We need to confirm with UX team whether to render this category when there is no recently accessed items.

Issues Resolved

Screenshot

image

image

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

@yuye-aws yuye-aws changed the title refactor: in left menu, move recently viewed from top to a category between home and library refactor: in left menu, move recently viewed from top to middle Aug 16, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 16, 2023

Codecov Report

Merging #87 (3261510) into workspace (b49aa1f) will increase coverage by 0.00%.
Report is 3 commits behind head on workspace.
The diff coverage is 90.00%.

❗ Current head 3261510 differs from pull request most recent head 40421c9. Consider uploading reports for the commit 40421c9 to get more accurate results

@@            Coverage Diff             @@
##           workspace      #87   +/-   ##
==========================================
  Coverage      65.78%   65.78%           
==========================================
  Files           3334     3334           
  Lines          64441    64439    -2     
  Branches       10258    10256    -2     
==========================================
+ Hits           42390    42392    +2     
+ Misses         19482    19477    -5     
- Partials        2569     2570    +1     
Flag Coverage Δ
Linux_1 34.71% <20.00%> (+<0.01%) ⬆️
Linux_3 42.66% <20.00%> (+<0.01%) ⬆️
Windows_1 34.72% <20.00%> (+<0.01%) ⬆️
Windows_2 54.69% <90.00%> (+0.02%) ⬆️
Windows_3 42.67% <20.00%> (+<0.01%) ⬆️
Windows_4 34.76% <20.00%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
src/core/public/chrome/nav_links/nav_link.ts 66.66% <ø> (ø)
src/core/public/chrome/ui/header/nav_link.tsx 60.86% <66.66%> (+10.86%) ⬆️
...c/core/public/chrome/ui/header/collapsible_nav.tsx 93.75% <100.00%> (+5.87%) ⬆️

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

className="osdCollapsibleNav__recentsListGroup"
/>
) : (
<EuiText size="s" color="subdued" style={{ padding: '0 8px 8px' }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will we still show No recently viewed items after this refactor?

Copy link
Collaborator Author

@yuye-aws yuye-aws Aug 17, 2023

Choose a reason for hiding this comment

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

No. This edge case for recently visited and favorites needs to be confirmed with UX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just get to know that No recently viewed items need to show. I will add it later.

@@ -134,16 +131,10 @@ export function createRecentNavLink(

return {
href,
label,
baseUrl: href,
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 a correct baseUrl value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think baseUrl can be considered as a placeholder rather than a real value. The reason is that Recent ChromeNavLink is only consumed by function createEuiListItem, where baseUrl is not used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK. Can we add some annotations about that? It may be confused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

Copy link
Owner

@ruanyl ruanyl Aug 18, 2023

Choose a reason for hiding this comment

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

baseUrl is supposed to be the base route used to open the root of an application, in this case, we are trying to generate ChromeNavLink from recently accessed url and ofc we don't know what's the root of an application.

Instead of simply making an conclusion:

Recent ChromeNavLink is only consumed by function createEuiListItem, where baseUrl is not used.

Here is what I'd suggest:

// src/core/public/chrome/ui/header/nav_link.tsx
export type RecentNavLink = Omit<ChromeNavLink, 'baseUrl'>;

export function createRecentChromeNavLink(/*....*/): RecentNavLink {
  //...
}

// src/core/public/chrome/ui/header/collapsible_nav.tsx
const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden);
const allNavLinks: Array<ChromeNavLink | RecentNavLink> = [...navLinks];
const recentlyAccessed = useObservable(observables.recentlyAccessed$, []);
if (recentlyAccessed.length) {
  allNavLinks.push(
    ...recentlyAccessed.map((link) => createRecentChromeNavLink(link, navLinks, basePath))
  );
} else {
  allNavLinks.push(emptyRecentlyVisited);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we need another type for const emptyRecentlyVisited?

Copy link
Owner

@ruanyl ruanyl Aug 18, 2023

Choose a reason for hiding this comment

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

I think you can use RecentNavLink I suggested.

Copy link
Collaborator Author

@yuye-aws yuye-aws Aug 18, 2023

Choose a reason for hiding this comment

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

Since baseUrl prop in navLinks is also not consumed, how about declaring the type as CollapsibleNavLink and then convert navLinks into this type?

// src/core/public/chrome/ui/header/nav_link.tsx
export type CollapsibleNavLink = Omit<ChromeNavLink, 'baseUrl'>;

// src/core/public/chrome/ui/header/collapsible_nav.tsx
const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden)
    .map(({ baseUrl, ...collapsibleNavLinkProps }) => collapsibleNavLinkProps);

Copy link
Owner

Choose a reason for hiding this comment

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

Not necessary, I would suggest you keep the existing code as it is if you can.

Copy link
Collaborator Author

@yuye-aws yuye-aws Aug 21, 2023

Choose a reason for hiding this comment

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

Ok, I define a new type ChromeOrRecentNavLink in my latest commit to refactor the code. Please take a look

// src/core/public/chrome/ui/header/nav_link.tsx
export type ChromeOrRecentNavLink = ChromeNavLink | RecentNavLink;

// src/core/public/chrome/ui/header/collapsible_nav.tsx
function getAllCategories(allCategorizedLinks: Record<string, ChromeOrRecentNavLink[]>) {
    ...
}

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
@yuye-aws yuye-aws requested a review from wanglam August 18, 2023 04:19
@yuye-aws yuye-aws requested a review from ruanyl August 18, 2023 06:03
@@ -110,12 +109,11 @@ export interface RecentNavLink {
* @param navLinks
* @param basePath
*/
export function createRecentNavLink(
export function createRecentChromeNavLink(
Copy link
Owner

Choose a reason for hiding this comment

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

I'm still looking at the this, please don't merge for now, having a few doubts need to figure out

id: '',
disabled: true,
category: recentlyVisitedCategory,
title: i18n.translate('core.ui.EmptyRecentlyVisitied', {
Copy link
Owner

Choose a reason for hiding this comment

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

Typo, Visited

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Copy link
Owner

@ruanyl ruanyl left a comment

Choose a reason for hiding this comment

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

Nice work!

@yuye-aws yuye-aws merged commit 7fd4139 into ruanyl:workspace Aug 21, 2023
37 of 39 checks passed
@yuye-aws yuye-aws deleted the recently branch August 21, 2023 04:30
SuZhou-Joe pushed a commit that referenced this pull request Aug 31, 2023
* refactor recently visited links to category

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* bring back external link logic

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add no recently visited items when empty

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change annotation

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* refactor with type RecentNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* rename navlink type from ChromeOrRecentNavLink to CollapsibleNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
SuZhou-Joe pushed a commit that referenced this pull request Aug 31, 2023
* refactor recently visited links to category

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* bring back external link logic

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add no recently visited items when empty

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change annotation

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* refactor with type RecentNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* rename navlink type from ChromeOrRecentNavLink to CollapsibleNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
ruanyl pushed a commit that referenced this pull request Sep 15, 2023
* refactor recently visited links to category

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* bring back external link logic

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add no recently visited items when empty

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change annotation

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* refactor with type RecentNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* rename navlink type from ChromeOrRecentNavLink to CollapsibleNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
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.

4 participants