Skip to content

[React] API Image Functionality - #5696

Merged
SchrodingersGat merged 12 commits into
inventree:masterfrom
SchrodingersGat:api-images
Oct 16, 2023
Merged

SchrodingersGat merged 12 commits into
inventree:masterfrom
SchrodingersGat:api-images

Conversation

@SchrodingersGat

Copy link
Copy Markdown
Member

This PR adds image loading function to the new react interface.

Currently, images hosted by the InvenTree server cannot be loaded by the front end, due to two reasons:

  • Lack of auth headers (previously handled by session cookies)
  • CORS issues (new front-end is hosted at ./platform/)

So. a new <ApiImage> component is provided, which fetches image data (using the user token). Note that browser caching is used for fetched images, so they need only be fetched once (or once per session).

- Do not force "/api/" prefix to the base URL of the server
- We will need to fetch media files from the server (at /media/)
- Extend API URL helper functions
- Used to fetch images from API which require auth
- Requires some tweaks to back-end CORS settings
- Otherwrise, image loading won't work on new API
@netlify

netlify Bot commented Oct 15, 2023 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit f703cbd
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/652cf0e84c857f00096e68e9
😎 Deploy Preview https://deploy-preview-5696--inventree-web-pui-preview.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 86 (no change from production)
Best Practices: 100 (no change from production)
SEO: 70 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair LMK what you think of this approach in general. There might be a better way to handle this? But I could not find a cleaner approach after much searching

@SchrodingersGat SchrodingersGat added the User Interface Related to the frontend / User Interface label Oct 15, 2023
# Conflicts:
#	src/frontend/src/components/renderers/GeneralRenderer.tsx
#	src/frontend/src/components/tables/build/BuildOrderTable.tsx
#	src/frontend/src/components/tables/part/PartTable.tsx
#	src/frontend/src/components/tables/part/RelatedPartTable.tsx

@matmair matmair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems to work; I think it should also work with just linking the media files but there is some CORS stuff that needs to be set up correctly for that to work.

@SchrodingersGat
SchrodingersGat merged commit 4de51f4 into inventree:master Oct 16, 2023
@SchrodingersGat
SchrodingersGat deleted the api-images branch October 16, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants