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

fix(newfilemenu): fix handler requirement, deprecate iconClass and fix context #742

Merged
merged 1 commit into from Aug 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/index.ts
Expand Up @@ -23,7 +23,7 @@

import { type Entry, getNewFileMenu } from './newFileMenu'
import { type Folder } from './files/folder'
import { type View } from './navigation/view'

Check warning on line 26 in lib/index.ts

View workflow job for this annotation

GitHub Actions / eslint

'View' is defined but never used

export { formatFileSize } from './humanfilesize'
export { FileAction, getFileActions, registerFileAction, DefaultType } from './fileAction'
Expand Down Expand Up @@ -68,9 +68,8 @@
* Get the list of registered entries from the upload menu
*
* @param {Folder} context the creation context. Usually the current folder FileInfo
* @param {View} view the current view
*/
export const getNewFileMenuEntries = function(context?: Folder, view?: View) {
export const getNewFileMenuEntries = function(context?: Folder) {
const newFileMenu = getNewFileMenu()
return newFileMenu.getEntries(context, view)
return newFileMenu.getEntries(context)
}
24 changes: 14 additions & 10 deletions lib/newFileMenu.ts
Expand Up @@ -21,7 +21,6 @@
*/

import { Folder } from './files/folder'
import { View } from './navigation/view'
import logger from './utils/logger'

export interface Entry {
Expand All @@ -35,16 +34,22 @@ export interface Entry {
* Condition wether this entry is shown or not
* @param {Folder} context the creation context. Usually the current folder
*/
if?: (context: Folder, view: View) => boolean
if?: (context: Folder) => boolean
/**
* Either iconSvgInline or iconClass must be defined
* Svg as inline string. <svg><path fill="..." /></svg>
*/
iconSvgInline?: string
/** Existing icon css class */
/**
* Existing icon css class
* @deprecated use iconSvgInline instead
*/
iconClass?: string
/** Function to be run after creation */
handler?: (context: Folder, view: View) => void
/**
* Function to be run after creation
* @param {Folder} context the creation context. Usually the current folder
*/
handler: (context: Folder) => void
}

export class NewFileMenu {
Expand Down Expand Up @@ -73,12 +78,11 @@ export class NewFileMenu {
* Get the list of registered entries
*
* @param {Folder} context the creation context. Usually the current folder
* @param {View} view the current view
*/
public getEntries(context?: Folder, view?: View): Array<Entry> {
if (context && view) {
public getEntries(context?: Folder): Array<Entry> {
if (context) {
return this._entries
.filter(entry => typeof entry.if === 'function' ? entry.if(context, view) : true)
.filter(entry => typeof entry.if === 'function' ? entry.if(context) : true)
}
return this._entries
}
Expand All @@ -88,7 +92,7 @@ export class NewFileMenu {
}

private validateEntry(entry: Entry) {
if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass)) {
if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass || entry.handler)) {
throw new Error('Invalid entry')
}

Expand Down