Skip to content

Commit

Permalink
fix: fix page hanging when none collaborators for non dashboard admin
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Dec 4, 2024
1 parent fe616e7 commit 2021419
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getNumberOfErrors,
isWorkspacePermissionSetting,
getPermissionModeName,
EMPTY_PERMISSIONS,
} from './utils';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionItemType, optionIdToWorkspacePermissionModesMap } from './constants';
Expand All @@ -19,9 +20,9 @@ import { WorkspaceFormErrorCode } from './types';
import { PermissionModeId } from '../../../../../core/public';

describe('convertPermissionSettingsToPermissions', () => {
it('should return undefined if permission items not provided', () => {
expect(convertPermissionSettingsToPermissions(undefined)).toBeUndefined();
expect(convertPermissionSettingsToPermissions([])).toBeUndefined();
it('should return empty permission object if permission items are not provided', () => {
expect(convertPermissionSettingsToPermissions(undefined)).toBe(EMPTY_PERMISSIONS);
expect(convertPermissionSettingsToPermissions([])).toBe(EMPTY_PERMISSIONS);
});

it('should not add duplicate users and groups', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/workspace/public/components/workspace_form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const isValidFormTextInput = (input?: string) => {
return typeof input === 'string' && regex.test(input);
};

export const EMPTY_PERMISSIONS = {
library_read: {},
library_write: {},
read: {},
write: {},
};

export const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => {
let numberOfErrors = 0;
if (formErrors.name) {
Expand Down Expand Up @@ -104,7 +111,8 @@ export const convertPermissionSettingsToPermissions = (
permissionItems: WorkspacePermissionSetting[] | undefined
) => {
if (!permissionItems || permissionItems.length === 0) {
return undefined;
// Workspace object should always have permissions, set it as an empty object here instead of undefined.
return EMPTY_PERMISSIONS;
}
return permissionItems.reduce<SavedObjectPermissions>((previous, current) => {
current.modes.forEach((mode) => {
Expand Down

0 comments on commit 2021419

Please sign in to comment.