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

feat: massive collaboratvie theming feature branch #31590

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

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Dec 20, 2024

Excuse the large PR, but this is fairly tangled up, and working on fixing up theming probably requires some massive PRs as it's really hard to proceed PR-by-PR - especially during the holiday break...

Introducing less handlebars templates

First. Clearly we should move away from less and commit to emotion/antd for theming Now deleting the less files is going to be difficult. In the meantime, I wanted to provide a way for less files to source from the main theme object. I decided to go with handlebars since that should be part of the build process.

Considerations:

  • this is temporary, goal is to get rid of less altogether. Having this enables layering the theming work, and allows to make the theme DRY, instead of referncing the same colors a bunch of times
  • eventually could remove the .less files from the repo, and make sure they are dynamically generated on every builds. In the meantime I thought I'd leave them here, and we can instruct people to alter .less.hds files and run npm run compile-less on demand, if/when altering the main theme

Large refactor - what's in this PR?

  • less templates - as described above
  • New Theme object and subpackage as commented in the theming SIP
  • Refactoring/fixing out-of-theme, css-heavy components
    • Alert - vanilla is better!
    • AceEditor
    • EmptyState refactor (that component WAS A MESS, felt almost like on-purpose maze of indirections), fixed the svg so it can receive currentColor as opposed to using an tag - required for making it themable/dark-modable
    • ErrorAlert refactor (also a huge mess, simplifying quite a bit here)
  • Making antd components more vanilla
  • Getting rid of a bunch of CSS
  • Start aligning our css-in-js across the app to use the antd theme tokens
  • storybook improvements
    • improving the theme stories

what's NOT in this PR? - yet to come

  • more theme.antd referencing in emotion
  • move CSS / LESS deletion
  • antd v5 migrations
  • ability to configure an antd ThemeConfig as the theme setup, this will require more moving from legacy theme object to antd

Compiling TODOs / visual bug as of 3/4/25

ok did a round of updates here, tackled some and left some TODOs in the list... thanks to @kgabryje and others for finding these issues!

  • Spacing between the header and the filters section is smaller
  • Import dashboards icon has different color
  • Table chart looks a bit different - now the header is gray, and before every other row had a light gray background, now its all white
  • Native filters modal - spacings are a bit off, the settings/scoping tabs background is gray
  • Explore Borders is controls are much darker
  • Explore: In table chart, when I applied conditional formatting, the colors are much lighter (more transparent??) than before

antd-v5-related

these should fix themselves as we migrate the components to antd-v5

  • Filters placeholders were light grey before
  • When you click on a filter, the active option in the menu has darker color than before

Copy link

korbit-ai bot commented Dec 20, 2024

Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment /korbit-review.

Your admin can change your review schedule in the Korbit Console

@rusackas rusackas self-requested a review December 20, 2024 23:27
@mistercrunch mistercrunch force-pushed the template_less branch 2 times, most recently from f1c7929 to 43452ff Compare December 24, 2024 04:49
@mistercrunch mistercrunch changed the title feat: feat(less): templatize .less files to reference main theme feat: feat(less): massive theming-related PR Dec 30, 2024
@mistercrunch mistercrunch changed the title feat: feat(less): massive theming-related PR feat: massive theming-related PR Dec 30, 2024
@github-actions github-actions bot added the github_actions Pull requests that update GitHub Actions code label Jan 5, 2025
@mistercrunch mistercrunch force-pushed the template_less branch 2 times, most recently from 003f992 to 1652452 Compare January 9, 2025 07:07
mistercrunch added a commit that referenced this pull request Jan 14, 2025
Chiseling at #31590 and bringing what's atomically committable out of there.

This simply adds eslint checks to pre-commit. Note that:
- it requires having run `npm i` in superset-frontend
- it's set up to NOT run in CI as part of the pre-commit validation workflow, since we run eslint more formally in another workflow

Why doing this? Currently it's common to forget to run `npm run lint` prior to committing/pushing, so people can waste time waiting for CI to fail where it could be caught easily. It's nice to have pre-commit do the check itself because it will only evaluate the files that have changed, making it much faster than running a full lint run against all files.
mistercrunch added a commit that referenced this pull request Jan 14, 2025
…rt/e2e.ts

While working on #31590, I noticed that `expect` was not properly imported. It was using it from global for some unknown reason.
@github-actions github-actions bot removed the github_actions Pull requests that update GitHub Actions code label Jan 14, 2025
mistercrunch added a commit that referenced this pull request Jan 15, 2025
Chiseling at #31590 that has gotten big / unruly, in this PR is a refactor of Alert-related components, going vanilla AntD.

Also. Deprecating colors.alerts since it's ambiguous/redundant with warning/error and does not exist in antd-v5
mistercrunch added a commit that referenced this pull request Jan 16, 2025
Chiseling at #31590 that has gotten big / unruly, in this PR is a refactor of Alert-related components, going vanilla AntD.

Also. Deprecating colors.alerts since it's ambiguous/redundant with warning/error and does not exist in antd-v5
mistercrunch added a commit that referenced this pull request Jan 16, 2025
Chiseling at #31590 that has gotten big / unruly, in this PR is a refactor of Alert-related components, going vanilla AntD.

Also. Deprecating colors.alerts since it's ambiguous/redundant with warning/error and does not exist in antd-v5
mistercrunch added a commit that referenced this pull request Jan 18, 2025
Chiseling at #31590 that has gotten big / unruly, in this PR is a refactor of Alert-related components, going vanilla AntD.

Also. Deprecating colors.alerts since it's ambiguous/redundant with warning/error and does not exist in antd-v5
mistercrunch added a commit that referenced this pull request Jan 18, 2025
Chiseling at #31590 that has gotten big / unruly, in this PR is a refactor of Alert-related components, going vanilla AntD.

Also. Deprecating colors.alerts since it's ambiguous/redundant with warning/error and does not exist in antd-v5
// Kept as is for backwards compatibility with the old theme system / superset_config.py
link = (
<GenericLink className="navbar-brand" to={brand.path}>
<img src={brand.icon} alt={brand.alt} />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 1 day ago

To fix the problem, we need to ensure that the brand.icon value is properly sanitized before being used in the src attribute of the img tag. This can be achieved by using a library like DOMPurify to sanitize the URL or by ensuring that the value is a safe URL.

  • Import the DOMPurify library to sanitize the brand.icon value.
  • Sanitize the brand.icon value before using it in the src attribute of the img tag.
  • Make changes in the superset-frontend/src/features/home/Menu.tsx file to implement the sanitization.
Suggested changeset 2
superset-frontend/src/features/home/Menu.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/src/features/home/Menu.tsx b/superset-frontend/src/features/home/Menu.tsx
--- a/superset-frontend/src/features/home/Menu.tsx
+++ b/superset-frontend/src/features/home/Menu.tsx
@@ -19,2 +19,3 @@
 import { useState, useEffect } from 'react';
+import DOMPurify from 'dompurify';
 import { styled, css, useTheme } from '@superset-ui/core';
@@ -282,3 +283,3 @@
         <GenericLink className="navbar-brand" to={brand.path}>
-          <img src={brand.icon} alt={brand.alt} />
+          <img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
         </GenericLink>
@@ -288,3 +289,3 @@
         <a className="navbar-brand" href={brand.path} tabIndex={-1}>
-          <img src={brand.icon} alt={brand.alt} />
+          <img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
         </a>
EOF
@@ -19,2 +19,3 @@
import { useState, useEffect } from 'react';
import DOMPurify from 'dompurify';
import { styled, css, useTheme } from '@superset-ui/core';
@@ -282,3 +283,3 @@
<GenericLink className="navbar-brand" to={brand.path}>
<img src={brand.icon} alt={brand.alt} />
<img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
</GenericLink>
@@ -288,3 +289,3 @@
<a className="navbar-brand" href={brand.path} tabIndex={-1}>
<img src={brand.icon} alt={brand.alt} />
<img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
</a>
superset-frontend/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/package.json b/superset-frontend/package.json
--- a/superset-frontend/package.json
+++ b/superset-frontend/package.json
@@ -219,3 +219,4 @@
     "use-query-params": "^1.1.9",
-    "yargs": "^17.7.2"
+    "yargs": "^17.7.2",
+    "dompurify": "^3.2.5"
   },
EOF
@@ -219,3 +219,4 @@
"use-query-params": "^1.1.9",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"dompurify": "^3.2.5"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.5 None
Copilot is powered by AI and may make mistakes. Always verify output.
);
} else {
link = (
<a className="navbar-brand" href={brand.path} tabIndex={-1}>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 2 days ago

To fix the problem, we need to ensure that the brand.path value is properly sanitized before being used in the href attribute. This can be achieved by using a library like DOMPurify to sanitize the value. We will import DOMPurify and use it to sanitize the brand.path value before rendering it in the href attribute.

Suggested changeset 2
superset-frontend/src/features/home/Menu.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/src/features/home/Menu.tsx b/superset-frontend/src/features/home/Menu.tsx
--- a/superset-frontend/src/features/home/Menu.tsx
+++ b/superset-frontend/src/features/home/Menu.tsx
@@ -19,2 +19,3 @@
 import { useState, useEffect } from 'react';
+import DOMPurify from 'dompurify';
 import { styled, css, useTheme } from '@superset-ui/core';
@@ -287,3 +288,3 @@
       link = (
-        <a className="navbar-brand" href={brand.path} tabIndex={-1}>
+        <a className="navbar-brand" href={DOMPurify.sanitize(brand.path)} tabIndex={-1}>
           <img src={brand.icon} alt={brand.alt} />
EOF
@@ -19,2 +19,3 @@
import { useState, useEffect } from 'react';
import DOMPurify from 'dompurify';
import { styled, css, useTheme } from '@superset-ui/core';
@@ -287,3 +288,3 @@
link = (
<a className="navbar-brand" href={brand.path} tabIndex={-1}>
<a className="navbar-brand" href={DOMPurify.sanitize(brand.path)} tabIndex={-1}>
<img src={brand.icon} alt={brand.alt} />
superset-frontend/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/package.json b/superset-frontend/package.json
--- a/superset-frontend/package.json
+++ b/superset-frontend/package.json
@@ -219,3 +219,4 @@
     "use-query-params": "^1.1.9",
-    "yargs": "^17.7.2"
+    "yargs": "^17.7.2",
+    "dompurify": "^3.2.5"
   },
EOF
@@ -219,3 +219,4 @@
"use-query-params": "^1.1.9",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"dompurify": "^3.2.5"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.5 None
Copilot is powered by AI and may make mistakes. Always verify output.
} else {
link = (
<a className="navbar-brand" href={brand.path} tabIndex={-1}>
<img src={brand.icon} alt={brand.alt} />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 2 days ago

To fix the problem, we need to ensure that the brand.icon value is properly sanitized before it is used in the img tag's src attribute. This can be achieved by using a library like DOMPurify to sanitize the value.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the relevant file.
  3. Use DOMPurify to sanitize the brand.icon value before using it in the img tag.
Suggested changeset 2
superset-frontend/src/features/home/Menu.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/src/features/home/Menu.tsx b/superset-frontend/src/features/home/Menu.tsx
--- a/superset-frontend/src/features/home/Menu.tsx
+++ b/superset-frontend/src/features/home/Menu.tsx
@@ -282,3 +282,3 @@
         <GenericLink className="navbar-brand" to={brand.path}>
-          <img src={brand.icon} alt={brand.alt} />
+          <img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
         </GenericLink>
@@ -288,3 +288,3 @@
         <a className="navbar-brand" href={brand.path} tabIndex={-1}>
-          <img src={brand.icon} alt={brand.alt} />
+          <img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
         </a>
EOF
@@ -282,3 +282,3 @@
<GenericLink className="navbar-brand" to={brand.path}>
<img src={brand.icon} alt={brand.alt} />
<img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
</GenericLink>
@@ -288,3 +288,3 @@
<a className="navbar-brand" href={brand.path} tabIndex={-1}>
<img src={brand.icon} alt={brand.alt} />
<img src={DOMPurify.sanitize(brand.icon)} alt={brand.alt} />
</a>
superset-frontend/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/package.json b/superset-frontend/package.json
--- a/superset-frontend/package.json
+++ b/superset-frontend/package.json
@@ -219,3 +219,4 @@
     "use-query-params": "^1.1.9",
-    "yargs": "^17.7.2"
+    "yargs": "^17.7.2",
+    "dompurify": "^3.2.5"
   },
EOF
@@ -219,3 +219,4 @@
"use-query-params": "^1.1.9",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"dompurify": "^3.2.5"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.5 None
Copilot is powered by AI and may make mistakes. Always verify output.
@mistercrunch mistercrunch changed the title feat: massive theming-related PR feat: massive collaboratvie theming feature branch Apr 7, 2025
mistercrunch added a commit that referenced this pull request Apr 9, 2025
Recently looked into typescript's import `type` keyword and its implications. Turns out using it should have noticeable impacts on bundle size and memory usage (yeh!), and there's a nice lint rule for it.

This PR is DRAFT and will be on hold until we merge the Theming branch to avoid a lot of conflicts.

Note that:
- there are north of 2k lint instance
- `--fix` seems to cover most cases, short by 100-200
- unclear how much we'll save on bundle size, but clearly is good hygiene

Let's pick this up after the great merge of #31590
mistercrunch added a commit that referenced this pull request Apr 9, 2025
Recently looked into typescript's import `type` keyword and its implications. Turns out using it should have noticeable impacts on bundle size and memory usage (yeh!), and there's a nice lint rule for it.

This PR is DRAFT and will be on hold until we merge the Theming branch to avoid a lot of conflicts.

Note that:
- there are north of 2k lint instance
- `--fix` seems to cover most cases, short by 100-200
- unclear how much we'll save on bundle size, but clearly is good hygiene

Let's pick this up after the great merge of #31590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.