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

[fix] Remove global CSS rules to avoid conflicts #303 Refactored CSS to prevent global styling conflicts with downstream projects. Fixes #303 #317

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Unnati-Gupta24
Copy link
Contributor

@Unnati-Gupta24 Unnati-Gupta24 commented Dec 23, 2024

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #303 .

Description of Changes

The initial issue was that CSS styles were being applied globally using the * selector, which can cause conflicts in larger projects. Here's how I fixed it:

Created a scoped container structure:

  • Added .netjsongraph-container as main wrapper

  • Added #graphChartContainer for the graph content

  • This contains styles to just these elements instead of affecting entire page

  • Fixed height/positioning issue:

  • Set proper html/body height to 100%

  • Made container absolute positioned with full dimensions
    This ensures graph fills available space correctly

Updated JavaScript:

  • Changed graph initialization to target specific container
  • This connects the new DOM structure to the graph rendering

This approach prevents style leaks while maintaining the original functionality.

@pandafy @nemesifier please review this pull request.
I have made appropriate changes to fix the issue.

@Unnati-Gupta24 Unnati-Gupta24 changed the title Fixing global css issue [fix] Refactor CSS to avoid global style declarations #303 Dec 23, 2024
@Unnati-Gupta24 Unnati-Gupta24 changed the title [fix] Refactor CSS to avoid global style declarations #303 [fix] Remove global CSS rules to avoid conflicts #303 Refactored CSS to prevent global styling conflicts with downstream projects. Fixes #303 Dec 23, 2024
Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @Unnati-Gupta24!

Comment on lines 24 to 30
.netjsongraph-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to duplicate these rules in all examples? You have already defined this in src/css/netjsongraph.css

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, @pandafy. You're absolutely right—the CSS rules are already defined in src/css/netjsongraph.css, so duplicating them in the example_templates folder is unnecessary. I've removed the duplicate code and updated the PR accordingly.
However it is taking sometime to reflect the changes the update shall be visible soon.
a1
Thanks again!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the code accordingly.
Kindly check it. @pandafy

@Unnati-Gupta24 Unnati-Gupta24 changed the base branch from master to dependabot/npm_and_yarn/babel/preset-env-7.26.7 February 12, 2025 04:03
@Unnati-Gupta24 Unnati-Gupta24 changed the base branch from dependabot/npm_and_yarn/babel/preset-env-7.26.7 to 0.2 February 12, 2025 04:04
@Unnati-Gupta24 Unnati-Gupta24 changed the base branch from 0.2 to master February 12, 2025 04:06
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I am not convinced about these changes, I leave some comments here but I think we'll need to double check this with @pandafy.

@@ -14,6 +14,13 @@
<link href="../lib/css/netjsongraph-theme.css" rel="stylesheet" />
<link href="../lib/css/netjsongraph.css" rel="stylesheet" />
<style type="text/css">
html, body {
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid repeating this in each example. We can make a CSS file and store it in public/asstes/css/, should be doable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya I'm making a separate file for example specific stylings

Comment on lines +78 to +80
<div class="netjsongraph-container">
<div id="graphChartContainer"></div>
</div>
Copy link
Member

Choose a reason for hiding this comment

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

Can we shorten this a bit, eg?

Suggested change
<div class="netjsongraph-container">
<div id="graphChartContainer"></div>
</div>
<div id="njg">
</div>

The njg acronym stands for netjsongraph, it's already used elsewhere in the code.

font-size: 14px;
overflow: hidden;
}

h3 {
Copy link
Member

Choose a reason for hiding this comment

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

I also see this and a @font-face directive which don't look right here.

I think the @font-face can be moved to the CSS file dedicated to the examples.

Regarding the h3, can we precede it with some other class?

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Adding a few more comments:

I am not sure if the library does this, but the right thing to do would be to inject an HTML element with a predefined CSS class, so that we prefix everything in the CSS with that class. We can't style main elements like body, html, h3 in a css that is meant to be included anywhere, nor we can load fonts.

Any styling meant for the examples shall be moved in the examples CSS file.

What do you think @pandafy?

@pandafy
Copy link
Member

pandafy commented Feb 21, 2025

I am not sure if the library does this, but the right thing to do would be to inject an HTML element with a predefined CSS class, so that we prefix everything in the CSS with that class. We can't style main elements like body, html, h3 in a css that is meant to be included anywhere, nor we can load fonts.

Any styling meant for the examples shall be moved in the examples CSS file.

What do you think @pandafy?

I agree with @nemesifier

@Unnati-Gupta24
Copy link
Contributor Author

Ok thank you for the suggestions. I'm working on them.

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

Successfully merging this pull request may close these issues.

[bug] Avoid setting CSS rules globally
3 participants