-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
chore(build): reduce Lodash usage in superset-frontend
#32341
chore(build): reduce Lodash usage in superset-frontend
#32341
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Memoization Missing for Config Builder ▹ view |
Files scanned
File Path | Reviewed |
---|---|
superset-websocket/eslint.config.js | ✅ |
superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts | ✅ |
superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Screengrid/Screengrid.tsx | ✅ |
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts | ✅ |
superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx | ✅ |
superset-frontend/src/features/home/ChartTable.tsx | ✅ |
superset-frontend/src/features/home/DashboardTable.tsx | ✅ |
superset-websocket/src/config.ts | ✅ |
superset-frontend/src/components/Select/AsyncSelect.tsx | ✅ |
superset-frontend/src/components/Select/Select.tsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Current Korbit Configuration
General Settings
Setting Value Review Schedule Automatic excluding drafts Max Issue Count 10 Automatic PR Descriptions ❌ Issue Categories
Category Enabled Documentation ✅ Logging ✅ Error Handling ✅ Readability ✅ Design ✅ Performance ✅ Security ✅ Functionality ✅ Feedback and Support
Note
Korbit Pro is free for open source projects 🎉
Looking to add Korbit to your team? Get started with a free 2 week trial here
const anchor = useSelector( | ||
(state: RootState) => | ||
last(state.dashboardState.directPathToChild) || undefined, | ||
const anchor = useSelector((state: RootState) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that last looks much more readable, especially when we have such long array names. Maybe we should either keep lodash or implement our own last
util function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes can, I'll put in our own last
impl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @kgabryje but don't think we should implement our own function. We need to keep in mind that any function that we implement needs to be maintained and in general it's best to depend on libraries that are greatly supported like Lodash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @hainenber. I think some of the changes are beneficial like filter
changes but others decrease readability and increase our maintenance cost. I left comments on the ones that I think we should preserve. As a general guidance, I think it's always better to rely on greatly supported libraries like Lodash instead of rewriting code which requires testing and support.
@@ -574,7 +574,9 @@ const AsyncSelect = forwardRef( | |||
} | |||
} else { | |||
const token = tokenSeparators.find(token => pastedText.includes(token)); | |||
const array = token ? uniq(pastedText.split(token)) : [pastedText]; | |||
const array = token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though we can implement this using simple Javascript, uniq
still offers semantic meaning that helps with readability.
const anchor = useSelector( | ||
(state: RootState) => | ||
last(state.dashboardState.directPathToChild) || undefined, | ||
const anchor = useSelector((state: RootState) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @kgabryje but don't think we should implement our own function. We need to keep in mind that any function that we implement needs to be maintained and in general it's best to depend on libraries that are greatly supported like Lodash.
superset-websocket/src/config.ts
Outdated
@@ -142,6 +140,50 @@ function applyEnvOverrides(config: ConfigType): ConfigType { | |||
} | |||
|
|||
export function buildConfig(): ConfigType { | |||
const config = _merge(defaultConfig(), configFromFile()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous version is way more readable and less error prone.
@@ -76,7 +75,7 @@ function ChartTable({ | |||
TableTab.Other, | |||
); | |||
|
|||
const filteredOtherTabData = filter(otherTabData, obj => 'viz_type' in obj); | |||
const filteredOtherTabData = otherTabData?.filter(obj => 'viz_type' in obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Thanks all for the feedbacks. Looking at this PR retrospectively, I think I optimized too much at the expense of other factors like readability and module maturity. I'll retain the Edit: Apologies for a force push 🙏 |
…rn JS alternatives
882f03e
to
03d7877
Compare
superset-websocket
and reduce Lodash usage in superset-frontend
superset-frontend
Signed-off-by: hainenber <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing the comments @hainenber. You have been one of the best additions to our committers roster. Keep up the excellent work 👏🏼
chore(build): reduce Lodash usage in
superset-frontend
SUMMARY
Reduce some Lodash usage for cases modern JS can handle by its own.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION