-
Notifications
You must be signed in to change notification settings - Fork 923
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
Changes from 18 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) => (workspaceEnabled ? !!item.workspaceId : true)), | ||
|
||
/** 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? |
||
}) | ||
); | ||
}, | ||
}; | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,6 @@ describe('createRecentNavLink', () => { | |
mockedNavigateToUrl | ||
); | ||
|
||
expect(recentLink.href).toEqual('http://localhost/test/w/foo/app/foo'); | ||
expect(recentLink.href).toEqual('http://localhost/test/app/foo'); | ||
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 need to add test case for workspace disabled? 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. Added |
||
}); | ||
}); |
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.
I'm thinking, should the filtering logic be done in the component where the data is used?
@SuZhou-Joe @wanglam what do you think?
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.
Correct me if I missing understanding. I remember we discuss this offline. All recent accessed items should applied the same filtering logic.
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.
Right, if we do the filtering logic in component, then we need to applied the same logic in multiple places.
But it occurs to me that we can use different storage key for workspace enabled / workspace disabled, then we do not need to use filter.
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.
I see, I'm fine with it now.
Sounds good to me, could a future improvement/refactor task