Skip to content

Commit

Permalink
fix(files_sharing): Add proper user facing messages on success
Browse files Browse the repository at this point in the history
1. Use proper translated strings
2. Fix invalid use of translation message on API result
3. Log all errors

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Oct 14, 2024
1 parent ef532fe commit b6dd6a9
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand All @@ -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':

Check failure on line 351 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
return t('files_sharing', 'Share expire date saved')

Check failure on line 352 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
case 'hideDownload':

Check failure on line 353 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
return t('files_sharing', 'Share hide-password state saved')

Check failure on line 354 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
case 'label':

Check failure on line 355 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
return t('files_sharing', 'Share label saved')

Check failure on line 356 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
case 'note':

Check failure on line 357 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
return t('files_sharing', 'Share note for recipient saved')

Check failure on line 358 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
case 'password':

Check failure on line 359 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
return t('files_sharing', 'Share password saved')

Check failure on line 360 in apps/files_sharing/src/mixins/SharesMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
case 'permissions':
return t('files_sharing', 'Share permissions saved')
default:
return t('files_sharing', 'Share saved')
}
},

/**
* Manage sync errors
*
Expand Down

0 comments on commit b6dd6a9

Please sign in to comment.