Skip to content

Commit

Permalink
only render button when valid file type
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
  • Loading branch information
elzody committed Mar 1, 2024
1 parent 849f5ae commit fb1f738
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/file-actions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { FileAction, registerFileAction } from '@nextcloud/files'

Check failure on line 1 in src/file-actions.js

View workflow job for this annotation

GitHub Actions / NPM lint

"@nextcloud/files" is extraneous
import { showError, spawnDialog } from '@nextcloud/dialogs'
import { spawnDialog } from '@nextcloud/dialogs'
import FileActionImport from './modules/modals/FileActionImport.vue'

const icon = `<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24" viewBox="0 0 24 24">
<path d="M4,3H20A2,2 0 0,1 22,5V20A2,2 0 0,1 20,22H4A2,2 0 0,1 2,20V5A2,2 0 0,1 4,3M4,7V10H8V7H4M10,7V10H14V7H10M20,10V7H16V10H20M4,12V15H8V12H4M4,20H8V17H4V20M10,12V15H14V12H10M10,20H14V17H10V20M20,20V17H16V20H20M20,12H16V15H20V12Z"/>
</svg>
`

const validMimeTypes = [
'text/csv',
'text/html',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel',
]

const fileAction = new FileAction({
id: 'import-to-tables',
displayName: () => t('tables', 'Import into Tables'),
iconSvgInline: () => icon,

exec: async (file) => {
const validFormats = /(.csv$)|(.xlsx$)|(.xls$)|(.html$)/gi
const isValidFormat = validFormats.test(file.extension)

if (!isValidFormat) {
showError(t('tables', 'This file type cannot be imported to Tables'))
return null
enabled: (files) => {
for (const file of files) {

Check failure on line 23 in src/file-actions.js

View workflow job for this annotation

GitHub Actions / NPM lint

Invalid loop. Its body allows only one iteration
return file.type == 'file' && validMimeTypes.includes(file.mime)

Check failure on line 24 in src/file-actions.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected '===' and instead saw '=='
}
},

exec: async (file) => {
spawnDialog(FileActionImport, { t, file, })

Check warning on line 29 in src/file-actions.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected trailing comma

return null
},
})
Expand Down

0 comments on commit fb1f738

Please sign in to comment.