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 privacy levels to the workspace #8907

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9050233
Add privacy selector UI at create page
Kapian1234 Nov 18, 2024
1265b85
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
Kapian1234 Nov 20, 2024
4def508
Add privacy settings UI at collaborstors page
Kapian1234 Nov 21, 2024
4e07afd
Changeset file for PR #8907 created/updated
opensearch-changeset-bot[bot] Nov 21, 2024
3f68926
Add privacy settings panel at collaborstors page
Kapian1234 Nov 25, 2024
b78909d
Merge branch 'workspace_privacy_settings' of github.com:Kapian1234/Op…
Kapian1234 Nov 25, 2024
19503d3
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
Kapian1234 Nov 25, 2024
609c9df
Fix the height of cards at workspace create page
Kapian1234 Nov 25, 2024
c363739
Refactor workspace creator form with privacyType and setPrivacyType
wanglam Nov 26, 2024
1ef6afe
Resolve some issues
Kapian1234 Nov 26, 2024
b73a75f
Resolve conflicts
Kapian1234 Nov 26, 2024
72fa00f
Add privacy settings control at details page
Kapian1234 Nov 27, 2024
b0eec18
Add single star user check for add collaborators modal
wanglam Nov 26, 2024
2655936
Disable save button if the selected privay type remains unchanged at …
Kapian1234 Nov 28, 2024
f772a0d
Fix workspace creator UT
wanglam Nov 29, 2024
1a96f10
Fix failed snapshots
wanglam Nov 29, 2024
6e4084c
Add missing UT for workspace form utils
wanglam Nov 29, 2024
50f1fac
Update UT for useWorkspaceForm
wanglam Nov 29, 2024
ba1e995
Add unit tests for privacy settings at workspace create and details
Kapian1234 Dec 2, 2024
37c9c36
Merge branch 'workspace_privacy_settings' of github.com:Kapian1234/Op…
Kapian1234 Dec 2, 2024
e0fa159
/
Kapian1234 Dec 2, 2024
07a9c7b
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
Kapian1234 Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8907.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add privacy levels to the workspace ([#8907](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8907))
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React from 'react';
import { EuiPage, EuiPanel } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPanel } from '@elastic/eui';
import { i18n } from '@osd/i18n';

import { useObservable } from 'react-use';
Expand All @@ -25,6 +25,7 @@ import {
} from '../workspace_form';
import { WorkspaceAttributeWithPermission } from '../../../../../core/types';
import { WorkspaceClient } from '../../workspace_client';
import { WorkspaceCollaboratorPrivacySettingPanel } from '../workspace_form/workspace_collaborator_privacy_setting_panel';

export const WorkspaceCollaborators = () => {
const {
Expand Down Expand Up @@ -116,13 +117,23 @@ export const WorkspaceCollaborators = () => {
]}
setMountPoint={application?.setAppRightControls}
/>
<EuiPanel>
<WorkspaceCollaboratorTable
permissionSettings={permissionSettings}
displayedCollaboratorTypes={displayedCollaboratorTypes}
handleSubmitPermissionSettings={handleSubmitPermissionSettings}
/>
</EuiPanel>
<EuiFlexGroup direction="column">
<EuiFlexItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to use flex item here? I think can be replaced with EuiSpacer

Copy link
Contributor Author

@Kapian1234 Kapian1234 Nov 26, 2024

Choose a reason for hiding this comment

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

      <WorkspaceCollaboratorPrivacySettingPanel
        permissionSettings={permissionSettings}
        handleSubmitPermissionSettings={handleSubmitPermissionSettings}
      />
      <EuiSpacer />
      <WorkspaceCollaboratorTable
        permissionSettings={permissionSettings}
        displayedCollaboratorTypes={displayedCollaboratorTypes}
        handleSubmitPermissionSettings={handleSubmitPermissionSettings}
      />

it would be like this if not using flex
Screenshot 2024-11-26 at 10 32 56

Copy link
Contributor

Choose a reason for hiding this comment

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

Try to wrap with a regular div.


      <div>
        <WorkspaceCollaboratorPrivacySettingPanel
          permissionSettings={permissionSettings}
          handleSubmitPermissionSettings={handleSubmitPermissionSettings}
        />
        <EuiSpacer />
        <EuiPanel>
          <WorkspaceCollaboratorTable
            permissionSettings={permissionSettings}
            displayedCollaboratorTypes={displayedCollaboratorTypes}
            handleSubmitPermissionSettings={handleSubmitPermissionSettings}
          />
        </EuiPanel>
      </div>

It won't using a horizontal layout.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, the Edit button seems not aligned with "Workspace privacy" title. Shall we fix it?
image

Copy link
Contributor Author

@Kapian1234 Kapian1234 Nov 26, 2024

Choose a reason for hiding this comment

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

alignItems="baseline" would fix it. Thanks for reminder!

<WorkspaceCollaboratorPrivacySettingPanel
permissionSettings={permissionSettings}
handleSubmitPermissionSettings={handleSubmitPermissionSettings}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiPanel>
<WorkspaceCollaboratorTable
permissionSettings={permissionSettings}
displayedCollaboratorTypes={displayedCollaboratorTypes}
handleSubmitPermissionSettings={handleSubmitPermissionSettings}
/>
</EuiPanel>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPage>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
navigationUI: NavigationPublicPluginStart['ui'];
}>();
const [isFormSubmitting, setIsFormSubmitting] = useState(false);
const [goToCollaborators, setGoToCollaborators] = useState(false);
const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled;

const { isOnlyAllowEssential, availableUseCases } = useFormAvailableUseCases({
Expand Down Expand Up @@ -145,7 +146,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
?.features[0].id;
// Redirect page after one second, leave one second time to show create successful toast.
window.setTimeout(() => {
if (isPermissionEnabled) {
if (isPermissionEnabled && goToCollaborators) {
Kapian1234 marked this conversation as resolved.
Show resolved Hide resolved
navigateToAppWithinWorkspace(
{ application, http },
newWorkspaceId,
Expand Down Expand Up @@ -186,6 +187,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
isFormSubmitting,
availableUseCases,
isPermissionEnabled,
goToCollaborators,
]
);

Expand Down Expand Up @@ -225,6 +227,8 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
availableUseCases={availableUseCases}
defaultValues={defaultWorkspaceFormValues}
isSubmitting={isFormSubmitting}
goToCollaborators={goToCollaborators}
onGoToCollaboratorsChange={setGoToCollaborators}
/>
)}
</EuiPageContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import { generateRightSidebarScrollProps, RightSidebarScrollField } from './util
import { CreatorDetailsPanel } from './creator_details_panel';

import './workspace_creator_form.scss';
import { WorkspacePrivacySettingPanel } from '../workspace_form/workspace_privacy_setting_panel';

interface WorkspaceCreatorFormProps extends WorkspaceFormProps {
isSubmitting: boolean;
goToCollaborators: boolean;
onGoToCollaboratorsChange: (value: boolean) => void;
}

export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {
Expand All @@ -42,6 +45,7 @@ export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {
handleColorChange,
handleUseCaseChange,
setSelectedDataSourceConnections,
setPermissionSettings,
} = useWorkspaceForm(props);

const isDashboardAdmin = application?.capabilities?.dashboards?.isDashboardAdmin ?? false;
Expand Down Expand Up @@ -110,6 +114,15 @@ export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {
</EuiPanel>
</>
)}
<EuiSpacer size="m" />
{isDashboardAdmin && (
<WorkspacePrivacySettingPanel
Kapian1234 marked this conversation as resolved.
Show resolved Hide resolved
onPermissionChange={setPermissionSettings}
permissionSettings={formData.permissionSettings}
goToCollaborators={props.goToCollaborators}
onGoToCollaboratorsChange={props.onGoToCollaboratorsChange}
/>
)}
</EuiForm>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export enum WorkspacePermissionItemType {
Group = 'group',
}

export enum WorkspacePrivacyItemType {
PrivateToCollaborators = 'privat-to-collaborators',
AnyoneCanView = 'anyone-can-view',
AnyoneCanEdit = 'anyone-can-edit',
}

export const optionIdToWorkspacePermissionModesMap: {
[key: string]: WorkspacePermissionMode[];
} = {
Expand Down Expand Up @@ -102,6 +108,42 @@ export const detailsColorHelpText = i18n.translate(
}
);

export const privacyTypePrivateTitle = i18n.translate(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm prefer to add a privacy type map to organize all these copy. Such as

const privacyType2CopyMap = {
    [WorkspacePrivacyItemType. PrivateToCollaborators]: {
        title: i18n.translate('workspace.privacy.anyoneCanView.title', {
            defaultMessage: 'Anyone can view',
        }),
        description: i18n.translate('workspace.privacy.privateToCollaborators.description', {
            defaultMessage: 'Only collaborators can access the workspace.',
        }),
    },
};

'workspace.privacy.privateToCollaborators.title',
{
defaultMessage: 'Private to collaborators',
}
);

export const privacyTypeViewTitle = i18n.translate('workspace.privacy.anyoneCanView.title', {
defaultMessage: 'Anyone can view',
});

export const privacyTypeEditTitle = i18n.translate('workspace.privacy.anyoneCanEdit.title', {
defaultMessage: 'Anyone can edit',
});

export const privacyTypePrivateDescription = i18n.translate(
'workspace.privacy.privateToCollaborators.description',
{
defaultMessage: 'Only collaborators can access the workspace.',
}
);

export const privacyTypeViewDescription = i18n.translate(
'workspace.privacy.anyoneCanView.description',
{
defaultMessage: 'Anyone can view workspace assets.',
}
);

export const privacyTypeEditDescription = i18n.translate(
'workspace.privacy.anyoneCanEdit.description',
{
defaultMessage: 'Anyone can view and edit workspace assets.',
}
);

export const PERMISSION_TYPE_LABEL_ID = 'workspace-form-permission-type-label';
export const PERMISSION_COLLABORATOR_LABEL_ID = 'workspace-form-permission-collaborator-label';
export const PERMISSION_ACCESS_LEVEL_LABEL_ID = 'workspace-form-permission-access-level-label';
Expand Down
Loading
Loading