Skip to content

Commit

Permalink
feat(UploadPicker): Allow to disable the "new"-menu
Browse files Browse the repository at this point in the history
This allows to also use the upload picker without the menu for just uploading files / folders.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Sep 4, 2024
1 parent 1446adc commit 8073221
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
17 changes: 17 additions & 0 deletions cypress/components/UploadPicker/UploadPicker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ describe('NewFileMenu handling', () => {
})
})

it('Does not show menu with "noMenu" prop', () => {
// Mount picker
cy.mount(UploadPicker, { propsData: { ...propsData, noMenu: true } })

// Check and init aliases
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
cy.get('[data-cy-upload-picker]')
.contains('button', 'New')
.should('be.visible')
.and('have.attr', 'data-cy-upload-picker-menu-entry', 'upload-file')
.click()

cy.get('[role="menu"]')
.should('not.exist')
})

it('Changes the context', () => {
// Mount picker
cy.mount(UploadPicker, { propsData })
Expand Down
18 changes: 14 additions & 4 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
{{ buttonName }}
</NcButton>
<NcActions v-else
:aria-label="t('New')"
:menu-name="buttonName"
:menu-title="t('New')"
type="secondary">
<template #icon>
<IconPlus :size="20" />
Expand Down Expand Up @@ -51,7 +51,7 @@
</NcActionButton>

<!-- App defined upload actions -->
<NcActionButton v-for="entry in menuEntriesUpload"
<NcActionButton v-for="!noMenu && entry in menuEntriesUpload"
:key="entry.id"
:icon="entry.iconClass"
:close-after-click="true"
Expand All @@ -65,7 +65,7 @@
</NcActionButton>

<!-- Custom new file entries -->
<template v-if="menuEntriesNew.length > 0">
<template v-if="!noMenu && menuEntriesNew.length > 0">
<NcActionSeparator />
<NcActionCaption :name="t('Create new')" />
<NcActionButton v-for="entry in menuEntriesNew"
Expand All @@ -83,7 +83,7 @@
</template>

<!-- other file entries -->
<template v-if="menuEntriesOther.length > 0">
<template v-if="!noMenu && menuEntriesOther.length > 0">
<NcActionSeparator />
<NcActionButton v-for="entry in menuEntriesOther"
:key="entry.id"
Expand Down Expand Up @@ -197,6 +197,16 @@ export default Vue.extend({
type: Boolean,
default: false,
},
/**
* Allow to disable the "new"-menu for this UploadPicker instance
* @default false
*/
noMenu: {
type: Boolean,
default: false,
},
destination: {
type: Folder,
default: undefined,
Expand Down

0 comments on commit 8073221

Please sign in to comment.