Skip to content

Commit

Permalink
Sketch for fixing #8456
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwengerter committed May 16, 2023
1 parent 43c9c45 commit b562d5b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-respect-archiver-limits
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Respect archiver limits

The archiver service can now announce a limit for both the amount of resources and
the size of the currently selected resources. The web UI now respects those limits
and shows a disabled download button once the limit has been reached.

https://github.com/owncloud/web/pull/9055
https://github.com/owncloud/web/issues/8456
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Bugfix: Interactive texts in OcTooltips

The new tooltip texts would only be initialized once and then didn't offer
the possibility of chaging reactively. By updating the directive, we've changed that.
the possibility of changing reactively. By updating the directive, we've changed that.

https://github.com/owncloud/owncloud-design-system/pull/1288
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
})
}

const archiverLimitsExceeded = (resources: Resource[]) => {
const archiverCapabilities = archiverService.capability
if (!archiverCapabilities) {
return
}

const selectedFilesAmount = resources.length

// TODO: selectedFilesSize doesn't traverse into folders, so currently limited to directly selected resources
const selectedFilesSize = resources.reduce(
(accumulator, currentValue) =>
accumulator +
(typeof currentValue.size === 'string' ? parseInt(currentValue.size) : currentValue.size),
0
)

return (
selectedFilesAmount > parseInt(archiverCapabilities.max_num_files) ||
// TODO: Check whether archiver and web use the same base for filesize calculation
selectedFilesSize > parseInt(archiverCapabilities.max_size)
)
}

const actions = computed((): FileAction[] => {
return [
{
Expand All @@ -68,6 +91,12 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
label: () => {
return $gettext('Download')
},
disabledTooltip: ({ resources }) => {
return archiverLimitsExceeded(resources)
? $gettext('Unable to download that many files at once')
: ''
},
isDisabled: ({ resources }) => archiverLimitsExceeded(resources),
isEnabled: ({ resources }) => {
if (
unref(isFilesAppActive) &&
Expand Down
2 changes: 2 additions & 0 deletions packages/web-app-files/src/services/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface ArchiverCapability {
formats: string[]
// eslint-disable-next-line camelcase
archiver_url: string
max_num_files: string
max_size: string
}

interface TriggerDownloadOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<li>
<li v-oc-tooltip="componentProps.disabled ? action.disabledTooltip(actionOptions) : ''">
<oc-button
v-oc-tooltip="showTooltip || action.hideLabel ? action.label(actionOptions) : ''"
:type="action.componentType"
Expand Down Expand Up @@ -35,8 +35,9 @@
v-if="!action.hideLabel"
class="oc-files-context-action-label"
data-testid="action-label"
>{{ action.label(actionOptions) }}</span
>
{{ action.label(actionOptions) }}
</span>
<span
v-if="action.shortcut && shortcutHint"
class="oc-files-context-action-shortcut"
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/composables/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Action<T = ActionOptions> {

// can be used to display the action in a disabled state in the UI
isDisabled?(options?: T): boolean
disabledTooltip?(options?: T): string
}

export type FileActionOptions = {
Expand Down

0 comments on commit b562d5b

Please sign in to comment.