forked from opensearch-project/OpenSearch-Dashboards
-
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: in left menu, move recently viewed from top to middle #87
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b0ed786
refactor recently visited links to category
yuye-aws 750a3b9
bring back external link logic
yuye-aws 0569e80
add no recently visited items when empty
yuye-aws 5ed0c86
change annotation
yuye-aws 3261510
refactor with type RecentNavLink
yuye-aws 40421c9
rename navlink type from ChromeOrRecentNavLink to CollapsibleNavLink
yuye-aws 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 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 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 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 |
---|---|---|
|
@@ -31,22 +31,21 @@ | |
import { EuiIcon } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import React from 'react'; | ||
import { ChromeNavLink, ChromeRecentlyAccessedHistoryItem, CoreStart } from '../../..'; | ||
import { AppCategory, ChromeNavLink, ChromeRecentlyAccessedHistoryItem, CoreStart } from '../../..'; | ||
import { HttpStart } from '../../../http'; | ||
import { InternalApplicationStart } from '../../../application/types'; | ||
import { relativeToAbsolute } from '../../nav_links/to_nav_link'; | ||
|
||
export const isModifiedOrPrevented = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => | ||
event.metaKey || event.altKey || event.ctrlKey || event.shiftKey || event.defaultPrevented; | ||
|
||
export type CollapsibleNavLink = ChromeNavLink | RecentNavLink; | ||
interface Props { | ||
link: ChromeNavLink; | ||
link: ChromeNavLink | RecentNavLink; | ||
appId?: string; | ||
basePath?: HttpStart['basePath']; | ||
dataTestSubj: string; | ||
onClick?: Function; | ||
navigateToApp: CoreStart['application']['navigateToApp']; | ||
externalLink?: boolean; | ||
} | ||
|
||
// TODO #64541 | ||
|
@@ -73,6 +72,7 @@ export function createEuiListItem({ | |
} | ||
|
||
if ( | ||
!link.externalLink && // ignore external links | ||
event.button === 0 && // ignore everything but left clicks | ||
!isModifiedOrPrevented(event) | ||
) { | ||
|
@@ -91,14 +91,16 @@ export function createEuiListItem({ | |
}; | ||
} | ||
|
||
export interface RecentNavLink { | ||
href: string; | ||
label: string; | ||
title: string; | ||
'aria-label': string; | ||
iconType?: string; | ||
onClick: React.MouseEventHandler; | ||
} | ||
export type RecentNavLink = Omit<ChromeNavLink, 'baseUrl'>; | ||
|
||
const recentlyVisitedCategory: AppCategory = { | ||
id: 'recentlyVisited', | ||
label: i18n.translate('core.ui.recentlyVisited.label', { | ||
defaultMessage: 'Recently Visited', | ||
}), | ||
order: 0, | ||
euiIconType: 'clock', | ||
}; | ||
|
||
/** | ||
* Add saved object type info to recently links | ||
|
@@ -110,11 +112,10 @@ export interface RecentNavLink { | |
* @param navLinks | ||
* @param basePath | ||
*/ | ||
export function createRecentNavLink( | ||
export function createRecentChromeNavLink( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
recentLink: ChromeRecentlyAccessedHistoryItem, | ||
navLinks: ChromeNavLink[], | ||
basePath: HttpStart['basePath'], | ||
navigateToUrl: InternalApplicationStart['navigateToUrl'] | ||
basePath: HttpStart['basePath'] | ||
): RecentNavLink { | ||
const { link, label } = recentLink; | ||
const href = relativeToAbsolute(basePath.prepend(link)); | ||
|
@@ -133,16 +134,20 @@ export function createRecentNavLink( | |
|
||
return { | ||
href, | ||
label, | ||
id: recentLink.id, | ||
externalLink: true, | ||
category: recentlyVisitedCategory, | ||
title: titleAndAriaLabel, | ||
'aria-label': titleAndAriaLabel, | ||
iconType: navLink?.euiIconType, | ||
/* Use href and onClick to support "open in new tab" and SPA navigation in the same link */ | ||
onClick(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) { | ||
if (event.button === 0 && !isModifiedOrPrevented(event)) { | ||
event.preventDefault(); | ||
navigateToUrl(href); | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
// As emptyRecentlyVisited is disabled, values for id, href and baseUrl does not affect | ||
export const emptyRecentlyVisited: RecentNavLink = { | ||
id: '', | ||
href: '', | ||
disabled: true, | ||
category: recentlyVisitedCategory, | ||
title: i18n.translate('core.ui.EmptyRecentlyVisited', { | ||
defaultMessage: 'No recently visited items', | ||
}), | ||
}; |
Oops, something went wrong.
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.
Will we still show
No recently viewed items
after this refactor?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.
No. This edge case for recently visited and favorites needs to be confirmed with UX.
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.
Just get to know that
No recently viewed items
need to show. I will add it later.