Skip to content

feat: cutomize file picker icon size - #2580

Merged
susnux merged 1 commit into
mainfrom
feat/file-picker-custom-icon-size
Sep 8, 2026
Merged

feat: cutomize file picker icon size#2580
susnux merged 1 commit into
mainfrom
feat/file-picker-custom-icon-size

Conversation

@kristian-zendato

@kristian-zendato kristian-zendato commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Fixes: https://github.com/nextcloud-gmbh/customer-feature-requests/issues/1876

Summary

Make the FilePicker list thumbnails configurable via the CSS custom property --file-picker-preview-size (default: 32px), so instances can change size through theming without a public API.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 61.16%. Comparing base (40d0492) to head (c3037e4).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
lib/composables/preview.ts 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2580      +/-   ##
==========================================
+ Coverage   59.86%   61.16%   +1.29%     
==========================================
  Files          15       15              
  Lines         461      479      +18     
  Branches       96      105       +9     
==========================================
+ Hits          276      293      +17     
- Misses        164      165       +1     
  Partials       21       21              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread README.md Outdated
Comment thread lib/components/FilePicker/FilePreview.vue Outdated
@kristian-zendato
kristian-zendato force-pushed the feat/file-picker-custom-icon-size branch from a0443ec to e3b37d1 Compare August 26, 2026 09:11
@kristian-zendato
kristian-zendato force-pushed the feat/file-picker-custom-icon-size branch from e3b37d1 to 7f75f7c Compare August 26, 2026 09:12
Comment thread lib/composables/preview.ts Outdated
Comment thread lib/composables/preview.ts Outdated
Comment thread lib/composables/preview.ts Outdated
mimeFallback: true,
...options,
// Keep request resolution in sync with CSS display size (avoids blurry upscales)
size: options.size ?? getFilePickerPreviewSize(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do a performance improvement here and always query 64px by default.
Because this is the size pregenerated on the backend, scaling can then be done with CSS.
In general we have two pregenerated (cheap) sizes:

  • 64px
  • 256px

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we always query 64px, the preview icon would be blurry for bigger icons size(e.g. 128px or 256px).
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure but the use case is is basically our default of ~34px (?) and 10px.
This method would be called hundreds or thousands of times for big folders.

So the value should be at least only calculated once on first usage (css should not change anymore) and then clamped size <= 64px -> use 64px, size > 64px -> use 256px.
Otherwise this will generate too many previews causing troubles on big instances

@kristian-zendato
kristian-zendato force-pushed the feat/file-picker-custom-icon-size branch from 7f75f7c to 6e38e42 Compare September 7, 2026 12:30
@kristian-zendato
kristian-zendato force-pushed the feat/file-picker-custom-icon-size branch from 6e38e42 to 6365742 Compare September 7, 2026 12:35
Comment thread lib/composables/preview.ts Outdated
Comment on lines +24 to +60
/**
* Cached snapped preview *request* size (64 or 256).
* CSS is read once — display size does not change at runtime.
*/
let previewRequestSize: number | undefined

/**
* Map a display size to a backend-pregenerated request size.
* size ≤ 64 → 64, size > 64 → 256 (avoids generating arbitrary preview sizes).
*
* @param size - Desired display or request size in px
*/
function toPregeneratedPreviewSize(size: number): number {
return size <= PREGENERATED_PREVIEW_SIZE_SMALL
? PREGENERATED_PREVIEW_SIZE_SMALL
: PREGENERATED_PREVIEW_SIZE_LARGE
}

/**
* Resolve the preview request size from CSS display size (once), snapped to 64 or 256.
*/
function getFilePickerPreviewRequestSize(): number {
if (previewRequestSize !== undefined) {
return previewRequestSize
}

const raw = getComputedStyle(document.documentElement)
.getPropertyValue(FILE_PICKER_PREVIEW_SIZE_VAR)
.trim()
const parsed = Number.parseFloat(raw)
const displaySize = Number.isFinite(parsed) && parsed > 0
? Math.round(parsed)
: PREGENERATED_PREVIEW_SIZE_SMALL

previewRequestSize = toPregeneratedPreviewSize(displaySize)
return previewRequestSize
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but for readability I would move all this below the exported stuff, as this is just helper methods (and function is hoisted in JS any ways).

Signed-off-by: kristian-zendato <kristian.zendato@nextcloud.com>
@kristian-zendato
kristian-zendato force-pushed the feat/file-picker-custom-icon-size branch from 6365742 to c3037e4 Compare September 7, 2026 16:33
@susnux
susnux merged commit 7ba8db3 into main Sep 8, 2026
15 checks passed
@susnux
susnux deleted the feat/file-picker-custom-icon-size branch September 8, 2026 10:32
@susnux

susnux commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

/backport to stable6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants