Skip to content

Commit c6dc87d

Browse files
committed
Add context support for newFileMenuEntries
Signed-off-by: John Molakvoæ <[email protected]>
1 parent eb63cd2 commit c6dc87d

6 files changed

Lines changed: 120 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ temp/
226226
# End of https://www.gitignore.io/api/node,macos,intellij+all
227227

228228
cypress/videos
229+
cypress/screenshots

lib/components/ActionIcon.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default {
2121
2222
methods: {
2323
async sanitizeSVG() {
24+
if (!this.svg) {
25+
return
26+
}
2427
this.cleanSvg = await sanitizeSVG(this.svg)
2528
},
2629
},

lib/components/UploadPicker.cy.ts

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,98 @@
11
// dist file might not be built when running eslint only
2-
// eslint-disable-next-line import/no-unresolved,node/no-missing-import
2+
// eslint-disable-next-line import/no-unresolved,n/no-missing-import
3+
import { addNewFileMenuEntry } from '@nextcloud/files'
34
import { UploadPicker } from '../../dist/index.js'
45

56
describe('UploadPicker rendering', () => {
67
it('Renders default UploadPicker', () => {
78
cy.mount(UploadPicker)
89
cy.get('form').should('have.class', 'upload-picker')
910
cy.get('form input[type="file"]').should('exist')
11+
cy.screenshot()
12+
})
13+
})
14+
15+
describe('NewFileMenu handling', () => {
16+
const propsData = {
17+
context: {
18+
basename: 'Folder',
19+
etag: '63071eedd82fe',
20+
fileid: '56',
21+
filename: '/Folder',
22+
hasPreview: false,
23+
lastmod: 1661410576,
24+
mime: 'httpd/unix-directory',
25+
month: '197001',
26+
permissions: 'CKGWDR',
27+
showShared: false,
28+
size: 2610077102,
29+
timestamp: 1661410,
30+
type: 'dir',
31+
},
32+
}
33+
const entry = {
34+
id: 'empty-file',
35+
displayName: 'Create empty file',
36+
templateName: 'New file',
37+
iconClass: 'icon-file',
38+
if: fileInfo => fileInfo.permissions.includes('CK'),
39+
handler() {},
40+
}
41+
42+
before(() => {
43+
cy.spy(entry, 'handler')
44+
addNewFileMenuEntry(entry)
45+
})
46+
47+
it('Open the New File Menu', () => {
48+
// Mount picker
49+
cy.mount(UploadPicker, { propsData })
50+
51+
// Check and init aliases
52+
cy.get('form input[type="file"]').as('input').should('exist')
53+
cy.get('form .upload-picker__progress').as('progress').should('exist')
54+
cy.get('form .action-item__menutoggle').as('menuButton').should('exist')
55+
56+
cy.get('@menuButton').click()
57+
cy.get('[data-upload-picker-add]').should('have.length', 1)
58+
cy.get('.upload-picker__menu-entry').should('have.length', 1)
59+
60+
cy.screenshot()
61+
62+
cy.get('.upload-picker__menu-entry')
63+
.click()
64+
.then(() => {
65+
expect(entry.handler).to.be.called
66+
cy.screenshot()
67+
})
68+
})
69+
70+
it('Changes the context', () => {
71+
// Mount picker
72+
cy.mount(UploadPicker, { propsData })
73+
74+
// Check and init aliases
75+
cy.get('form input[type="file"]').as('input').should('exist')
76+
cy.get('form .upload-picker__progress').as('progress').should('exist')
77+
cy.get('form .action-item__menutoggle').as('menuButton').should('exist')
78+
79+
cy.get('@menuButton').click()
80+
cy.get('[data-upload-picker-add]').should('have.length', 1)
81+
cy.get('.upload-picker__menu-entry').should('have.length', 1)
82+
cy.screenshot()
83+
84+
// Close menu
85+
cy.get('body').click()
86+
cy.get('[data-upload-picker-add]').should('not.exist')
87+
cy.get('.upload-picker__menu-entry').should('not.exist')
88+
89+
cy.get('@component').then(component => {
90+
component.setContext(Object.assign({}, propsData.context, { permissions: 'GR' }))
91+
})
92+
cy.get('form .action-item__menutoggle').as('menuButton').should('not.exist')
93+
cy.get('[data-upload-picker-add]').should('have.length', 1)
94+
cy.get('.upload-picker__menu-entry').should('not.exist')
95+
cy.screenshot()
1096
})
1197
})
1298

@@ -65,6 +151,7 @@ describe('UploadPicker valid uploads', () => {
65151
cy.wait('@chunks').then(() => {
66152
cy.get('form .upload-picker__progress').as('progress').should('be.visible')
67153
cy.get('@progress').children('progress').should('not.have.value', '0')
154+
cy.screenshot()
68155
})
69156
cy.wait('@assembly', { timeout: 60000 }).then(() => {
70157
cy.get('form .upload-picker__progress').as('progress').should('not.be.visible')
@@ -103,7 +190,6 @@ describe('Destination management', () => {
103190
// Mount picker
104191
cy.mount(UploadPicker, { propsData })
105192

106-
107193
// Check and init aliases
108194
cy.get('form input[type="file"]').as('input').should('exist')
109195
cy.get('form .upload-picker__progress').as('progress').should('exist')

lib/components/UploadPicker.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export default {
124124
type: String,
125125
default: '/',
126126
},
127+
context: {
128+
type: Object,
129+
default: undefined,
130+
},
127131
},
128132
129133
data() {
@@ -135,7 +139,7 @@ export default {
135139
eta: null,
136140
timeLeft: '',
137141
138-
newFileMenuEntries: getNewFileMenuEntries(),
142+
newFileMenuEntries: getNewFileMenuEntries(this.context),
139143
uploadManager,
140144
}
141145
},
@@ -170,6 +174,15 @@ export default {
170174
},
171175
172176
watch: {
177+
/**
178+
* If the context change, we need to refresh the menu
179+
*
180+
* @param {FileInfo} context the current NewFileMenu context
181+
*/
182+
context(context) {
183+
this.setContext(context)
184+
},
185+
173186
totalQueueSize(size) {
174187
this.eta = makeEta({ min: 0, max: size })
175188
this.updateStatus()
@@ -207,6 +220,7 @@ export default {
207220
208221
beforeMount() {
209222
this.setDestination(this.destination)
223+
this.setContext(this.context)
210224
logger.debug('UploadPicker initialised')
211225
},
212226
@@ -269,6 +283,11 @@ export default {
269283
logger.debug(`Destination path set to ${destination}`)
270284
this.uploadManager.destination = destination
271285
},
286+
287+
setContext(context) {
288+
logger.debug('Context changed to', context);
289+
this.newFileMenuEntries = getNewFileMenuEntries(context)
290+
},
272291
},
273292
}
274293
</script>

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"dependencies": {
8383
"@nextcloud/auth": "^2.0.0",
8484
"@nextcloud/axios": "^2.0.0",
85-
"@nextcloud/files": "^3.0.0-beta.1",
85+
"@nextcloud/files": "^3.0.0-beta.3",
8686
"@nextcloud/l10n": "^1.6.0",
8787
"@nextcloud/logger": "^2.3.0",
8888
"@nextcloud/router": "^2.0.0",

0 commit comments

Comments
 (0)