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

Adding configuration to allow loading css loaders for react-html5-camera-photo #772

Closed
wants to merge 1 commit into from

Conversation

arodidev
Copy link

@arodidev arodidev commented Sep 21, 2023

…era-photo

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

Summary

This PR adds configurations to the base webpack config file to allow adding of css loaders that enable styles for react-html5-camera-photo component, which is currently being bottlenecked due to lack of configuration. This is in relation work being done to add file-attachment rendering to the react form engine, where files can be uploaded and also captured via camera. The camera component being imported has issues with loading the shutter button out of the gate, hence the need to import a css file to add styles to the camera component.

The camera component though is unresponsive to css being loaded directly from the imported file and a webpack configuration has to be added to the consuming application to allow for the styles to apply to the camera component, so that the shutter button is visible out of the box.

Housing the configuration in the base webpack config file will allow for the configurations to be applied to any esm utilizing react form engine without the need of further adding configuration to each esm.

Screenshots

Related Issue

Other

@arodidev arodidev changed the title Adding configuration to allow loading css loaders for react-html5-cam… Adding configuration to allow loading css loaders for react-html5-camera-photo Sep 21, 2023
Comment on lines +318 to +330
const cfgCreator = require('openmrs/default-webpack-config');

module.exports = (env, argv) => {
const config = cfgCreator(env, argv);
const cssLoaderMode = resourcePath => {
if (/.*react-html5-camera-photo\/build\/css\/index.css/i.test(resourcePath) || /styles.css$/i.test(resourcePath)) {
return 'global';
}
return 'local';
};
config.module.rules[1].use[1].options.modules['mode'] = cssLoaderMode;
config.module.rules[2].use[1].options.modules['mode'] = cssLoaderMode;
return config;
Copy link
Member

Choose a reason for hiding this comment

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

@arodidev have you actually tested this out locally? There is no way this works.

Copy link
Member

Choose a reason for hiding this comment

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

@samuelmale Could you work with Jamie to come up with something that works

@vasharma05
Copy link
Member

vasharma05 commented Sep 28, 2023

We are using the html5 camera photo package in the attachments too. Please do confirm the attachements widget before merging.
Thanks!
CC: @denniskigen @samuelmale

@ibacher
Copy link
Member

ibacher commented Sep 28, 2023

Yeah, one consideration for this is what happens if we mark the CSS as global (so non-module scoped), but end up with multiple copies of it. Rather than just hacking around with how the CSS is loaded via webpack, we probably want to make it into a shared module (peerDependency).

@arodidev
Copy link
Author

arodidev commented Oct 2, 2023

@ibacher Did you mean something like this

@ibacher
Copy link
Member

ibacher commented Oct 2, 2023

@arodidev What I was suggesting is that each app that uses the react-html5-camera-photo should have that library listed in their peerDependencies. That part shouldn’t require any modifications to the default webpack configuration.

@arodidev
Copy link
Author

arodidev commented Oct 4, 2023

@ibacher I attemped adding 'react-html5-camera-photo' as a peerDependency to the app utilising the react-html5-camera-photo (which is the react form engine) and this does not seem to solve the issue. Could this be resolved in another way?

@arodidev arodidev closed this Oct 8, 2023
@ibacher
Copy link
Member

ibacher commented Oct 10, 2023

@arodidev I wasn't meaning to suggest that marking the module as a peer dependency would solve the CSS loading issue, simply that it's something we should do in addition to solving the CSS loading issue. However, as @samuelmale pointed out, the code in this PR wouldn't have fixed the issue in this context (specifically, the code in the PR seems to be aimed at modifying the object exported by the file you're editing to add a rule; you need to just add the rule directly).

@arodidev
Copy link
Author

@ibacher I appreciate the feedback, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants