From b6dd6a90558dab02145f904181d4ef09b3abbd17 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 14 Oct 2024 16:27:43 +0200 Subject: [PATCH] fix(files_sharing): Add proper user facing messages on success 1. Use proper translated strings 2. Fix invalid use of translation message on API result 3. Log all errors Signed-off-by: Ferdinand Thiessen --- apps/files_sharing/src/mixins/SharesMixin.js | 44 +++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js index 994a0fe5cb319..a5ac86f2aa760 100644 --- a/apps/files_sharing/src/mixins/SharesMixin.js +++ b/apps/files_sharing/src/mixins/SharesMixin.js @@ -3,11 +3,11 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { getCurrentUser } from '@nextcloud/auth' +import { showError, showSuccess } from '@nextcloud/dialogs' import { emit } from '@nextcloud/event-bus' import { fetchNode } from '../services/WebdavClient.ts' -import { showError, showSuccess } from '@nextcloud/dialogs' -import { getCurrentUser } from '@nextcloud/auth' -// eslint-disable-next-line import/no-unresolved, n/no-missing-import + import PQueue from 'p-queue' import debounce from 'debounce' @@ -316,11 +316,17 @@ export default { // clear any previous errors this.$delete(this.errors, propertyNames[0]) - showSuccess(t('files_sharing', 'Share {propertyName} saved', { propertyName: propertyNames[0] })) - } catch ({ message }) { + showSuccess(this.updateSuccessMessage(propertyNames)) + } catch (error) { + logger.error('Could not update share', { error, share: this.share, propertyNames }) + + const { message } = error if (message && message !== '') { this.onSyncError(propertyNames[0], message) - showError(t('files_sharing', message)) + showError(message) + } else { + // We do not have information what happened, but we should still inform the user + showError(t('files_sharing', 'Could not update share')) } } finally { this.saving = false @@ -333,6 +339,32 @@ export default { console.debug('Updated local share', this.share) }, + /** + * @param {string[]} names Properties changed + */ + updateSuccessMessage(names) { + if (names.length !== 1) { + return t('files_sharing', 'Share saved') + } + + switch (names[0]) { + case 'expireDate': + return t('files_sharing', 'Share expire date saved') + case 'hideDownload': + return t('files_sharing', 'Share hide-password state saved') + case 'label': + return t('files_sharing', 'Share label saved') + case 'note': + return t('files_sharing', 'Share note for recipient saved') + case 'password': + return t('files_sharing', 'Share password saved') + case 'permissions': + return t('files_sharing', 'Share permissions saved') + default: + return t('files_sharing', 'Share saved') + } + }, + /** * Manage sync errors *