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

[stable29] Feat/5524 link preview add button to delete links in preview mode #5580

Merged
merged 1 commit into from
Mar 29, 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
64 changes: 64 additions & 0 deletions cypress/e2e/nodes/PreviewOptions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @copyright Copyright (c) 2022
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { initUserAndFiles, randUser } from '../../utils/index.js'

const user = randUser()

describe('Preview Options', function() {
before(function() {
initUserAndFiles(user, 'codeblock.md', 'empty.md')
})
beforeEach(function() {
cy.login(user)
cy.isolateTest({ sourceFile: 'empty.md' })
cy.openFile('empty.md')
cy.get('.entry-action__insert-link').click()
cy.get('li').get('[data-text-action-entry="insert-link-website"]').click()
cy.get('.input-field__input--trailing-icon').type('nextcloud.com')
cy.get('.input-field__trailing-button').click()
cy.get('.preview-options').click()
})

it('should render previewOptions correctly', function() {
cy.get('.action-button__text').contains('Remove link').should('be.visible')
cy.get('.action-radio__label').each(el => {
cy.wrap(el).invoke('text').should('match', /Text only|Show link preview/)
})
})

it('should toggle to Link Preview', function() {
cy.get('.preview').should('not.exist')
cy.get('.action-radio__label').each(el => {
cy.wrap(el).invoke('text').then(text => {
if (text === 'Show link preview') {
cy.wrap(el).click()
}
})
})
cy.get('.preview').should('be.visible')
})

it('should Remove link', function() {
cy.get('.paragraph-content').should('have.text', 'nextcloud.com')
cy.get('.action-button__text').contains('Remove link').click()
cy.get('.paragraph-content').should('not.have.text', 'nextcloud.com')
})
})
62 changes: 38 additions & 24 deletions src/components/Editor/PreviewOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,56 @@
-
-->
<template>
<NcActions data-text-preview-options="select"
@open="$emit('open')">
<template #icon>
<DotsVerticalIcon :size="20" />
</template>
<NcActionCaption :name="t('text', 'Preview options')" />
<NcActionRadio data-text-preview-option="text-only"
close-after-click
name="preview-option"
value="text-only"
:checked="value === 'text-only'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Text only') }}
</NcActionRadio>
<NcActionRadio data-text-preview-option="link-preview"
close-after-click
name="preview-option"
value="link-preview"
:checked="value === 'link-preview'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Show link preview') }}
</NcActionRadio>
</NcActions>
<div>
<NcActions data-text-preview-options="select"
class="preview-options"
@open="$emit('open')">
<template #icon>
<DotsVerticalIcon :size="20" />
</template>
<NcActionCaption :name="t('text', 'Preview options')" />
<NcActionRadio data-text-preview-option="text-only"
close-after-click
name="preview-option"
value="text-only"
:checked="value === 'text-only'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Text only') }}
</NcActionRadio>
<NcActionRadio data-text-preview-option="link-preview"
close-after-click
name="preview-option"
value="link-preview"
:checked="value === 'link-preview'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Show link preview') }}
</NcActionRadio>
<NcActionSeparator />
<NcActionButton @click="e => $emit('update:value', 'delete-preview')">
<template #icon>
<DeleteIcon :size="20" />
</template>
{{ t('text','Remove link') }}
</NcActionButton>
</NcActions>
</div>
</template>

<script>
import { NcActions, NcActionRadio, NcActionCaption } from '@nextcloud/vue'
import { NcActions, NcActionButton, NcActionRadio, NcActionCaption, NcActionSeparator } from '@nextcloud/vue'
import DotsVerticalIcon from 'vue-material-design-icons/DotsVertical.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'

export default {
name: 'PreviewOptions',
components: {
DotsVerticalIcon,
NcActions,
NcActionButton,
NcActionCaption,
NcActionRadio,
NcActionSeparator,
DeleteIcon,
},
props: {
value: {
Expand Down
12 changes: 9 additions & 3 deletions src/nodes/ParagraphView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PreviewOptions v-if="editor.isEditable && isSelected && canConvertToPreview"
:value.sync="value"
@open="editor.commands.hideLinkBubble()"
@update:value="convertToPreview" />
@update:value="changeViewMode" />
<NodeViewContent class="paragraph-content" />
</NodeViewWrapper>
</template>
Expand Down Expand Up @@ -74,8 +74,14 @@ export default {
this.editor.off('selectionUpdate', this.checkSelection)
},
methods: {
convertToPreview(...args) {
console.info(...args)
changeViewMode(value) {
if (value === 'delete-preview') {
this.deleteNode()
} else if (value === 'link-preview') {
this.convertToPreview()
}
},
convertToPreview() {
this.editor.chain()
.focus()
.setTextSelection(this.getPos() + 1)
Expand Down
12 changes: 9 additions & 3 deletions src/nodes/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<NodeViewContent style="display:none" />
<PreviewOptions v-if="editor.isEditable"
:value.sync="value"
@update:value="convertToParagraph" />
@update:value="changeViewMode" />
<NcReferenceList :text="node.attrs.href"
:limit="1"
:interactive="!extension.options.isEmbedded" />
Expand Down Expand Up @@ -56,8 +56,14 @@ export default {
}
},
methods: {
convertToParagraph(...args) {
console.info(...args)
changeViewMode(value) {
if (value === 'delete-preview') {
this.deleteNode()
} else if (value === 'text-only') {
this.convertToParagraph()
}
},
convertToParagraph() {
this.$editor.chain()
.focus()
.setTextSelection(this.getPos() + 1)
Expand Down
Loading