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]Add WorkspaceCollaboratorTypesService and AddCollaboratorsModal #8486

Conversation

wanglam
Copy link
Contributor

@wanglam wanglam commented Oct 4, 2024

Description

This PR is for adding WorkspaceCollaboratorTypesService to allow set customized collaborator types. These types will be used in the workspace settings refactor PR. It allow customized different UI when adding collaborators in workspace detail page. This PR added a setCollaboratorTypes method in workspace setup return value to customize the collaborator using interface below.

export interface WorkspaceCollaboratorType {
  id: string;
  name: string;
  buttonLabel: string;
  getDisplayedType?: (collaborator: WorkspaceCollaborator) => boolean;
  onAdd: ({ onAddCollaborators }: OnAddOptions) => Promise<void>;
}

export interface WorkspacePluginSetup {
  setCollaboratorTypes: (collaboratorTypes: WorkspaceCollaboratorType[]) => void;
  getAddCollaboratorsModal: () => typeof AddCollaboratorsModal;
}

Here are some examples to register collaborator types:
https://github.com/opensearch-project/OpenSearch-Dashboards/blob/0ea1c3462f20099b4f02c61c7092d2118262f8ea/src/plugins/workspace/public/register_default_collaborator_types.tsx

Screenshot

  • AddCollaboratorsModal for adding user
    image

  • AddCollaboratorsModal for adding group
    image

Testing the changes

Can refer new added testing cases in files below:

  • src/plugins/workspace/public/plugin.test.ts
  • src/plugins/workspace/public/services/workspace_collaborator_types_service.test.ts
  • src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.test.tsx
  • src/plugins/workspace/public/components/add_collaborators_modal/workspace_collaborator_input.test.tsx
  • src/plugins/workspace/public/components/add_collaborators_modal/workspace_collaborators_panel.test.tsx

Changelog

  • feat: [Workspace]Add WorkspaceCollaboratorTypesService and AddCollaboratorsModal

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

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

Project coverage is 60.95%. Comparing base (57eea79) to head (e9c7f62).
Report is 103 commits behind head on main.

Files with missing lines Patch % Lines
...llaborators_modal/workspace_collaborator_input.tsx 92.85% 0 Missing and 1 partial ⚠️
...laborators_modal/workspace_collaborators_panel.tsx 93.75% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8486   +/-   ##
=======================================
  Coverage   60.94%   60.95%           
=======================================
  Files        3760     3766    +6     
  Lines       89301    89359   +58     
  Branches    13969    13977    +8     
=======================================
+ Hits        54426    54468   +42     
- Misses      31480    31493   +13     
- Partials     3395     3398    +3     
Flag Coverage Δ
Linux_1 28.96% <96.61%> (+0.05%) ⬆️
Linux_2 56.30% <ø> (ø)
Linux_3 37.76% <ø> (-0.01%) ⬇️
Linux_4 29.93% <ø> (ø)
Windows_1 28.98% <96.61%> (+0.04%) ⬆️
Windows_2 56.25% <ø> (ø)
Windows_3 37.76% <ø> (ø)
Windows_4 29.93% <ø> (ø)

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.

SuZhou-Joe
SuZhou-Joe previously approved these changes Oct 4, 2024
Comment on lines 12 to 37
export interface WorkspaceCollaboratorType {
id: string;
name: string;
pluralName: string;
// Will be assigned to this type in the final ACL permissions object
permissionSettingType: WorkspaceCollaboratorPermissionSettingType;
modal: {
title: string;
description?: string;
// Will use name with ID suffix for fallback
inputLabel?: string;
inputDescription?: string;
// Will use name with ID suffix for fallback
inputPlaceholder?: string;
};
instruction?: {
title: string;
detail: string;
link?: string;
};
// To match wether passed collaborator match this collaborator type
collaboratorMatcher?: (collaborator: {
type: WorkspaceCollaboratorPermissionSettingType;
userOrGroupId: string;
}) => boolean;
}
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
export interface WorkspaceCollaboratorType {
id: string;
name: string;
pluralName: string;
// Will be assigned to this type in the final ACL permissions object
permissionSettingType: WorkspaceCollaboratorPermissionSettingType;
modal: {
title: string;
description?: string;
// Will use name with ID suffix for fallback
inputLabel?: string;
inputDescription?: string;
// Will use name with ID suffix for fallback
inputPlaceholder?: string;
};
instruction?: {
title: string;
detail: string;
link?: string;
};
// To match wether passed collaborator match this collaborator type
collaboratorMatcher?: (collaborator: {
type: WorkspaceCollaboratorPermissionSettingType;
userOrGroupId: string;
}) => boolean;
}
export interface WorkspaceCollaboratorType {
id: string;
name: string;
onAdd: () => any
}
// `onAdd` function will be called when the dropdown menu been clicked
// It will show a modal, for example something like
{
onAdd: () => coreStart.overlays.openModal(mount(<AddCollaboratorModal permissionType={} title="" {...} />))
}

This way, we maximize the flexibility of how the add collaborator modal should be look like, at the same time, it keeps the API simple. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I guess collaboratorMatcher is needed either way because it will be used to populate the type column in collaborator table.

If we are gonna to use onAdd, I guess we need to add some callback functions like

onAdd: (props: { onChange: (value: valueTypeForCollaborator) => void }) => ...

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @SuZhou-Joe what will onChange do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think valueTypeForCollaborator should be an array. Will refactor code like this and include the AddCollaboratorModal in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

If we use a modal to maximize the flexibility, we need a callback to tell the parent component that user has added a user id. Or I do not know how we can communicate with parent component.

Signed-off-by: Lin Wang <[email protected]>
@wanglam wanglam changed the title [Workspace]Add WorkspaceCollaboratorTypesService [Workspace]Add WorkspaceCollaboratorTypesService and AddCollaboratorsModal Oct 4, 2024
@wanglam
Copy link
Contributor Author

wanglam commented Oct 4, 2024

Hi @ruanyl @SuZhou-Joe , I've refactor code base our discussions. Could you help me take a look? Thank you.

Copy link
Member

@ruanyl ruanyl 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 the quick updates! It looks good to me, I left a few minor comments

</>
)}
{collaborators.map((item, index) => (
<React.Fragment key={item.id}>
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this React.Fragment is unnecessary

overlayRef?.close();
}}
onAddCollaborators={async (collaborators) => {
await onAddCollaborators(collaborators);
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 try/catch here? perhaps could be a future improvement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should we do after catch an error? Do we need to prevent the modal close? Add a try catch would be better, but it's up to the collaborator type register. I think we can added it when we need it.

setCollaboratorTypes: (types: WorkspaceCollaboratorType[]) => {
this.collaboratorTypes.setTypes(types);
},
getAddCollaboratorsModal: () => AddCollaboratorsModal,
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 follow this pattern? It looks when plugin expose components, it exposes under ui property

Suggested change
getAddCollaboratorsModal: () => AddCollaboratorsModal,
ui: { AddCollaboratorsModal },

Comment on lines 566 to 568
setCollaboratorTypes: (types: WorkspaceCollaboratorType[]) => {
this.collaboratorTypes.setTypes(types);
},
Copy link
Member

Choose a reason for hiding this comment

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

I think we can expose the entire collaboratorTypes service.

Suggested change
setCollaboratorTypes: (types: WorkspaceCollaboratorType[]) => {
this.collaboratorTypes.setTypes(types);
},
collaboratorTypes: this.collaboratorTypes;
},

SuZhou-Joe
SuZhou-Joe previously approved these changes Oct 4, 2024
Signed-off-by: Lin Wang <[email protected]>
@ruanyl ruanyl merged commit d3ddf91 into opensearch-project:main Oct 5, 2024
67 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 5, 2024
…Modal (#8486)

(cherry picked from commit d3ddf91)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ruanyl pushed a commit that referenced this pull request Oct 8, 2024
…Modal (#8486) (#8499)

(cherry picked from commit d3ddf91)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@ananzh ananzh added the v2.18.0 label Oct 30, 2024
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.

4 participants