Skip to content

Commit

Permalink
fix: Get proper rich object for card actions
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl committed Dec 5, 2023
1 parent 2389eff commit b06b41f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
48 changes: 48 additions & 0 deletions cypress/e2e/cardFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,52 @@ describe('Card', function() {

})

describe('Card actions', () => {
beforeEach(function() {
cy.login(user)
useModal(false).then(() => {
cy.visit(`/apps/deck/#/board/${boardId}`)
})
})

it('Custom card actions', () => {
const myAction = {
label: 'Test action',
icon: 'icon-user',
callback(card) {
console.log('Called callback', card)
},
}
cy.spy(myAction, 'callback').as('myAction.callback')

cy.window().then(win => {
win.OCA.Deck.registerCardAction(myAction)
})

cy.get('.card:contains("Hello world")').should('be.visible').click()
cy.get('#app-sidebar-vue')
.find('.ProseMirror h1').contains('Hello world').should('be.visible')

cy.get('.app-sidebar-header .action-item__menutoggle').click()
cy.get('.v-popper__popper button:contains("Test action")').click()

cy.get('@myAction.callback')
.should('be.called')
.its('firstCall.args.0')
.as('args')

cy.url().then(url => {
const cardId = url.split('/').pop()
cy.get('@args').should('have.property', 'name', 'Hello world')
cy.get('@args').should('have.property', 'stackname', 'TestList')
cy.get('@args').should('have.property', 'boardname', 'MyTestBoard')
cy.get('@args').its('link').then((url) => {
expect(url.split('/').pop() === cardId).to.be.true
cy.visit(url)
cy.get('#app-sidebar-vue')
.find('.ProseMirror h1').contains('Hello world').should('be.visible')
})
})
})
})
})
10 changes: 0 additions & 10 deletions src/components/card/CardSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@

<script>
import { NcActionButton, NcAppSidebar, NcAppSidebarTab } from '@nextcloud/vue'
import { generateUrl } from '@nextcloud/router'
import { mapState, mapGetters } from 'vuex'
import CardSidebarTabDetails from './CardSidebarTabDetails.vue'
import CardSidebarTabAttachments from './CardSidebarTabAttachments.vue'
Expand Down Expand Up @@ -160,15 +159,6 @@ export default {
subtitleTooltip() {
return t('deck', 'Modified') + ': ' + this.formatDate(this.currentCard.lastModified) + '\n' + t('deck', 'Created') + ': ' + this.formatDate(this.currentCard.createdAt)
},
cardRichObject() {
return {
id: '' + this.currentCard.id,
name: this.currentCard.title,
boardname: this.currentBoard.title,
stackname: this.stackById(this.currentCard.stackId)?.title,
link: window.location.protocol + '//' + window.location.host + generateUrl('/apps/deck/') + `#/board/${this.currentBoard.id}/card/${this.currentCard.id}`,
}
},
cardDetailsInModal: {
get() {
return this.$store.getters.config('cardDetailsInModal')
Expand Down
14 changes: 13 additions & 1 deletion src/components/cards/CardMenuEntries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export default {
'isArchived',
'boards',
'cardActions',
'stackById',
'boardById',
]),
...mapState({
showArchived: state => state.showArchived,
Expand Down Expand Up @@ -165,7 +167,17 @@ export default {
},
boardId() {
return this.card?.boardId ? this.card.boardId : this.$route.params.id
return this.card?.boardId ? this.card.boardId : Number(this.$route.params.id)
},
cardRichObject() {
return {
id: '' + this.card.id,
name: this.card.title,
boardname: this.boardById(this.boardId)?.title,
stackname: this.stackById(this.card.stackId)?.title,
link: window.location.protocol + '//' + window.location.host + generateUrl('/apps/deck/') + `card/${this.card.id}`,
}
},
},
methods: {
Expand Down

0 comments on commit b06b41f

Please sign in to comment.