Skip to content

Commit

Permalink
feat: support a as component type in actions (#11502)
Browse files Browse the repository at this point in the history
* feat: support a as component type in actions
  • Loading branch information
kulmann committed Sep 3, 2024
1 parent 4fdcbc8 commit 289f0eb
Show file tree
Hide file tree
Showing 62 changed files with 59 additions and 81 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/enhancement-action-a-tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Support a tags in actions

We've added support for `a` tags in actions. This allows developers to create action extensions for e.g. opening file-specific URLs from the context menu.

https://github.com/owncloud/web/pull/11502
7 changes: 3 additions & 4 deletions docs/extension-system/extension-types/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ The most important configuration options are:
- `icon` - The icon to be displayed, can be picked from https://owncloud.design/#/Design%20Tokens/IconList
- `name` - The name of the action (not displayed in the UI)
- `label` - The text to be displayed
- `route` - The string/route to navigate to, if the nav item should be a `<router-link>`
- `handler` - The action to perform upon click, if the nav item should be a `<button>`
- `componentType` - Either `'button'` or `'router-link'`, depending on whether the action should be a link or button
- `route` - The string/route to navigate to. The nav item will be a `<router-link>` tag.
- `href` - The URL to navigate to. The nav item will be a `<a>`tag.
- `handler` - The action to perform upon click. The nav item will be a `<button>` tag.
- `isVisible` - Determines whether the action is displayed to the user

Please check the [`Action` type](https://github.com/owncloud/web/blob/236c185540fc6758dc7bd84985c8834fa4145530/packages/web-pkg/src/composables/actions/types.ts#L6) for a full list of configuration options.
Expand All @@ -58,7 +58,6 @@ export const useDownloadFilesExtension = () => {
action: {
name: 'download-files',
icon: 'download',
componentType: 'button',
class: 'oc-files-actions-download-files',
label: () => $gettext('Download'),
isVisible: ({ space, resources }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const useGeneralActionsResetLogo = () => {
return ability.can('update-all', 'Logo')
},
handler,
componentType: 'button',
class: 'oc-general-actions-reset-logo-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const useGeneralActionsUploadLogo = ({ imageInput }: { imageInput: VNodeR
handler: () => {
unref(imageInput).click()
},
componentType: 'button',
class: 'oc-general-actions-upload-logo-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const useGroupActionsCreateGroup = () => {
{
name: 'create-group',
icon: 'add',
componentType: 'button',
class: 'oc-groups-actions-create-group',
label: () => $gettext('New group'),
isVisible: () => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const useGroupActionsDelete = () => {
isVisible: ({ resources }) => {
return !!resources.length && !resources.some((r) => r.groupTypes?.includes('ReadOnly'))
},
componentType: 'button',
class: 'oc-groups-actions-delete-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const useGroupActionsEdit = () => {
isVisible: ({ resources }) => {
return resources.length === 1 && !resources[0].groupTypes?.includes('ReadOnly')
},
componentType: 'button',
class: 'oc-groups-actions-edit-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const useUserActionsAddToGroups = ({ groups }: { groups: Ref<Group[]> })
{
name: 'add-to-groups',
icon: 'add',
componentType: 'button',
class: 'oc-users-actions-add-to-groups-trigger',
label: () => $gettext('Add to groups'),
isVisible: ({ resources }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const useUserActionsCreateUser = () => {
{
name: 'create-user',
icon: 'add',
componentType: 'button',
class: 'oc-users-actions-create-user',
label: () => $gettext('New user'),
isVisible: () => !capabilityStore.graphUsersCreateDisabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const useUserActionsDelete = () => {
isVisible: ({ resources }) => {
return !!resources.length && !capabilityStore.graphUsersDeleteDisabled
},
componentType: 'button',
class: 'oc-users-actions-delete-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const useUserActionsEdit = () => {
isVisible: ({ resources }) => {
return resources.length === 1
},
componentType: 'button',
class: 'oc-users-actions-edit-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const useUserActionsEditLogin = () => {
{
name: 'edit-login',
icon: 'login-circle',
componentType: 'button',
class: 'oc-users-actions-edit-login-trigger',
label: () => $gettext('Edit login'),
isVisible: ({ resources }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export const useUserActionsEditQuota = () => {

return ability.can('set-quota-all', 'Drive')
},
componentType: 'button',
class: 'oc-users-actions-edit-quota-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const useUserActionsRemoveFromGroups = ({ groups }: { groups: Ref<Group[]
{
name: 'remove-users-from-groups',
icon: 'subtract',
componentType: 'button',
class: 'oc-users-actions-remove-from-groups-trigger',
label: () => $gettext('Remove from groups'),
isVisible: ({ resources }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const useAppActionsDownload = () => {
isVisible: () => {
return true
},
componentType: 'button',
appearance: 'outline'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const useSpaceActionsUploadImage = ({ spaceImageInput }: { spaceImageInpu

return resources[0].canEditImage({ user: userStore.user })
},
componentType: 'button',
class: 'oc-files-actions-upload-space-image-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,24 @@ const fileActions: Record<string, ActionWithSelector> = {
copy: mock<ActionWithSelector>({
handler: vi.fn(),
label: () => 'Copy',
componentType: 'button',
class: 'oc-files-actions-copy-trigger',
selector: '.oc-files-actions-copy-trigger'
}),
move: mock<ActionWithSelector>({
handler: vi.fn(),
label: () => 'Move',
componentType: 'button',
class: 'oc-files-actions-move-trigger',
selector: '.oc-files-actions-move-trigger'
}),
download: mock<ActionWithSelector>({
handler: vi.fn(),
label: () => 'Download',
componentType: 'button',
class: 'oc-files-actions-download-file-trigger',
selector: '.oc-files-actions-download-file-trigger'
}),
'text-editor': mock<ActionWithSelector>({
handler: vi.fn(),
label: () => 'Open in Text Editor',
componentType: 'button',
class: 'oc-files-actions-text-editor-trigger',
selector: '.oc-files-actions-text-editor-trigger'
})
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-importer/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export const extensions = ({ applicationConfig }: ApplicationSetupOptions) => {
},
isDisabled: () => !!Object.keys(uppyService.getCurrentUploads()).length,
disabledTooltip: () => $gettext('Please wait until all imports have finished'),
componentType: 'button',
class: 'oc-files-actions-import'
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-ocm/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const extensions = (appInfo: ApplicationInformation) => {
resources[0]?.storageId?.startsWith(OCM_PROVIDER_ID)
)
},
componentType: 'button',
class: 'oc-files-actions-open-file-remote'
}
},
Expand Down
5 changes: 1 addition & 4 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,10 @@ export default defineComponent({
disabledTooltip: () => '',
isVisible: () => unref(isEditor),
isDisabled: () => isReadOnly.value || !isDirty.value,
componentType: 'button',
icon: 'save',
id: 'app-save-action',
label: () => 'Save',
handler: () => {
save()
}
handler: save
}
]
})
Expand Down
39 changes: 30 additions & 9 deletions packages/web-pkg/src/components/ContextActions/ActionMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<li v-oc-tooltip="componentProps.disabled ? action.disabledTooltip?.(actionOptions) : ''">
<oc-button
v-oc-tooltip="showTooltip || action.hideLabel ? action.label(actionOptions) : ''"
:type="action.componentType"
:type="componentType"
v-bind="componentProps"
:class="[action.class, 'action-menu-item', 'oc-py-s', 'oc-px-m', 'oc-width-1-1']"
:aria-label="componentProps.disabled ? action.disabledTooltip?.(actionOptions) : ''"
Expand Down Expand Up @@ -99,6 +99,23 @@ export default defineComponent({
const configStore = useConfigStore()
const { options } = storeToRefs(configStore)
const componentType = computed<string>(() => {
if (Object.hasOwn(props.action, 'handler')) {
return 'button'
}
if (Object.hasOwn(props.action, 'route')) {
return 'router-link'
}
if (Object.hasOwn(props.action, 'href')) {
return 'a'
}
console.warn(
'ActionMenuItem: No handler, route or href callback found in action',
props.action
)
return 'button'
})
const componentProps = computed(() => {
const properties = {
appearance: props.action.appearance || props.appearance,
Expand All @@ -109,15 +126,18 @@ export default defineComponent({
...(props.action.id && { id: props.action.id })
}
if (props.action.componentType === 'router-link' && props.action.route) {
return {
...properties,
to: props.action.route(props.actionOptions),
return {
...properties,
...(unref(componentType) === 'router-link' && {
to: props.action.route(props.actionOptions)
}),
...(unref(componentType) === 'a' && {
href: props.action.href(props.actionOptions)
}),
...(['router-link', 'a'].includes(unref(componentType)) && {
target: options.value.cernFeatures ? '_blank' : '_self'
}
})
}
return properties
})
const isMacOs = computed(() => {
Expand All @@ -133,6 +153,7 @@ export default defineComponent({
})
return {
componentType,
componentProps,
openInNewTabHint
}
Expand All @@ -142,7 +163,7 @@ export default defineComponent({
return this.action.icon && /^https?:\/\//i.test(this.action.icon)
},
componentListeners() {
if (typeof this.action.handler !== 'function' || this.action.componentType !== 'button') {
if (typeof this.action.handler !== 'function') {
return {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const useFileActions = () => {
iconFillType: appInfo.iconFillType
}),
img: appInfo.img,
componentType: 'router-link',
route: ({ space, resources }) => {
return getEditorRoute({
appFileExtension: fileExtension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const useFileActionsCopy = () => {
// a user always has their home dir with write access
return true
},
componentType: 'button',
class: 'oc-files-actions-copy-trigger'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const useFileActionsCopyQuickLink = () => {

return canShare({ space, resource: resources[0] })
},
componentType: 'button',
class: 'oc-files-actions-copy-quicklink-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export const useFileActionsCreateLink = ({
return $gettext('Create links')
},
isVisible,
componentType: 'button',
class: 'oc-files-actions-create-links'
},
{
Expand All @@ -164,7 +163,6 @@ export const useFileActionsCreateLink = ({
return $gettext('Create links')
},
isVisible,
componentType: 'button',
class: 'oc-files-actions-create-quick-links'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export const useFileActionsCreateNewFile = ({ space }: { space?: Ref<SpaceResour
isVisible: () => {
return unref(currentFolder)?.canUpload({ user: userStore.user })
},
componentType: 'button',
class: 'oc-files-actions-create-new-file',
ext: appFileExtension.extension,
isExternal: appFileExtension.app?.startsWith('external-')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export const useFileActionsCreateNewFolder = ({ space }: { space?: Ref<SpaceReso
isVisible: () => {
return unref(currentFolder)?.canCreate()
},
componentType: 'button',
class: 'oc-files-actions-create-new-folder'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const useFileActionsCreateNewShortcut = ({ space }: { space: Ref<SpaceRes
isVisible: () => {
return unref(currentFolder)?.canCreate()
},
componentType: 'button',
class: 'oc-files-actions-create-new-shortcut'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const useFileActionsCreateSpaceFromResource = () => {

return true
},
componentType: 'button',
class: 'oc-files-actions-create-space-from-resource-trigger'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const useFileActionsDelete = () => {
})
return !deleteDisabled
},
componentType: 'button',
class: 'oc-files-actions-delete-trigger'
},
{
Expand All @@ -106,7 +105,6 @@ export const useFileActionsDelete = () => {

return resources.length > 0
},
componentType: 'button',
class: 'oc-files-actions-delete-permanent-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const useFileActionsDisableSync = () => {

return resources.some((resource) => resource.syncEnabled)
},
componentType: 'button',
class: 'oc-files-actions-disable-sync-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const useFileActionsDownloadArchive = () => {
})
return !downloadDisabled
},
componentType: 'button',
class: 'oc-files-actions-download-archive-trigger'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const useFileActionsDownloadFile = () => {
}
return resources[0].canDownload()
},
componentType: 'button',
class: 'oc-files-actions-download-file-trigger'
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const useFileActionsEmptyTrashBin = () => {
isDisabled: () => {
return resourcesStore.activeResources.length === 0
},
componentType: 'button',
class: 'oc-files-actions-empty-trash-bin-trigger',
variation: 'danger',
appearance: 'filled'
Expand Down
Loading

0 comments on commit 289f0eb

Please sign in to comment.