-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add a dashboard breadcrumb when user naviagte from dashboard #10904
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
Open
Maosaic
wants to merge
4
commits into
opensearch-project:main
Choose a base branch
from
Maosaic:breadcrumbs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−3
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5da6ba2
Add a dashboard breadcrumb when user naviagte from dashboard
Maosaic 7e3732e
fix(breadcrumbs): update discover breadcrumbs to include dashboard list
ruanyl 9cd3d5f
Changeset file for PR #10904 created/updated
opensearch-changeset-bot[bot] 359b1b9
Address comments
Maosaic 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| feat: | ||
| - Add a dashboard breadcrumb when user naviagte from dashboard ([#10904](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10904)) |
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
74 changes: 74 additions & 0 deletions
74
src/plugins/explore/public/utils/get_previous_page_breadcrumb.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,74 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { ChromeStart, ChromeRecentlyAccessedHistoryItem, ApplicationStart } from 'src/core/public'; | ||
|
|
||
| export interface BreadcrumbConfig { | ||
| href?: string; | ||
| onClick?: () => void; | ||
| } | ||
|
|
||
| export interface PreviousPageInfo { | ||
| breadcrumbConfig: BreadcrumbConfig; | ||
| previousPage?: ChromeRecentlyAccessedHistoryItem; | ||
| } | ||
|
|
||
| export interface GetBreadcrumbOptions { | ||
| chrome: ChromeStart; | ||
| application?: ApplicationStart; | ||
| currentPageId?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Get breadcrumb configuration that navigates to the previous page | ||
| * Uses chrome.recentlyAccessed to determine where the user came from | ||
| * | ||
| * @param options - Configuration options | ||
| * @returns Previous page info with breadcrumb config | ||
| */ | ||
| export function getPreviousPageBreadcrumb(options: GetBreadcrumbOptions): PreviousPageInfo { | ||
| const { chrome, application, currentPageId: pageId } = options; | ||
| const recentlyAccessed = chrome.recentlyAccessed.get(); | ||
|
|
||
| // Get the most recently accessed page (first item, which is most recent) | ||
| // Skip if it's the current page | ||
| const previousPage = | ||
| recentlyAccessed.length > 0 && recentlyAccessed[0].id !== pageId | ||
| ? recentlyAccessed[0] | ||
| : undefined; | ||
|
|
||
| if (previousPage && previousPage.link) { | ||
| // We found a previous page - construct the full URL with workspace ID | ||
| let href = previousPage.link; | ||
|
|
||
| // Check if the current URL has a workspace ID and the previous page link doesn't | ||
| const currentPathname = window.location.pathname; | ||
| const workspaceMatch = currentPathname.match(/\/w\/([^/]+)\//); | ||
|
|
||
| if (workspaceMatch && !href.includes('/w/')) { | ||
| // Add workspace ID to the href | ||
| const workspaceId = workspaceMatch[1]; | ||
| href = `/w/${workspaceId}${href}`; | ||
| } | ||
|
|
||
| // If application service is available, use onClick with navigateToUrl for SPA navigation | ||
| if (application) { | ||
| return { | ||
| breadcrumbConfig: { | ||
| onClick: () => { | ||
| application.navigateToUrl(href); | ||
| }, | ||
| }, | ||
| previousPage, | ||
| }; | ||
| } | ||
|
|
||
| // Fallback to href (may cause hard refresh) | ||
| return { breadcrumbConfig: { href }, previousPage }; | ||
| } else { | ||
| // No previous page found, fallback to explore home | ||
| return { breadcrumbConfig: { href: '#/' } }; | ||
| } | ||
| } | ||
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.
not sure how reliable this is in the future, does workspace have API to get id?
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.
@joshuali925 yes, workspace has API to get the current workspace id