Skip to content

Commit

Permalink
Display estimated export size
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jun 4, 2022
1 parent 8873f4a commit b057cb6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
15 changes: 11 additions & 4 deletions src/components/ExportSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
</template>
{{ t('user_migration', 'Export') }}
</Button>
<span class="settings-hint">{{ t('user_migration', 'Your estimated export size is {estimatedSize}', { estimatedSize: this.estimatedSize }) }}</span>
<div v-if="startingExport" class="icon-loading section__loading" />
</div>

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -165,10 +167,11 @@ export default {
data() {
return {
modalOpened: false,
startingExport: false,
cancellingExport: false,
estimatedSize: null,
modalOpened: false,
selectedMigrators: [],
startingExport: false,
}
},
Expand Down Expand Up @@ -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)
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/migrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit b057cb6

Please sign in to comment.