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(dashboard-css): make to load saved css template #19840

Merged
merged 5 commits into from
Apr 27, 2022

Conversation

prosdev0107
Copy link
Contributor

@prosdev0107 prosdev0107 commented Apr 25, 2022

SUMMARY

CSS template not saving

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

BEFORE:
CSS template not saving

AFTER:
https://user-images.githubusercontent.com/47900232/165148019-2adf38ac-dd71-4989-84be-9c78b7a72ab6.mov

TESTING INSTRUCTIONS

How to reproduce issues

  1. Create a dashboard
  2. Edit CSS and load a CSS template, for instance the one that shows up by default
  3. Save the changes to the dashboard
  4. Reload the page
  5. Edit the dashboard again

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@@ -314,7 +311,7 @@ class HeaderActionsDropdown extends React.PureComponent {
<Menu.Item key={MENU_KEYS.EDIT_CSS}>
<CssEditor
triggerNode={<span>{t('Edit CSS')}</span>}
initialCss={this.state.css}
initialCss={customCss}
Copy link
Contributor

Choose a reason for hiding this comment

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

@prosdev0107 did you check how initialCss works?
I believe initialCss is required in mounting only, not in every rendering. If we use props value directly, intialCss will be defined every rendering, which is not its purpose.

What about the following?

componentDidMount() {
   this.setState({
       css: this.props.customCss
   });
}
...
...
<CssEditor
    initialCss={this.state.css}
    ...
/>

What do you think @diegomedina248 ?

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 tried to resolve it with componentDidMount but it doesn't work.

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 resolved this with componentWillReceiveProps.

@codecov
Copy link

codecov bot commented Apr 25, 2022

Codecov Report

Merging #19840 (8c5feed) into master (523bd8b) will decrease coverage by 0.07%.
The diff coverage is 44.11%.

❗ Current head 8c5feed differs from pull request most recent head 39a3c66. Consider uploading reports for the commit 39a3c66 to get more accurate results

@@            Coverage Diff             @@
##           master   #19840      +/-   ##
==========================================
- Coverage   66.55%   66.48%   -0.08%     
==========================================
  Files        1692     1713      +21     
  Lines       64802    64996     +194     
  Branches     6657     6699      +42     
==========================================
+ Hits        43129    43212      +83     
- Misses      19973    20077     +104     
- Partials     1700     1707       +7     
Flag Coverage Δ
javascript 51.16% <34.10%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...preset-chart-deckgl/src/layers/Geojson/Geojson.jsx 0.00% <0.00%> (ø)
...et-chart-deckgl/src/layers/Geojson/controlPanel.ts 50.00% <ø> (ø)
...plugins/plugin-chart-handlebars/src/Handlebars.tsx 0.00% <0.00%> (ø)
...ars/src/components/Handlebars/HandlebarsViewer.tsx 0.00% <0.00%> (ø)
...frontend/src/SqlLab/components/SqlEditor/index.jsx 51.07% <0.00%> (-0.28%) ⬇️
...src/components/FilterableTable/FilterableTable.tsx 71.42% <ø> (ø)
...rset-frontend/src/components/ReportModal/index.tsx 78.46% <0.00%> (ø)
...ntend/src/views/CRUD/annotation/AnnotationList.tsx 69.35% <ø> (ø)
...-frontend/src/visualizations/presets/MainPreset.js 100.00% <ø> (ø)
superset/charts/post_processing.py 67.17% <ø> (ø)
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 523bd8b...39a3c66. Read the comment docs.

@@ -136,6 +136,12 @@ class HeaderActionsDropdown extends React.PureComponent {
});
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (this.props.customCss !== nextProps.customCss) {
this.setState({ css: nextProps.customCss });
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like customCss comes from redux store, which is updated via updateCss.
Maybe we can try removing the following from changeCss, and inject the custom css after saving it here?:

this.setState({ css }, () => {
  injectCustomCss(css);
});

That would leave us with a single source of truth, which is better (if it works as desired)

@rusackas
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@rusackas Ephemeral environment spinning up at http://54.203.4.231:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM. Would it be easy enough to add some test assertions via RTL or Cypress? This isn't the first time we've seen this sort of trouble in this area.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Apr 27, 2022
@rusackas rusackas merged commit 4a835a4 into apache:master Apr 27, 2022
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

hughhhh pushed a commit to hve-labs/superset that referenced this pull request May 11, 2022
* fix(dashboard-css): make to load saved css template

* fix(dashboard-css): make to update state css with componentDidMount

* fix(dashobard-css): make to inject custom css after updateCss

* fix(dashboard-css): make to add RTL for custom css

* fix(dashboard-css): make to fix lint issue
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
* fix(dashboard-css): make to load saved css template

* fix(dashboard-css): make to update state css with componentDidMount

* fix(dashobard-css): make to inject custom css after updateCss

* fix(dashboard-css): make to add RTL for custom css

* fix(dashboard-css): make to fix lint issue
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels Preset-Patch size/M 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants