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

feat(UploadPicker): Allow to disable the "new"-menu #1373

Merged
merged 1 commit into from
Sep 5, 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
47 changes: 43 additions & 4 deletions cypress/components/UploadPicker/new-menu.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,51 @@ describe('UploadPicker: "new"-menu', () => {
handler() {},
} as Entry

before(() => {
cy.spy(entry, 'handler')
addNewFileMenuEntry(entry)
})
before(() => addNewFileMenuEntry(entry))
beforeEach(() => cy.spy(entry, 'handler'))
afterEach(() => resetDocument())

it('With "noMenu" prop no menu is shown', () => {
// 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', 'Upload')
.should('be.visible')
// Directly trigger upload
.and('have.attr', 'data-cy-upload-picker-menu-entry', 'upload-file')
.click()

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

it('With "noMenu" prop and allowed folder-upload only the upload menu is shown', () => {
// Mount picker
cy.mount(UploadPicker, { propsData: { ...propsData, noMenu: true, allowFolders: 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', 'Upload')
.should('be.visible')
// Directly no trigger
.and('not.have.attr', 'data-cy-upload-picker-menu-entry', 'upload-file')
// click should open the menu
.click()

cy.get('[role="menu"]')
.should('be.visible')
.get('[role="menuitem"]')
// only two (!) entries: uploader folder + upload files
.should('have.length', 2)
// Not the custom entry
cy.get('[data-cy-upload-picker-menu-entry="empty-file"]').should('not.exist')
})

it('Open the New File Menu', () => {
// Mount picker
cy.mount(UploadPicker, { propsData })
Expand Down
3 changes: 3 additions & 0 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ msgstr[1] ""
msgid "Unknown size"
msgstr ""

msgid "Upload"
msgstr ""

msgid "Upload files"
msgstr ""

Expand Down
50 changes: 33 additions & 17 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="upload-picker"
data-cy-upload-picker>
<!-- New button -->
<NcButton v-if="newFileMenuEntries.length === 0 && !canUploadFolders"
<NcButton v-if="(noMenu || newFileMenuEntries.length === 0) && !canUploadFolders"
:disabled="disabled"
data-cy-upload-picker-add
data-cy-upload-picker-menu-entry="upload-file"
Expand All @@ -21,8 +21,8 @@
{{ buttonName }}
</NcButton>
<NcActions v-else
:aria-label="buttonLabel"
:menu-name="buttonName"
:menu-title="t('New')"
type="secondary">
<template #icon>
<IconPlus :size="20" />
Expand Down Expand Up @@ -51,21 +51,23 @@
</NcActionButton>

<!-- App defined upload actions -->
<NcActionButton v-for="entry in menuEntriesUpload"
:key="entry.id"
:icon="entry.iconClass"
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
{{ entry.displayName }}
</NcActionButton>
<template v-if="!noMenu">
<NcActionButton v-for="entry in menuEntriesUpload"
:key="entry.id"
:icon="entry.iconClass"
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
{{ entry.displayName }}
</NcActionButton>
</template>

<!-- 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 +85,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 +199,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 Expand Up @@ -293,12 +305,16 @@ export default Vue.extend({
return this.uploadManager.info?.status === Status.PAUSED
},

buttonLabel() {
return this.noMenu ? t('Upload') : t('New')
},

// Hide the button text if we're uploading
buttonName() {
if (this.isUploading) {
return undefined
}
return t('New')
return this.buttonLabel
},
},

Expand Down
Loading