fix: extract filename from path in S3 widget preview#1587
Conversation
Previously used slice:-30 which blindly cut the last 30 characters, showing broken paths like "etana/Desktop/X2TQS.txt" instead of the actual filename. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the S3 record-edit widget’s preview label to display the actual filename extracted from an S3 key/path instead of blindly slicing the last 30 characters (which could show broken partial paths).
Changes:
- Add a
displayFilenamecomputed signal that extracts the last path segment and truncates long filenames with an ellipsis. - Update the S3 widget preview template to use
displayFilename()instead of theslice:-30pipe.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/src/app/components/ui-components/record-edit-fields/s3/s3.component.ts | Adds computed logic to extract and truncate the displayed filename from the stored S3 key/path. |
| frontend/src/app/components/ui-components/record-edit-fields/s3/s3.component.html | Switches the preview filename rendering to use the new computed value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| readonly displayFilename = computed(() => { | ||
| const val = this.internalValue() || this.value(); | ||
| if (!val) return ''; | ||
| const name = val.split('/').pop() || val; | ||
| return name.length > 40 ? '...' + name.slice(-37) : name; | ||
| }); |
There was a problem hiding this comment.
Add/adjust unit tests for the new displayFilename computed behavior. There are existing component/spec tests, but they currently only assert that the filename element exists; they should now assert that a path-like key (e.g., uploads/document.pdf) renders just document.pdf, and that long filenames are truncated according to the new 40-char/ellipsis logic.
| const name = val.split('/').pop() || val; | ||
| return name.length > 40 ? '...' + name.slice(-37) : name; |
There was a problem hiding this comment.
displayFilename uses magic numbers (40 and 37) to implement truncation. Consider extracting these into named constants (e.g., maxDisplayLength / tailLength) so the intent is clearer and future changes don’t risk off-by-one mistakes.
Previously used slice:-30 which blindly cut the last 30 characters, showing broken paths like "etana/Desktop/X2TQS.txt" instead of the actual filename.