Skip to content

Commit

Permalink
feat: implement direct file upload
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Feb 23, 2024
1 parent c86aeb4 commit 207c0a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cypress/e2e/tables-import.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Import csv', () => {
cy.visit('apps/tables')
})

it('Import csv', () => {
it('Import csv from Files', () => {
cy.uploadFile('test-import.csv', 'text/csv')
cy.loadTable('Tutorial')
cy.clickOnTableThreeDotMenu('Import')
Expand All @@ -25,11 +25,11 @@ describe('Import csv', () => {
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '0')
cy.get('[data-cy="importResultRowsInserted"]').should('contain.text', '3')
cy.get('[data-cy="importResultParsingErrors"]').should('contain.text', '0')
cy.get('[data-cy="importResultRowErrors"]').should('contain.text', '0')
cy.get('[data-cy="importResultParsingErrors"]').should('not.exist')
cy.get('[data-cy="importResultRowErrors"]').should('not.exist')
})

it('Import csv with upload file button', () => {
it('Import csv from device', () => {
cy.loadTable('Tutorial')
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Upload from device').click()
Expand All @@ -39,8 +39,8 @@ describe('Import csv', () => {
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '0')
cy.get('[data-cy="importResultRowsInserted"]').should('contain.text', '3')
cy.get('[data-cy="importResultParsingErrors"]').should('contain.text', '0')
cy.get('[data-cy="importResultRowErrors"]').should('contain.text', '0')
cy.get('[data-cy="importResultParsingErrors"]').should('not.exist')
cy.get('[data-cy="importResultRowErrors"]').should('not.exist')
})

})
3 changes: 1 addition & 2 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi
} else {
$error = true;
}
}
elseif (\file_exists($path)) {
} elseif (\file_exists($path)) {
$spreadsheet = IOFactory::load($path);
$this->loop($spreadsheet->getActiveSheet());
} else {
Expand Down
11 changes: 9 additions & 2 deletions src/modules/modals/Import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<p class="span">
{{ t('tables', 'Supported formats: xlsx, xls, csv, html, xml') }}
<br>
{{ t('tables', 'The first row if the file must contain column headings.') }}
{{ t('tables', 'First row of the file must contain column headings.') }}
</p>
</div>
</RowFormWrapper>
Expand Down Expand Up @@ -224,7 +224,14 @@ export default {
return this.canCreateMissingColumns && this.createMissingColumns
},
importFileName() {
return this.selectedUploadFile ? this.selectedUploadFile.name : this.path
const fileName = this.selectedUploadFile ? this.selectedUploadFile.name : this.path
if (fileName.length > 30) {
const extension = fileName.split('.').pop()
return fileName.substring(0, 30 - extension.length - 3) + '...' + extension
}
return fileName
},
},
watch: {
Expand Down

0 comments on commit 207c0a8

Please sign in to comment.