Skip to content

[Content] Improve image thumbnails #3224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from

Conversation

finnar-bin
Copy link
Contributor

Show the appropriate thumbnail for non-image files
Resolves #3206

image

@finnar-bin finnar-bin added bug Something isn't working ready PR is complete and ready for deployment labels Feb 17, 2025
@finnar-bin finnar-bin self-assigned this Feb 17, 2025
@finnar-bin finnar-bin requested a review from agalin920 February 28, 2025 04:54
@finnar-bin finnar-bin requested a review from shrunyan March 11, 2025 08:17

if (!params.value || hasError) {
if (!matchedFile) {
// If cache doesn't have the file data, attempt to look it up from the server
Copy link
Contributor

@agalin920 agalin920 Mar 18, 2025

Choose a reason for hiding this comment

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

In what cases will it not? Its an RTK query hook, that data will always be present (fetched or cached)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added to address @shrunyan 's concern in case the cache may have not have been updated

Copy link
Contributor

@agalin920 agalin920 Mar 19, 2025

Choose a reason for hiding this comment

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

Looking at the thread comment you are correcting the assumption that we do in fact make api call and hydrate the media on every load. Was there an additional discussion im not aware of? Im trying to understand in what real world cases this code path will go down. Bigger concern, what if the file has been deleted? Wouldn't this case cause the table cell to make a call every single time?

Copy link
Contributor Author

@finnar-bin finnar-bin Mar 20, 2025

Choose a reason for hiding this comment

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

Stuart and I had a discussion about this last week on a call. If I remember correctly, I think the reason was that it's just a backup in case the cache doesn't have it yet, since in the future what if we decide to limit the response of the api that fetches all the media files then there's a possibility that the file is missing in the cache.

Regarding the concern about a file being deleted, that's actually a good catch. I'll look into that today and see what the behavior is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agalin920 so based on my testing the ImageCell does end up triggering the getFile rtk query every time it's rendered (scrolled in and out of view for example) when the file has been deleted. I can't think of any other way to prevent this aside from having a state on the parent that stores all image zuids with deleted files but I think that's just way too much.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't the record in the local cache have a deleted_at value? That would then inform us the item is deleted. We could not make the API call and display an experience which indicates the fact the image is delete.

Copy link
Contributor Author

@finnar-bin finnar-bin Mar 24, 2025

Choose a reason for hiding this comment

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

@shrunyan there's a deleted_at field but as soon as a file is deleted and rtk query's cache gets invalidated and therefore has to do a get /bin/1-xxxx-xxxx/files to update the cache, the deleted file no longer gets returned in the response. Similarly, doing a get /file/3-xxxx-xxxx to fetch the file, returns a 404 since the file has already been deleted.

The downside to the code that I added above which @agalin920 is raising is that whenever a user is scrolling and a field with a media item that has been deleted is rendered, it will always attempt to do a get /file/3-xxxx-xxxx and will always return a 404, it doesn't loop per se but it does do the api call everytime that item gets rendered to the virtualized table.

Copy link
Contributor

Choose a reason for hiding this comment

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

With deleted files being requested every time they are rendered I'm not sure it matters that much. As it is about just as chatty with the API as files which are not deleted, those records have to fetched as well. A bit more as the user could scroll away and back which would then cause a network request versus pulling it from cache(as you stated it wouldn't be present due to it being deleted and purged from the local rtk query cache). The ratio of deleted images to non-deleted images I would have to imagine is very low. Additionally there could be an argument to be made about wanting to express the fact the associated image to the content record is deleted. Otherwise how else would a user know that. All-in-all I am not sure I see the re-fetching of referenced images which have been deleted as something we should avoid.

Towards @agalin920 primary point around what is the purpose of this check, as the assumption is the data should be present either from network or cache. I'm assuming that is in reference to the isFetchingAllMediaFiles call in this same component. That call seems to aggressive to me. If the component is provided a parameter of the media ZUID why are we not doing a single media file check against cache and then network? To jump ahead of a response of "it would cause to many requests" is that what the all media fetch at app load covers?

@agalin920 agalin920 self-requested a review March 19, 2025 17:08
@agalin920 agalin920 self-requested a review March 19, 2025 17:12
@finnar-bin finnar-bin requested a review from Copilot March 27, 2025 00:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the image thumbnail display by introducing file data lookup logic and using a dedicated preview component for non-image files. Key changes include:

  • Updating ImageCell to query file details via the media manager and render a FileTypePreview.
  • Simplifying the image URL extraction logic in ItemList.
  • Correcting the ecoId property to ecoID in the Favicon component.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/apps/content-editor/src/app/views/ItemList/TableCells/ImageCell.tsx Implements file data retrieval and conditional rendering for image/non-image thumbnails.
src/apps/content-editor/src/app/views/ItemList/index.tsx Simplifies image URL extraction by removing legacy resolution logic.
src/shell/components/Favicon/index.tsx Updates property name for consistency with store types.
Comments suppressed due to low confidence (1)

src/apps/content-editor/src/app/views/ItemList/TableCells/ImageCell.tsx:96

  • Rendering FileTypePreview without ensuring that fileData is present may lead to UI issues. Consider adding a conditional check to render a placeholder or skeleton until fileData is available.
<FileTypePreview isMediaThumbnail src={fileData?.url} filename={fileData?.filename} updatedAt={fileData?.updated_at} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PR is complete and ready for deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content: Multi Page Table - File Type Column - Incorrect File Thumbnails
3 participants