From 6e43669535d41ef473b8c415c7aeb5ba99d76724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 19 Jan 2024 17:39:45 +0100 Subject: [PATCH 1/4] feat: Use simple input field instead of multiselect for plain URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../sidebar/sections/SidebarIntegration.vue | 22 +----- .../partials/rowTypePartials/TextLinkForm.vue | 78 +++++++++++++++++-- src/shared/mixins/copyToClipboard.js | 30 +++++++ 3 files changed, 107 insertions(+), 23 deletions(-) create mode 100644 src/shared/mixins/copyToClipboard.js diff --git a/src/modules/sidebar/sections/SidebarIntegration.vue b/src/modules/sidebar/sections/SidebarIntegration.vue index 60d09644b..387c4a473 100644 --- a/src/modules/sidebar/sections/SidebarIntegration.vue +++ b/src/modules/sidebar/sections/SidebarIntegration.vue @@ -48,9 +48,10 @@ import { mapGetters, mapState } from 'vuex' import { generateUrl } from '@nextcloud/router' import permissionsMixin from '../../../shared/components/ncTable/mixins/permissionsMixin.js' +import copyToClipboard from '../../../shared/mixins/copyToClipboard.js' + import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js' import ContentCopy from 'vue-material-design-icons/ContentCopy.vue' -import { showError, showSuccess } from '@nextcloud/dialogs' export default { components: { @@ -58,7 +59,7 @@ export default { ContentCopy, }, - mixins: [permissionsMixin], + mixins: [permissionsMixin, copyToClipboard], data() { return { @@ -80,22 +81,7 @@ export default { }, methods: { copyUrl() { - if (navigator?.clipboard) { - navigator.clipboard.writeText(this.apiEndpointUrl).then(function() { - showSuccess(t('files', 'Integration URL copied to clipboard')) - }, function(err) { - showError(t('files', 'Clipboard is not available')) - console.error('Async: Could not copy text: ', err) - }) - } else { - try { - document.querySelector('input#urlTextField').select() - document.execCommand('copy') - showSuccess(t('files', 'Integration URL copied to clipboard')) - } catch (e) { - showError(t('files', 'Clipboard is not available')) - } - } + this.copyToClipboard(this.apiEndpointUrl, false) }, }, } diff --git a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue index a5284cfcb..ecd1df0c3 100644 --- a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue +++ b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue @@ -10,8 +10,9 @@ {{ t('tables', 'You can not insert any links in this field. Please configure at least one link provider in the column configuration.') }} -
- + + + + + + + +
+ + diff --git a/src/shared/mixins/copyToClipboard.js b/src/shared/mixins/copyToClipboard.js new file mode 100644 index 000000000..41e129b6e --- /dev/null +++ b/src/shared/mixins/copyToClipboard.js @@ -0,0 +1,30 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { showError, showSuccess } from '@nextcloud/dialogs' + +export default { + methods: { + async copyToClipboard(content, silent = true) { + try { + if (navigator?.clipboard) { + await navigator.clipboard.writeText(content) + } else { + throw new Error('Clipboard is not available') + } + + if (!silent) { + showSuccess(t('files', 'Copied to clipboard.')) + } + return true + } catch (e) { + console.error('Error copying to clipboard', e) + if (!silent) { + showError(t('files', 'Clipboard is not available')) + } + } + }, + }, +} From f5eb414bc326a5349e222d9b17357b55ff3830fa Mon Sep 17 00:00:00 2001 From: Cleopatra Enjeck M Date: Sun, 21 Jan 2024 19:56:30 +0100 Subject: [PATCH 2/4] fix(test): modify columm-text-link test Signed-off-by: Cleopatra Enjeck M --- cypress/e2e/column-text-link.cy.js | 6 ++---- cypress/support/commands.js | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/column-text-link.cy.js b/cypress/e2e/column-text-link.cy.js index c3022f3f8..5d11f9e02 100644 --- a/cypress/e2e/column-text-link.cy.js +++ b/cypress/e2e/column-text-link.cy.js @@ -37,8 +37,7 @@ describe('Test column text-link', () => { cy.loadTable('Test text-link') cy.get('.NcTable').contains('Create row').click({ force: true }) - cy.get('.modal__content .slot input').first().type('https://nextcloud.com').tick(500) - cy.get('.icon-label-container .labels').contains('https://nextcloud.com').click() + cy.get('.modal__content .slot input').first().type('https://nextcloud.com') cy.intercept({ method: 'GET', url: '**/search/providers/files/*' }).as('filesResults') cy.get('.modal__content .slot input').eq(1).type('pdf').tick(500) @@ -58,8 +57,7 @@ describe('Test column text-link', () => { cy.loadTable('Test text-link') cy.get('.NcTable tr td button').click({ force: true }) - cy.get('.modal__content .slot input').first().clear().type('https://github.com').tick(500) - cy.get('[data-cy*="github"]').click() + cy.get('.modal__content .slot input').first().clear().type('https://github.com') cy.get('.modal__content .slot input').eq(1).type('photo-test').tick(500) cy.get('[data-cy*="photo-test"]').first().click() diff --git a/cypress/support/commands.js b/cypress/support/commands.js index a6cee5b23..eb67e7048 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -156,7 +156,9 @@ Cypress.Commands.add('createTextLinkColumn', (title, ressourceProvider, isFirstC cy.get('.typeSelection span').contains('Url', { matchCase: false }).click() cy.get('.typeSelection span').contains('Files').click() // TODO is the contacts search provider deactivated by default beginning with nc28 - // cy.get('.typeSelection span label').contains('Contacts').click() + if (['stable27'].includes(Cypress.env('ncVersion'))) { + cy.get('.typeSelection span').contains('Contacts').click() + } ressourceProvider.forEach(provider => cy.get('.typeSelection span').contains(provider, { matchCase: false }).click(), From cd41c6b777a46dcd2199e752195cf0abfc0215be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 30 Aug 2024 08:27:18 +0200 Subject: [PATCH 3/4] fix: Simplify selected option display to avoid sizing issues with NcSelect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../partials/rowTypePartials/TextLinkForm.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue index ecd1df0c3..bd34d2b6c 100644 --- a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue +++ b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue @@ -23,7 +23,7 @@ @@ -262,10 +262,19 @@ export default { }, } - From ef6ea7eeb88a2523a4285cb7409d0e1fa2c23965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 30 Aug 2024 08:34:11 +0200 Subject: [PATCH 4/4] fix: Only show url result if a valid URL is provided MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../partials/rowTypePartials/TextLinkForm.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue index bd34d2b6c..86b7a786d 100644 --- a/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue +++ b/src/shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue @@ -196,7 +196,9 @@ export default { this.removeResultsByProviderId(providerId) if (providerId === 'url') { - this.addUrlResult(term) + if (this.isValidUrl(term)) { + this.addUrlResult(term) + } this.setProviderLoading(providerId, false) return } @@ -227,6 +229,14 @@ export default { this.setProviderLoading(providerId, false) }, + isValidUrl(string) { + try { + return new URL(string) + } catch (err) { + return false + } + }, + addUrlResult(term) { this.results.push({ title: term,