66import type { AxiosError } from '@nextcloud/axios'
77import type { Node } from '@nextcloud/files'
88
9+ import { FileAction } from '@nextcloud/files'
910import { showWarning } from '@nextcloud/dialogs'
1011import { translate as t } from '@nextcloud/l10n'
1112import AlertSvg from '@mdi/svg/svg/alert-circle.svg?raw'
@@ -15,7 +16,6 @@ import '../css/fileEntryStatus.scss'
1516import { getStatus , type StorageConfig } from '../services/externalStorage'
1617import { isMissingAuthConfig , STORAGE_STATUS } from '../utils/credentialsUtils'
1718import { isNodeExternalStorage } from '../utils/externalStorageUtils'
18- import { FileAction } from '@nextcloud/files'
1919
2020export const action = new FileAction ( {
2121 id : 'check-external-storage' ,
@@ -34,45 +34,51 @@ export const action = new FileAction({
3434 * @param node The node to render inline
3535 */
3636 async renderInline ( node : Node ) {
37+ const span = document . createElement ( 'span' )
38+ span . className = 'files-list__row-status'
39+ span . innerHTML = t ( 'files_external' , 'Checking storage …' )
40+
3741 let config = null as unknown as StorageConfig
38- try {
39- const response = await getStatus ( node . attributes . id , node . attributes . scope === 'system' )
40- config = response . data
41- Vue . set ( node . attributes , 'config' , config )
42+ getStatus ( node . attributes . id , node . attributes . scope === 'system' )
43+ . then ( response => {
44+
45+ config = response . data
46+ Vue . set ( node . attributes , 'config' , config )
47+
48+ if ( config . status !== STORAGE_STATUS . SUCCESS ) {
49+ throw new Error ( config ?. statusMessage || t ( 'files_external' , 'There was an error with this external storage.' ) )
50+ }
4251
43- if ( config . status !== STORAGE_STATUS . SUCCESS ) {
44- throw new Error ( config ?. statusMessage || t ( 'files_external' , 'There was an error with this external storage.' ) )
45- }
52+ span . remove ( )
53+ } )
54+ . catch ( error => {
55+ // If axios failed or if something else prevented
56+ // us from getting the config
57+ if ( ( error as AxiosError ) . response && ! config ) {
58+ showWarning ( t ( 'files_external' , 'We were unable to check the external storage {basename}' , {
59+ basename : node . basename ,
60+ } ) )
61+ }
4662
47- return null
48- } catch ( error ) {
49- // If axios failed or if something else prevented
50- // us from getting the config
51- if ( ( error as AxiosError ) . response && ! config ) {
52- showWarning ( t ( 'files_external' , 'We were unable to check the external storage {basename}' , {
53- basename : node . basename ,
54- } ) )
55- return null
56- }
63+ // Reset inline status
64+ span . innerHTML = ''
5765
58- // Checking if we really have an error
59- const isWarning = isMissingAuthConfig ( config )
60- const overlay = document . createElement ( 'span' )
61- overlay . classList . add ( `files-list__row-status--${ isWarning ? 'warning' : 'error' } ` )
66+ // Checking if we really have an error
67+ const isWarning = ! config ? false : isMissingAuthConfig ( config )
68+ const overlay = document . createElement ( 'span' )
69+ overlay . classList . add ( `files-list__row-status--${ isWarning ? 'warning' : 'error' } ` )
6270
63- const span = document . createElement ( 'span' )
64- span . className = 'files-list__row-status'
71+ // Only show an icon for errors, warning like missing credentials
72+ // have a dedicated inline action button
73+ if ( ! isWarning ) {
74+ span . innerHTML = AlertSvg
75+ span . title = ( error as Error ) . message
76+ }
6577
66- // Only show an icon for errors, warning like missing credentials
67- // have a dedicated inline action button
68- if ( ! isWarning ) {
69- span . innerHTML = AlertSvg
70- span . title = ( error as Error ) . message
71- }
78+ span . prepend ( overlay )
79+ } )
7280
73- span . prepend ( overlay )
74- return span
75- }
81+ return span
7682 } ,
7783
7884 order : 10 ,
0 commit comments