From 3d4f1fd8ce62ed2cd35af23231062a95b70c500b Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 4 Apr 2023 13:37:36 -0400 Subject: [PATCH] 20085: Fix quirky behavior when removing share with public/all users row Fix some runtime warnings Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- src/services/common-service/common-service.ts | 6 +- .../sharing-dialog/sharing-dialog-actions.ts | 18 +++-- .../sharing-dialog-component.tsx | 2 +- .../sharing-invitation-form-component.tsx | 16 ++--- .../sharing-public-access-form-component.tsx | 2 +- .../sharing-dialog/sharing-urls-component.tsx | 68 +++++++++---------- .../visibility-level-select.tsx | 8 +-- 7 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index 4b857edd..8e9fe631 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -107,12 +107,14 @@ export class CommonService { ); } - delete(uuid: string): Promise { + delete(uuid: string, showErrors?: boolean): Promise { this.validateUuid(uuid); return CommonService.defaultResponse( this.serverApi .delete(`/${this.resourceType}/${uuid}`), - this.actions + this.actions, + true, // mapKeys + showErrors ); } diff --git a/src/store/sharing-dialog/sharing-dialog-actions.ts b/src/store/sharing-dialog/sharing-dialog-actions.ts index c998e767..fb34398e 100644 --- a/src/store/sharing-dialog/sharing-dialog-actions.ts +++ b/src/store/sharing-dialog/sharing-dialog-actions.ts @@ -49,8 +49,8 @@ export const connectSharingDialogProgress = withProgress(SHARING_DIALOG_NAME); export const saveSharingDialogChanges = async (dispatch: Dispatch, getState: () => RootState) => { dispatch(progressIndicatorActions.START_WORKING(SHARING_DIALOG_NAME)); - await dispatch(saveManagementChanges); await dispatch(savePublicPermissionChanges); + await dispatch(saveManagementChanges); await dispatch(sendInvitations); dispatch(reset(SHARING_INVITATION_FORM_NAME)); await dispatch(loadSharingDialog); @@ -236,7 +236,7 @@ const savePublicPermissionChanges = async (_: Dispatch, getState: () => RootStat // If visibility level changed, delete the previous link to public/all users. // On PRIVATE this link will be deleted by saveManagementChanges // so don't double delete (which would show an error dialog). - if (permissionUuid !== "" && visibility !== initialVisibility && visibility !== VisibilityLevel.PRIVATE) { + if (permissionUuid !== "" && visibility !== initialVisibility) { await permissionService.delete(permissionUuid); } if (visibility === VisibilityLevel.ALL_USERS) { @@ -272,10 +272,16 @@ const saveManagementChanges = async (_: Dispatch, getState: () => RootState, { p (a, b) => a.permissionUuid === b.permissionUuid ); - const deletions = cancelledPermissions.map(({ permissionUuid }) => - permissionService.delete(permissionUuid)); - const updates = permissions.map(update => - permissionService.update(update.permissionUuid, { name: update.permissions })); + const deletions = cancelledPermissions.map(async ({ permissionUuid }) => { + try { + await permissionService.delete(permissionUuid, false); + } catch (e) { } + }); + const updates = permissions.map(async update => { + try { + await permissionService.update(update.permissionUuid, { name: update.permissions }, false); + } catch (e) { } + }); await Promise.all([...deletions, ...updates]); } }; diff --git a/src/views-components/sharing-dialog/sharing-dialog-component.tsx b/src/views-components/sharing-dialog/sharing-dialog-component.tsx index ac1ebde1..089eee8d 100644 --- a/src/views-components/sharing-dialog/sharing-dialog-component.tsx +++ b/src/views-components/sharing-dialog/sharing-dialog-component.tsx @@ -90,7 +90,7 @@ export default (props: SharingDialogComponentProps) => { {...{ open, onClose }} className="sharing-dialog" fullWidth - maxWidth='sm' + maxWidth='md' disableBackdropClick={saveEnabled} disableEscapeKeyDown={saveEnabled}> diff --git a/src/views-components/sharing-dialog/sharing-invitation-form-component.tsx b/src/views-components/sharing-dialog/sharing-invitation-form-component.tsx index 17f3250a..3ff98b0a 100644 --- a/src/views-components/sharing-dialog/sharing-invitation-form-component.tsx +++ b/src/views-components/sharing-dialog/sharing-invitation-form-component.tsx @@ -49,15 +49,15 @@ const StyledSharingInvitationFormComponent = withStyles(styles)( - - + + - - + + ); diff --git a/src/views-components/sharing-dialog/sharing-public-access-form-component.tsx b/src/views-components/sharing-dialog/sharing-public-access-form-component.tsx index a9c9d6fc..bcee8dce 100644 --- a/src/views-components/sharing-dialog/sharing-public-access-form-component.tsx +++ b/src/views-components/sharing-dialog/sharing-public-access-form-component.tsx @@ -60,4 +60,4 @@ const SharingPublicAccessFormComponent = ({ visibility, includePublic, onSave }: export default SharingPublicAccessFormComponent; const VisibilityLevelSelectComponent = ({ input, includePublic }: { includePublic: boolean } & WrappedFieldProps) => - ; + ; diff --git a/src/views-components/sharing-dialog/sharing-urls-component.tsx b/src/views-components/sharing-dialog/sharing-urls-component.tsx index c9cbc0df..5facb2e3 100644 --- a/src/views-components/sharing-dialog/sharing-urls-component.tsx +++ b/src/views-components/sharing-dialog/sharing-urls-component.tsx @@ -14,7 +14,7 @@ import { withStyles } from '@material-ui/core'; import { ApiClientAuthorization } from 'models/api-client-authorization'; -import { CopyIcon, RemoveIcon } from 'components/icon/icon'; +import { CopyIcon, CloseIcon } from 'components/icon/icon'; import CopyToClipboard from 'react-copy-to-clipboard'; import { ArvadosTheme } from 'common/custom-theme'; import moment from 'moment'; @@ -58,38 +58,38 @@ export interface SharingURLsComponentActionProps { export type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps; export const SharingURLsComponent = withStyles(styles)((props: SharingURLsComponentProps & WithStyles) => - { props.sharingTokens.length > 0 - ? props.sharingTokens - .sort((a, b) => (new Date(a.expiresAt).getTime() - new Date(b.expiresAt).getTime())) - .map(token => { - const url = props.sharingURLsPrefix.includes('*') - ? `${props.sharingURLsPrefix.replace('*', props.collectionUuid)}/t=${token.apiToken}/_/` - : `${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${token.apiToken}/_/`; - const expDate = new Date(token.expiresAt); - const urlLabel = !!token.expiresAt - ? `Token ${token.apiToken.slice(0, 8)}... expiring at: ${expDate.toLocaleString()} (${moment(expDate).fromNow()})` - : `Token ${token.apiToken.slice(0, 8)}... with no expiration date`; + {props.sharingTokens.length > 0 + ? props.sharingTokens + .sort((a, b) => (new Date(a.expiresAt).getTime() - new Date(b.expiresAt).getTime())) + .map(token => { + const url = props.sharingURLsPrefix.includes('*') + ? `${props.sharingURLsPrefix.replace('*', props.collectionUuid)}/t=${token.apiToken}/_/` + : `${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${token.apiToken}/_/`; + const expDate = new Date(token.expiresAt); + const urlLabel = !!token.expiresAt + ? `Token ${token.apiToken.slice(0, 8)}... expiring at: ${expDate.toLocaleString()} (${moment(expDate).fromNow()})` + : `Token ${token.apiToken.slice(0, 8)}... with no expiration date`; - return - - - {urlLabel} - - - - - - props.onCopy('Sharing URL copied')}> - - - - - props.onDeleteSharingToken(token.uuid)}> - - - - - - }) - : No sharing URLs } + return + + + {urlLabel} + + + + + + props.onCopy('Sharing URL copied')}> + + + + + props.onDeleteSharingToken(token.uuid)}> + + + + + + }) + : No sharing URLs} ); diff --git a/src/views-components/sharing-dialog/visibility-level-select.tsx b/src/views-components/sharing-dialog/visibility-level-select.tsx index c869e739..4f12e3ea 100644 --- a/src/views-components/sharing-dialog/visibility-level-select.tsx +++ b/src/views-components/sharing-dialog/visibility-level-select.tsx @@ -13,20 +13,20 @@ import { SelectItem } from './select-item'; import { VisibilityLevel } from 'store/sharing-dialog/sharing-dialog-types'; -type VisibilityLevelSelectClasses = 'value'; +type VisibilityLevelSelectClasses = 'root'; const VisibilityLevelSelectStyles: StyleRulesCallback = theme => ({ - value: { + root: { marginLeft: theme.spacing.unit, } }); export const VisibilityLevelSelect = withStyles(VisibilityLevelSelectStyles)( - ({ classes, ...props }: { includePublic: boolean } & SelectProps & WithStyles) => + ({ classes, includePublic, ...props }: { includePublic: boolean } & SelectProps & WithStyles) =>