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

chore: replace Lodash usage with native JS implementation #31907

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hainenber
Copy link
Contributor

@hainenber hainenber commented Jan 17, 2025

SUMMARY

chore: replace Lodash usage with native JS implementation

I noticed these replaceable lodash usage in the codebase when refactoring Enzyme-based unit tests to RTL and made a corresponding PR to address them afterwards.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

All CI checks should pass

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

Copy link

@korbit-ai korbit-ai bot left a 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
Functionality Unhandled JSON Parse Error ▹ view
Performance Redundant Type Checking ▹ view
Files scanned
File Path Reviewed
superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts
superset-frontend/packages/superset-ui-core/src/query/normalizeOrderBy.ts
superset-frontend/plugins/plugin-chart-echarts/src/utils/treeBuilder.ts
superset-frontend/packages/superset-ui-core/src/components/SafeMarkdown.tsx
superset-frontend/src/explore/components/controls/BoundsControl.tsx
superset-frontend/plugins/legacy-preset-chart-deckgl/src/utils.ts
superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts
superset-frontend/src/reduxUtils.ts
superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx
superset-frontend/src/explore/components/controls/ColorSchemeControl/index.tsx
superset-frontend/src/explore/components/DatasourcePanel/index.tsx
superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
superset-frontend/src/SqlLab/components/SqlEditor/index.tsx
superset-frontend/plugins/plugin-chart-table/src/TableChart.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
Naming
Database Operations
Documentation
Logging
Error Handling
Systems and Environment
Objects and Data Structures
Readability and Maintainability
Asynchronous Processing
Design Patterns
Third-Party Libraries
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

Comment on lines +283 to 284
if (typeof datasource?.templateParams === 'string') {
const p = JSON.parse(datasource.templateParams);
Copy link

Choose a reason for hiding this comment

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

Unhandled JSON Parse Error category Functionality

Tell me more
What is the issue?

The code doesn't handle JSON.parse errors which could occur if templateParams contains invalid JSON string.

Why this matters

If templateParams contains malformed JSON, the application will crash when trying to parse it, interrupting the save dataset operation.

Suggested change ∙ Feature Preview

Add try-catch block to handle potential JSON parsing errors:

let templateParams;
if (typeof datasource?.templateParams === 'string') {
  try {
    const p = JSON.parse(datasource.templateParams);
    /* eslint-disable-next-line no-underscore-dangle */
    if (p._filters) {
      /* eslint-disable-next-line no-underscore-dangle */
      delete p._filters;
      // eslint-disable-next-line no-param-reassign
      templateParams = JSON.stringify(p);
    }
  } catch (error) {
    console.error('Error parsing templateParams:', error);
    templateParams = datasource.templateParams;
  }
}
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not my change though

@@ -76,7 +75,7 @@ export function CustomFrame(props: FrameComponentProps) {
value: string | number,
) {
// only positive values in grainValue controls
if (isInteger(value) && value > 0) {
if (typeof value === 'number' && Number.isInteger(value) && value > 0) {
Copy link

Choose a reason for hiding this comment

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

Redundant Type Checking category Performance

Tell me more
What is the issue?

Multiple type checks are being performed unnecessarily in sequence, with Number.isInteger() already implying the value is a number.

Why this matters

The redundant type checking adds unnecessary computation overhead, especially in frequently executed code paths.

Suggested change ∙ Feature Preview

Simplify the condition to only use Number.isInteger() which inherently checks for number type:

if (Number.isInteger(value) && value > 0)
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the typecheck in the beginning, there will be a type error

image

@dosubot dosubot bot added the frontend:refactor Related to refactoring the frontend label Jan 17, 2025
Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

LGTM, wondering if we can switch some eslint rules to force more native stuff in place of lodash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend:refactor Related to refactoring the frontend packages plugins size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants