Skip to content

Commit

Permalink
feat: create new table from import
Browse files Browse the repository at this point in the history
  • Loading branch information
luka-nextcloud committed Mar 8, 2024
1 parent 0333a1f commit cdb003c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
24 changes: 23 additions & 1 deletion cypress/e2e/tables-table.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,35 @@ describe('Manage a table', () => {
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('to do list')
cy.contains('button', 'Create table').click()
cy.contains('button', 'Create table').scrollIntoView().click()

cy.contains('button', 'Create row').should('be.visible')
cy.contains('h1', 'to do list').should('be.visible')
cy.contains('table th', 'Task').should('exist')
})

it('Create with import', () => {
cy.uploadFile('test-import.csv', 'text/csv')
cy.contains('.app-menu-entry--label', 'Tables').click()
cy.contains('button', 'Create new table').click()
cy.get('.tile').contains('Import').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('import list')
cy.contains('button', 'Create table').scrollIntoView().click()
cy.contains('h2', 'Import').should('be.visible')

cy.get('.modal__content button').contains('Select a file').click()
cy.get('.file-picker__files').contains('test-import').click()
cy.get('.file-picker button span').contains('Choose test-import.csv').click()
cy.get('.modal__content button').contains('Import').click()
cy.get('[data-cy="importResultColumnsFound"]').should('contain.text', '4')
cy.get('[data-cy="importResultColumnsMatch"]').should('contain.text', '0')
cy.get('[data-cy="importResultColumnsCreated"]').should('contain.text', '4')
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')
})

it('Update title', () => {
cy.get('.app-navigation__list').contains('to do list').click({ force: true })
cy.get('[data-cy="customTableAction"] button').click()
Expand Down
16 changes: 15 additions & 1 deletion src/modules/modals/CreateTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
:tabbable="true"
@set-template="setTemplate('custom')" />
</div>
<div class="col-2 block space-R space-B">
<NcTile
:title="t('tables', '📄 Import table')"
:body="t('tables', 'Import table from file.')"
:active="templateChoice === 'import'"
:tabbable="true"
@set-template="setTemplate('import')" />
</div>
<div v-for="template in templates" :key="template.name" class="col-2 block space-R space-B">
<NcTile
:title="template.icon + ' ' + template.title"
Expand Down Expand Up @@ -64,6 +72,7 @@ import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import NcTile from '../../shared/components/ncTile/NcTile.vue'
import displayError from '../../shared/utils/displayError.js'
import { emit } from '@nextcloud/event-bus'
export default {
name: 'CreateTable',
Expand Down Expand Up @@ -119,14 +128,16 @@ export default {
if (!this.customIconChosen) {
if (name === 'custom') {
this.icon = '🔧'
} else if (name === 'import') {
this.icon = '📄'
} else {
const templateObject = this.templates?.find(item => item.name === name) || ''
this.icon = templateObject?.icon
}
}
if (!this.customTitleChosen) {
if (name === 'custom') {
if (name === 'custom' || name === 'import') {
this.title = ''
} else {
const templateObject = this.templates?.find(item => item.name === name) || ''
Expand All @@ -150,6 +161,9 @@ export default {
const newTableId = await this.sendNewTableToBE(this.templateChoice)
if (newTableId) {
await this.$router.push('/table/' + newTableId)
if (this.templateChoice === 'import') {
emit('tables:modal:import', { element: { tableId: newTableId, id: newTableId }, isView: false })
}
this.actionCancel()
}
}
Expand Down

0 comments on commit cdb003c

Please sign in to comment.