Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repair schema export and import #1321

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["tsconfig.json", "vendor-bin/openapi-extractor/composer.json", "vendor-bin/openapi-extractor/composer.lock"]
path = ["tsconfig.json", "vendor-bin/openapi-extractor/composer.json", "cypress/e2e/ToDo list.json", "vendor-bin/openapi-extractor/composer.lock"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/ToDo list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"ToDo list","emoji":"\u2705","columns":[{"id":491,"tableId":132,"title":"Task","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"line","mandatory":true,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":492,"tableId":132,"title":"Description","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"Title or short description","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":493,"tableId":132,"title":"Target","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"Date, time or whatever","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":494,"tableId":132,"title":"Progress","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"number","subtype":"progress","mandatory":false,"description":"","numberDefault":0,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":495,"tableId":132,"title":"Comments","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"text","subtype":"rich","mandatory":false,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false},{"id":496,"tableId":132,"title":"Proofed","createdBy":"admin","createdByDisplayName":"admin","createdAt":"2024-08-26 12:58:43","lastEditBy":"admin","lastEditByDisplayName":"admin","lastEditAt":"2024-08-26 12:58:43","type":"selection","subtype":"check","mandatory":false,"description":"","numberDefault":null,"numberMin":null,"numberMax":null,"numberDecimals":0,"numberPrefix":"","numberSuffix":"","textDefault":"","textAllowedPattern":"","textMaxLength":-1,"selectionOptions":[],"selectionDefault":"","datetimeDefault":"","usergroupDefault":[],"usergroupMultipleItems":false,"usergroupSelectUsers":false,"usergroupSelectGroups":false,"showUserStatus":false}],"views":[],"description":"","tablesVersion":"0.8.0-beta.2"}
59 changes: 59 additions & 0 deletions cypress/e2e/tables-import-export-scheme.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
let localUser

const omitSubFields = (array, fields) => {
return array.map(
(item) => Object.keys(item).filter(
filterKey => !fields.includes(filterKey)).reduce(
(obj, key) => {
obj[key] = item[key]
return obj
}, {}),
)
}

describe('Import Export Scheme', () => {

before(function() {
cy.createRandomUser().then(user => {
localUser = user
})
})

beforeEach(function() {
cy.login(localUser)
cy.visit('apps/tables')
})

it('Import table from scheme', () => {
cy.get('.icon-loading').should('not.exist')
cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })
cy.get('p').contains('Import Scheme').click({ force: true })
cy.contains('button', 'Create table').scrollIntoView().click()
cy.get('input[type=file].hidden-visually').selectFile('./cypress/e2e/ToDo list.json', { force: true })
cy.get('button').contains('Import').click()
cy.get('.app-navigation-toggle-wrapper').should('be.visible').click()
cy.get('.app-navigation__list').contains('ToDo list').should('exist')
})

it('Export scheme to json', () => {
const columnFieldsToIgnore = ['id', 'tableId', 'createdAt', 'lastEditAt', 'createdBy', 'createdByDisplayName', 'lastEditBy', 'lastEditByDisplayName']
cy.get('.app-navigation-toggle-wrapper').should('be.visible').click()
cy.get('.app-navigation__list').contains('ToDo list').click()
cy.get('.row.first-row').should('be.visible')
cy.get('.app-navigation__list').contains('ToDo list').trigger('mouseover')
cy.get('.app-navigation-entry__actions').last('').click()
cy.get('.action-button__text').contains('Export').click()
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile('./cypress/e2e/ToDo list.json').then(content => {
cy.readFile(`${downloadsFolder}/ToDo list.json`).then(expectedContent => {
expectedContent.columns = omitSubFields(expectedContent.columns, columnFieldsToIgnore)
content.columns = omitSubFields(content.columns, columnFieldsToIgnore)
expect(JSON.stringify(expectedContent)).to.eq(JSON.stringify(content))
})
})
})
})
2 changes: 1 addition & 1 deletion lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti

$column['datetimeDefault'],

$column['usergroupDefault'],
$column['usergroupDefault'][0] ?? '',
$column['usergroupMultipleItems'],
$column['usergroupSelectUsers'],
$column['usergroupSelectGroups'],
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/modules/modals/CreateTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ export default {
this.$emit('close')
},
async submit() {
if (this.templateChoice === 'scheme') {
emit('tables:modal:scheme', this.title)
this.actionCancel()
return
}
if (this.title === '') {
if (this.templateChoice === 'scheme') {
emit('tables:modal:scheme', {})
this.actionCancel()
return
}
showError(t('tables', 'Cannot create new table. Title is missing.'))
this.errorTitle = true
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/modules/modals/ImportScheme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class="hidden-visually"
:accept="mimeTypes.join(',')"
@change="onUploadFileInputChange">
<span v-if="selectedUploadFile">{{ selectedUploadFile?.name }}</span>
<div class="row">
<div class="fix-col-4 end">
<NcButton :aria-label="t('tables', 'Import')" type="primary" @click="actionSubmit">
Expand Down Expand Up @@ -50,6 +51,10 @@ export default {
type: Boolean,
default: false,
},
title: {
type: String,
default: '',
},
},
data() {
return {
Expand Down Expand Up @@ -77,6 +82,9 @@ export default {
reader.readAsText(this.selectedUploadFile, 'UTF-8')
reader.onload = (evt) => {
const json = JSON.parse(evt.target.result)
if (this.title !== '') {
json.title = this.title
}
axios.post(generateOcsUrl('/apps/tables/api/2/tables/scheme'), json).then(async res => {
if (res.status === 200) {
await this.$store.dispatch('loadTablesFromBE')
Expand Down
4 changes: 3 additions & 1 deletion src/modules/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

<ImportScheme
:show-modal="showImportScheme"
:title="importSchemeTitle"
@close="showImportScheme = false" />
<CreateContext :show-modal="showModalCreateContext" @close="showModalCreateContext = false" />
<EditContext :context-id="editContext" :show-modal="editContext !== null" @close="editContext = null" />
Expand Down Expand Up @@ -108,6 +109,7 @@ export default {
showModalCreateContext: false,
importToElement: null,
showImportScheme: false,
importSchemeTitle: '',
createViewTableId: null, // if null, no modal open
tableToDelete: null,
viewToDelete: null,
Expand Down Expand Up @@ -152,7 +154,7 @@ export default {

// misc
subscribe('tables:modal:import', element => { this.importToElement = element })
subscribe('tables:modal:scheme', () => { this.showImportScheme = true })
subscribe('tables:modal:scheme', title => { this.importSchemeTitle = title; this.showImportScheme = true })

// context
subscribe('tables:context:create', () => { this.showModalCreateContext = true })
Expand Down
Loading