@samitouri / QOSami-HFS / commits / 4a76095e

added id to menu entries, for easier customization

Massimo Melina committed May 16, 2024 at 20:29 UTC 4a76095e376ba16892069cda454d769b38205c65
2 files changed +9 -7
dev-plugins.md
+2 -1
@@ -320,7 +320,7 @@ This is a list of available frontend-events, with respective object parameter an
320 onClick?: () => (Promisable<boolean>) // return false to not close menu dialog
321 //...rest is transfered to <a> element, for example 'target', or 'title'
322 }
323 - type FileMenuProp = [ReactNode,ReactNode] | ReactElement
323 + type FileMenuProp = { id?: string, label: ReactNode, value: ReactNode } | ReactElement
324 ```
325 Example, if you want to remove the 'show' item of the menu:
326 ```typescript
@@ -443,6 +443,7 @@ If you want to override a text regardless of the language, use the special langu
443 - frontend event: menuZip
444 - config.type:username
445 - api.events class has changed
446 + - frontend event "fileMenu": changed props format
447 - 8.72 (v0.52.0)
448 - HFS.toast
449 - HFS.misc functions
frontend/src/fileMenu.ts
+7 -6
@@ -58,10 +58,10 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
58 isFolder && !entry.web && { id: 'list', label: t`Get list`, href: uri + '?get=list&folders=*', icon: 'list' },
59 ]
60 const props = [
61 - [t`Name`, entry.name],
62 - typeof s === 'number' && [t`Size`, h(Fragment, {},
63 - formatBytes(s), h('small', {}, prefix(' (', s > 1024 && s.toLocaleString(), ')')) ) ],
64 - entry.t && [t`Timestamp`, entry.t.toLocaleString()],
61 + { id: 'name', label: t`Name`, value: entry.name },
62 + typeof s === 'number' && { id: 'size', label: t`Size`,
63 + value: h(Fragment, {}, formatBytes(s), h('small', {}, prefix(' (', s > 1024 && s.toLocaleString(), ')')) ) },
64 + entry.t && { id: 'timestamp', label: t`Timestamp`, value: entry.t.toLocaleString() },
65 ]
66 const res = hfsEvent('fileMenu', { entry, menu, props })
67 if (res)
@@ -77,12 +77,12 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
77 const {t} = useI18N()
78 const details = useApi('get_file_details', { uris: [entry.uri] }).data
79 const showProps = [ ...props,
80 - with_(details?.[0]?.upload, x => x && [ t`Uploader`, x.ip + prefix(' (', x.username, ')') ])
80 + with_(details?.[0]?.upload, x => x && { id: 'uploader', label: t`Uploader`, value: x.ip + prefix(' (', x.username, ')') })
81 ]
82 return h(Fragment, {},
83 h('dl', { className: 'file-dialog-properties' },
84 dontBotherWithKeys(showProps.map(prop => isValidElement(prop) ? prop
85 - : Array.isArray(prop) ? h(Fragment, {}, h('dt', {}, prop[0]), h('dd', {}, prop[1]))
85 + : _.isPlainObject(prop) ? h('div', { id: `menu-prop-${prop.id}` }, h('dt', {}, prop.label), h('dd', {}, prop.value))
86 : null
87 ))
88 ),
@@ -94,6 +94,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
94 key: i,
95 href: '#',
96 ..._.omit(e, ['label', 'icon', 'toggled']),
97 + id: e.id && `menu-entry-${e.id}`,
98 className: e.toggled ? 'toggled' : undefined,
99 async onClick(event: MouseEvent) {
100 if (!e.href)