Skip to content
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

[React] API Image Functionality #5696

Merged
merged 12 commits into from
Oct 16, 2023

Conversation

SchrodingersGat
Copy link
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
Copy link

netlify bot commented Oct 15, 2023

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
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 Platform UI Related to the React based 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
Copy link
Member

@matmair matmair left a comment

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
20 checks passed
@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
Platform UI Related to the React based User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants