Hide empty Text view for documents with no text content#613
Open
Hide empty Text view for documents with no text content#613
Conversation
When a document has OCR text but no extracted text content (e.g. an OCR'd image), the Text tab was still shown in the viewer and could be selected or defaulted to, displaying a blank page. Changes: - Add hasTextContent() helper to check for non-empty text contents - Update PreviewSwitcher to hide the Text tab when text is empty - Update PreviewSwitcher validation and fallback to skip empty text - Update getDefaultView() to prefer preview over empty text view - Add previewStatus to the frontend Resource type (already sent by backend, used by JS components, but missing from the TS type) - Add tests for getDefaultView() and hasTextContent()
- Remove unnecessary undefined guard from hasTextContent (text is non-optional on Resource) - Use hasTextContent() in getDefaultView instead of repeating the inline trim/length check - Use idiomatic trim() !== '' comparisons instead of trim().length > 0
Give makeResource a default empty text so callers only need to pass overrides for the fields relevant to each test case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #325
When a document has OCR text but no extracted text content (e.g. an OCR'd image), the Text tab was still shown in the viewer and could be selected or defaulted to, displaying a blank page.
But it was even worse if you opened an image that had no OCRable text. Here the view mode choices were Text (which showed nothing) and Preview (which showed the image), with the default being Text. So by default for non-textual images, users got a blank page and the impression that they had opened a broken or empty file.
This change removes empty Text view modes from the available views. There's a sensible cascade through the default views on opening a doc, even when the user is pushed to a particular view mode (e.g. with ?view=text in the URL). If there's no text, show OCR; if there's no OCR, show preview.
Before, when someone opens an image document that doesn't have any OCR text:
After, opening the same document:
Note that there is no Text view available at the bottom.
Changes:
How has this change been tested?