From b057cb6843b9852b3d88693c9bd701b7cc82d27b Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Sat, 4 Jun 2022 00:39:50 +0000 Subject: [PATCH] Display estimated export size Signed-off-by: Christopher Ng --- src/components/ExportSection.vue | 15 +++++++++++---- src/services/migrationService.js | 2 +- src/shared/utils.js | 30 +++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/components/ExportSection.vue b/src/components/ExportSection.vue index 7ade5678..41d7cc18 100644 --- a/src/components/ExportSection.vue +++ b/src/components/ExportSection.vue @@ -81,6 +81,7 @@ {{ t('user_migration', 'Export') }} + {{ t('user_migration', 'Your estimated export size is {estimatedSize}', { estimatedSize: this.estimatedSize }) }}
@@ -130,6 +131,7 @@ import PackageDown from 'vue-material-design-icons/PackageDown' import { queueExportJob, cancelJob, checkExportability } from '../services/migrationService.js' import { handleError, handleWarning } from '../shared/utils.js' +import { TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs' export default { name: 'ExportSection', @@ -165,10 +167,11 @@ export default { data() { return { - modalOpened: false, - startingExport: false, cancellingExport: false, + estimatedSize: null, + modalOpened: false, selectedMigrators: [], + startingExport: false, } }, @@ -201,9 +204,13 @@ export default { immediate: false, async handler(migrators, oldMigrators) { try { - await checkExportability(migrators) + const { size, units, warning } = await checkExportability(migrators) + if (warning) { + handleWarning(warning, { timeout: TOAST_PERMANENT_TIMEOUT }) + } + this.estimatedSize = `${size} ${units}` } catch (error) { - handleWarning(error) + handleError(error) } }, }, diff --git a/src/services/migrationService.js b/src/services/migrationService.js index 14aaa612..01b6d67d 100644 --- a/src/services/migrationService.js +++ b/src/services/migrationService.js @@ -66,7 +66,7 @@ export const cancelJob = async () => { * @return {object} */ export const checkExportability = async (migrators) => { - const url = generateOcsUrl('/apps/{appId}/api/v{apiVersion}/exportable', { appId: APP_ID, apiVersion: API_VERSION }) + formatQueryParamArray('migrators', migrators) + const url = generateOcsUrl('/apps/{appId}/api/v{apiVersion}/export', { appId: APP_ID, apiVersion: API_VERSION }) + formatQueryParamArray('migrators', migrators) const response = await axios.get(url) return response.data.ocs?.data diff --git a/src/shared/utils.js b/src/shared/utils.js index c916861f..debb3e72 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -25,25 +25,37 @@ import { showWarning, showError } from '@nextcloud/dialogs' import logger from './logger.js' /** - * @param {AxiosError} error Error object + * @param {string|AxiosError} warning Warning + * @param {import('@nextcloud/dialogs/dist/toast').ToastOptions} toastOptions Toast options * * @return {void} */ -export const handleWarning = (error) => { - const warningMessage = error.response.data.ocs?.meta?.message || 'Unknown warning' - logger.warn(warningMessage, { error }) - showWarning(warningMessage) +export const handleWarning = (warning, toastOptions = {}) => { + let warningMessage = 'Unknown warning' + if (typeof warning === 'string') { + warningMessage = warning || 'Unknown warning' + } else { + warningMessage = warning.response.data.ocs?.meta?.message || 'Unknown warning' + } + logger.warn(warningMessage, { error: warning }) + showWarning(warningMessage, toastOptions) } /** - * @param {AxiosError} error Error object + * @param {string|AxiosError} error Error + * @param {import('@nextcloud/dialogs/dist/toast').ToastOptions} toastOptions Toast options * * @return {void} */ -export const handleError = (error) => { - const errorMessage = error.response.data.ocs?.meta?.message || 'Unknown error' +export const handleError = (error, toastOptions = {}) => { + let errorMessage = 'Unknown error' + if (typeof error === 'string') { + errorMessage = error || 'Unknown error' + } else { + errorMessage = error.response.data.ocs?.meta?.message || 'Unknown error' + } logger.error(errorMessage, { error }) - showError(errorMessage) + showError(errorMessage, toastOptions) } /**