-
Notifications
You must be signed in to change notification settings - Fork 919
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
Fix the display and jump logic for recent assets #8136
base: main
Are you sure you want to change the base?
Changes from 5 commits
4707fac
66f2b68
5a07c11
8ff5a28
9a540d3
3340ea8
41a1ca4
37db157
8fff3cf
e4fe87c
879917e
ea1e2ab
0d046b9
291e82d
07a6f74
af72d86
9c0064e
7c28a46
0c92d9e
4c83a8c
101c4b8
d6ee2f1
4d375a1
bef66a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- Fix the display and jump logic for recent assets ([#8136](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8136)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,12 @@ | |
*/ | ||
|
||
import { Observable } from 'rxjs'; | ||
|
||
import { map } from 'rxjs/operators'; | ||
import { PersistedLog } from './persisted_log'; | ||
import { createLogKey } from './create_log_key'; | ||
import { HttpSetup } from '../../http'; | ||
import { WorkspacesStart } from '../../workspace'; | ||
import { InternalApplicationStart } from '../../application'; | ||
|
||
/** @public */ | ||
export interface ChromeRecentlyAccessedHistoryItem { | ||
|
@@ -50,16 +51,18 @@ export interface ChromeRecentlyAccessedHistoryItem { | |
interface StartDeps { | ||
http: HttpSetup; | ||
workspaces: WorkspacesStart; | ||
application: InternalApplicationStart; | ||
} | ||
|
||
/** @internal */ | ||
export class RecentlyAccessedService { | ||
async start({ http, workspaces }: StartDeps): Promise<ChromeRecentlyAccessed> { | ||
async start({ http, workspaces, application }: StartDeps): Promise<ChromeRecentlyAccessed> { | ||
const logKey = await createLogKey('recentlyAccessed', http.basePath.getBasePath()); | ||
const history = new PersistedLog<ChromeRecentlyAccessedHistoryItem>(logKey, { | ||
maxLength: 20, | ||
isEqual: (oldItem, newItem) => oldItem.id === newItem.id, | ||
}); | ||
const workspaceEnabled = application.capabilities.workspaces.enabled; | ||
|
||
return { | ||
/** Adds a new item to the history. */ | ||
|
@@ -81,10 +84,16 @@ export class RecentlyAccessedService { | |
}, | ||
|
||
/** Gets the current array of history items. */ | ||
get: () => history.get(), | ||
get: () => history.get().filter((item) => !!item.workspaceId), | ||
|
||
/** Gets an observable of the current array of history items. */ | ||
get$: () => history.get$(), | ||
get$: () => { | ||
return history.get$().pipe( | ||
map((items) => { | ||
return items.filter((item) => (workspaceEnabled ? !!item.workspaceId : true)); | ||
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. Can we add some UT to test this filtering logic? |
||
}) | ||
); | ||
}, | ||
}; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -125,13 +125,17 @@ export function createRecentNavLink( | |||||
recentLink: ChromeRecentlyAccessedHistoryItem, | ||||||
navLinks: ChromeNavLink[], | ||||||
basePath: HttpStart['basePath'], | ||||||
navigateToUrl: InternalApplicationStart['navigateToUrl'] | ||||||
navigateToUrl: InternalApplicationStart['navigateToUrl'], | ||||||
workspaceEnabled: boolean = true | ||||||
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. The default value should be false I think? 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. Indeed, it should be false. |
||||||
): RecentNavLink { | ||||||
const { link, label, workspaceId } = recentLink; | ||||||
const href = relativeToAbsolute( | ||||||
basePath.prepend(formatUrlWithWorkspaceId(link, workspaceId || '', basePath), { | ||||||
withoutClientBasePath: true, | ||||||
}) | ||||||
basePath.prepend( | ||||||
formatUrlWithWorkspaceId(link, workspaceEnabled ? workspaceId || '' : '', basePath), | ||||||
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. This logic looks a little bit strange to me, I think we don't need to call
Suggested change
By the way, can we add some unit tests about it? 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. sure |
||||||
{ | ||||||
withoutClientBasePath: true, | ||||||
} | ||||||
) | ||||||
); | ||||||
const navLink = navLinks.find((nl) => href.startsWith(nl.baseUrl)); | ||||||
let titleAndAriaLabel = label; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,9 +232,9 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean | |
recentAccessItem, | ||
navLinks, | ||
core.http.basePath, | ||
core.application.navigateToUrl | ||
core.application.navigateToUrl, | ||
!!workspaceEnabled | ||
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. Shall we do a search for the places that are using
|
||
); | ||
|
||
content = ( | ||
<EuiCard | ||
title={ | ||
|
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 this impact workspace disabled case? I think we should check workspaceEnabled flag
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.
yes I forgot it here, thx for reminding!