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

[Workspace] Feature/workspace service core module #5092

Merged

Conversation

ruanyl
Copy link
Member

@ruanyl ruanyl commented Sep 22, 2023

Description

The core workspace module(WorkspaceService) is a foundational component that enables the implementation of workspace features within OSD plugins. The purpose of the core workspace module is to provide a framework for workspace implementations.

This module does not implement specific workspace functionality but provides the essential infrastructure for plugins to
extend and customize workspace features, it maintains a shared workspace state(observables) across the entire application to ensure a consistent and up-to-date view of workspace-related information to all parts of the application.

Why introducing these changes to core?

The main consideration of introducing core workspace module includes:

  1. The workspace is a fundamental feature for OSD, the workspace state, such as currentWorkspace, workspaceList, etc maybe/is used by other core modules and core plugins, having it in core seems the most reasonable approached and it also makes it easy to be accessed.
  2. We don't want to make the workspace implementation opinionated, if encapsulating these changes in workspace plugin, it will make other core modules and core plugins to depend on workspace plugin. So we moved some abstractions to core(considering the efforts of maintaining such a small workspace module in core which I think worth it).

Issues Resolved

Partially resolved #5091

Screenshot

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

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Attention: Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.

Project coverage is 66.79%. Comparing base (f28b729) to head (a21adee).
Report is 735 commits behind head on main.

Files with missing lines Patch % Lines
src/core/public/workspace/workspaces_service.ts 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5092      +/-   ##
==========================================
+ Coverage   66.73%   66.79%   +0.05%     
==========================================
  Files        3284     3286       +2     
  Lines       63095    63129      +34     
  Branches    10049    10053       +4     
==========================================
+ Hits        42108    42164      +56     
+ Misses      18589    18570      -19     
+ Partials     2398     2395       -3     
Flag Coverage Δ
Linux_1 35.25% <26.66%> (-0.01%) ⬇️
Linux_2 55.29% <94.11%> (?)
Linux_3 43.82% <26.66%> (-0.02%) ⬇️
Linux_4 35.35% <26.66%> (-0.01%) ⬇️
Windows_1 35.27% <26.66%> (-0.01%) ⬇️
Windows_2 55.26% <94.11%> (+0.05%) ⬆️
Windows_3 43.83% <26.66%> (-0.02%) ⬇️
Windows_4 35.35% <26.66%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ruanyl ruanyl changed the title Feature/workspace service core module [Workspace] Feature/workspace service core module Sep 26, 2023
* SPDX-License-Identifier: Apache-2.0
*/

export interface WorkspaceAttribute {
Copy link
Member

Choose a reason for hiding this comment

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

if this a core type would be able to have a fast follow to use this one within the workspace plugin?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this type WorkspaceAttribute is the same as the one used in #5075 and this core type will be used by the plugin, is this what you are referring?

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha! So it's here for the sake of breaking down the PRs. Thanks!

Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! People do love extending core stuff.

Would you potentially be able to add inline commenting could be like something like this:
opensearch-project/opensearch-dashboards-sdk-js#47

which produced https://github.com/kavilla/opensearch-dashboards-sdk-js/blob/avillk/sdk_base_2_no_doc/docs/modules.md. That way, in the future if we have to we can run a skip to dump documentation since usually the hardest part about the extending core functionality for plugins usually tends to be lack of knowing the usages and what to respect.

currentWorkspaceId$: BehaviorSubject<string>;
currentWorkspace$: BehaviorSubject<WorkspaceObject | null>;
workspaceList$: BehaviorSubject<WorkspaceObject[]>;
workspaceEnabled$: BehaviorSubject<boolean>;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is redundant? Since a plugin being disabled is kind of a before run time operation.

When setting this up as well, the workspaces plugin can set the value for /api/core/capabilities and plugins can check it is available to use
http://localhost:5609/vzu/api/core/capabilities

Copy link
Member Author

@ruanyl ruanyl Sep 27, 2023

Choose a reason for hiding this comment

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

That's a very good point. I will remove this and update to use capabilities in the follow PRs

Copy link
Member Author

Choose a reason for hiding this comment

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

@kavilla Just to confirm that you mean we could use core.capabilities.registerProvider to register a flag when workspace plugin is loaded. Then we could read this at frontend via, for example application.capabilities.workspaces.loaded

Copy link
Member

Choose a reason for hiding this comment

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

Cool. I've fine with being part of a backlog but to be revisited prior to 2.11

cc: @manasvinibs (since she has worked a lot with it)

@kavilla
Copy link
Member

kavilla commented Sep 28, 2023

I see the cypress tests failed I think it was cached will re-run it. But would you like me to run this against a branch of cypress tests within a fork of the ftrepo?

@kavilla
Copy link
Member

kavilla commented Sep 28, 2023

Overall, I think this fine. It's only going into unreleased for now so if it's unused by core functionality and then probably better off to get it merged sooner than later and let it bake in main for a little before getting into 2.x.

Will check if the cypress tests are successful and also could we update any of the files such as: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/80758aae438560445f8a1f8e69008e1c90603c84/src/core/public/public.api.md if they exist and require such changes.

@ruanyl ruanyl force-pushed the feature/workspace-service-core-module branch from 80758aa to 59b0a3e Compare September 28, 2023 08:17
@ruanyl
Copy link
Member Author

ruanyl commented Sep 28, 2023

Would you potentially be able to add inline commenting could be like something like this:
opensearch-project/opensearch-dashboards-sdk-js#47

Hi @kavilla , thanks for suggesting this, I've added some comments, but I'm not sure if that meets the standards. Please take a look if you have time :)

Also could you help to rerun the bwc test? Error shows OSD did not load properly, looks like a temporary issue. And I checked the failed cypress tests as well, it looks not related to this PR.

@ruanyl
Copy link
Member Author

ruanyl commented Sep 28, 2023

also could we update any of the files such as: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/80758aae438560445f8a1f8e69008e1c90603c84/src/core/public/public.api.md if they exist and require such changes.

Will keep this in mind and update those accordingly when appropriate.

kavilla
kavilla previously approved these changes Sep 30, 2023
Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

Cypress tests are failing like other PRs. Known issue we are working on.

@ruanyl
Copy link
Member Author

ruanyl commented Oct 7, 2023

Hi @AMoo-Miki, could you take another look at the PR and see if everything looks good to you? Much appreciate!

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

A couple minor questions, but no large concerns. I would like to have in this PR or the related issue a summary of why this needs to be exposed as a core service rather than entirely encapsulated in a plugin.

features?: string[];
color?: string;
icon?: string;
defaultVISTheme?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a design doc that explains this interface, and the use of this prop in particular?

Copy link
Member Author

Choose a reason for hiding this comment

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

Had a discussion with team, the original requirement was to support different theme on workspace level. But we're not going to support this in our initial release. I will remove defaultVISTheme for now to avoid confusion.

* The workspace that is derived from `currentWorkspaceId` and `workspaceList`, if
* `currentWorkspaceId` cannot be found from `workspaceList`, it will return an error
*
* This value MUST NOT set manually from outside of WorkspacesService
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to enforce this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think we can enforce it, that requires to refactor the current implementation a bit. Since this is the first PR, there will be other PRs will depends on this one, to avoid impacting others, what do you think if I create a task and come back to refactor this later?

Copy link
Member

Choose a reason for hiding this comment

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

We can definitely do it in a follow-up; the concern here is to make sure we don't expose any public interfaces that we don't intend to, because those will all be subject to semver once they go out in a release.

Comment on lines 29 to 30
* The list of available workspaces. This workspace list should be set by whoever
* the workspace functionalities
Copy link
Member

Choose a reason for hiding this comment

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

"by whoever the workspace functionalities" - sorry, I'm not following this. Can we rephrase?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! I think there was one line been removed accidentally, will fix this.

}

enum WORKSPACE_ERROR {
WORKSPACE_STALED = 'WORKSPACE_STALED',
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename? Maybe WORKSPACE_IS_STALE

* Do a simple idempotent verification here
*/
if (!isEqual(currentWorkspace, this.currentWorkspace$.getValue())) {
this.currentWorkspace$.next(currentWorkspace ?? null);
Copy link
Member

Choose a reason for hiding this comment

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

why do we want to use null here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think no particular reason, undefined also works, just null was used at the beginning :)


if (currentWorkspaceId && !currentWorkspace?.id) {
/**
* Current workspace is staled
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Current workspace is staled
* Current workspace is stale

@@ -341,3 +347,5 @@ export {
};

export { __osdBootstrap__ } from './osd_bootstrap';

export { WorkspacesStart, WorkspacesSetup, WorkspacesService } from './workspace';
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to export WorkspacesService? Doesn't it just get accessed via the core lifecycle methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, this is not necessary.

ruanyl and others added 11 commits October 13, 2023 16:39
The core workspace module(WorkspaceService) is a foundational component
that enables the implementation of workspace features within OSD
plugins. The purpose of the core workspace module is to provide
a framework for workspace implementations.

This module does not implement specific workspace
functionality but provides the essential infrastructure for plugins to
extend and customize workspace features, it maintains a shared
workspace state(observables) across the entire application to ensure
a consistent and up-to-date view of workspace-related information to
all parts of the application.

---------

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Co-authored-by: Miki <amoo_miki@yahoo.com>
Signed-off-by: Yulong Ruan <ruanyu1@gmail.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
@ruanyl
Copy link
Member Author

ruanyl commented Oct 13, 2023

I would like to have in this PR or the related issue a summary of why this needs to be exposed as a core service rather than entirely encapsulated in a plugin.

@joshuarrrr Updated it in the PR description

* SPDX-License-Identifier: Apache-2.0
*/

export { WorkspacesStart, WorkspacesService, WorkspacesSetup } from './workspaces_service';
Copy link
Member

Choose a reason for hiding this comment

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

shall we add a README.md to talk about some internals and usage of workspace service like https://github.com/opensearch-project/OpenSearch-Dashboards/tree/main/src/core/public/chrome

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, we have a separate PR that adds the documentation of workspace feature design and some implementation details #5282, I can add the one more section there about the WorkspacesService

Comment on lines +18 to +26
currentWorkspaceId$: BehaviorSubject<string>;

/**
* The workspace that is derived from `currentWorkspaceId` and `workspaceList`, if
* `currentWorkspaceId` cannot be found from `workspaceList`, it will return an error
*
* This value MUST NOT set manually from outside of WorkspacesService
*/
currentWorkspace$: BehaviorSubject<WorkspaceObject | null>;
Copy link
Member

Choose a reason for hiding this comment

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

doesn't the currentWorkspace object include workspace id that we need to have another observable for workspace id?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, ideally having currentWorkspaceId and workspaceList is good enough, because currentWorkspace can be derived from currentWorkspaceId and workspaceList.

However, in the actual code, the places that SET the current workspace normally only have the id and the places that GET the current workspace normally will need the entire workspace object.

The currentWorkspace$ is more like a helper, its computed from currentWorkspaceId$ and workspaceList$ once they changed.

* This is a flag which indicates the WorkspacesService module is initialized and ready
* for consuming by others. For example, the `workspaceList` has been set, etc
*/
initialized$: BehaviorSubject<boolean>;
Copy link
Member

Choose a reason for hiding this comment

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

this can only go from not initialized to initialized, does it needs to be an observable?

Copy link
Member Author

Choose a reason for hiding this comment

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

The intention of making it reactive is, the value changing from not initialized to initialized maybe happen at any time, this is unlike reading regular configurations which we get value when application is mount. Using an observable so that the application can react to the value change.

@zengyan-amazon
Copy link
Member

do we want to save the selected workspace in browser localStorage so that it can be remembered for next login?

@ruanyl
Copy link
Member Author

ruanyl commented Oct 16, 2023

do we want to save the selected workspace in browser localStorage so that it can be remembered for next login?

@zengyan-amazon Sounds good to me, could be an improvement task, I will create a task for this and discuss it with the team and UX.

@kavilla kavilla merged commit 9e3e3a7 into opensearch-project:main Oct 17, 2023
57 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 1, 2023
* feat: add core workspace module (#145)

The core workspace module(WorkspaceService) is a foundational component
that enables the implementation of workspace features within OSD
plugins. The purpose of the core workspace module is to provide
a framework for workspace implementations.

This module does not implement specific workspace
functionality but provides the essential infrastructure for plugins to
extend and customize workspace features, it maintains a shared
workspace state(observables) across the entire application to ensure
a consistent and up-to-date view of workspace-related information to
all parts of the application.

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyu1@gmail.com>
Co-authored-by: Miki <amoo_miki@yahoo.com>
(cherry picked from commit 9e3e3a7)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
ananzh added a commit that referenced this pull request Dec 14, 2023
* [Workspace] Feature/workspace service core module (#5092)

* feat: add core workspace module (#145)

The core workspace module(WorkspaceService) is a foundational component
that enables the implementation of workspace features within OSD
plugins. The purpose of the core workspace module is to provide
a framework for workspace implementations.

This module does not implement specific workspace
functionality but provides the essential infrastructure for plugins to
extend and customize workspace features, it maintains a shared
workspace state(observables) across the entire application to ensure
a consistent and up-to-date view of workspace-related information to
all parts of the application.

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyu1@gmail.com>
Co-authored-by: Miki <amoo_miki@yahoo.com>
(cherry picked from commit 9e3e3a7)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Miki <miki@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Miki <miki@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.

[Workspace] Provides fundamental features from OSD core to support workspace development
5 participants