-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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(fe): upgrade superset-frontend
to Typescript v5
#31979
feat(fe): upgrade superset-frontend
to Typescript v5
#31979
Conversation
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
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
|
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
…alue assignment Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
/korbit-review |
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 |
---|---|---|
Incorrect Type Return with Optional ID ▹ view | ✅ | |
Zero Value Edge Case in Bubble Size Normalization ▹ view | ✅ | |
Incorrect Type Union in Native Filters Reduction ▹ view | ||
Incorrect Type Assertion in QueryEditor Accumulator ▹ view | ✅ | |
Overly Restrictive Field Type Casting for className ▹ view | ||
Incorrect Field Type Casting for helpText ▹ view | ||
Unsafe numeric conversion in comparator ▹ view | ✅ | |
Lost Hover State Functionality ▹ view | ✅ | |
Potentially Breaking Optional Values Property ▹ view | ✅ | |
Invalid tagIds Type Union ▹ view | ✅ |
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.
Feedback and Support
superset-frontend/src/dashboard/components/ColorSchemeControlWrapper.jsx
Outdated
Show resolved
Hide resolved
...frontend/src/features/databases/DatabaseModal/DatabaseConnectionForm/ValidatedInputField.tsx
Show resolved
Hide resolved
helpText={FIELD_TEXT_MAP[field].helpText} | ||
label={FIELD_TEXT_MAP[field].label || field} | ||
placeholder={FIELD_TEXT_MAP[field as FieldTextMapKey].placeholder} | ||
helpText={FIELD_TEXT_MAP[field as 'account']?.helpText} |
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.
Incorrect Field Type Casting for helpText ![category Functionality](https://camo.githubusercontent.com/be66cdb454480bb0cbb9d568c5947d38543421fabac2bcbd8b17a41babf9d7f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46756e6374696f6e616c6974792d303238346337)
Tell me more
What is the issue?
The field type is incorrectly cast to only 'account', which means helpText will only be available for account fields even when it might be needed for other field types.
Why this matters
This will cause helpText to be undefined for all fields except 'account', potentially hiding important help information from users for other field types.
Suggested change ∙ Feature Preview
Change the type casting to use FieldTextMapKey like other properties:
helpText={FIELD_TEXT_MAP[field as FieldTextMapKey]?.helpText}
💡 Does this comment miss the mark? Tell us why and Korbit will adapt to your team’s feedback.
💬 Chat with Korbit by mentioning @korbit-ai.
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.
@korbit-ai Go with your change doesn't make sense. It returns this issue
Property 'helpText' does not exist on type '{ label: string; helpText: string; placeholder: string; } | { label: string; placeholder: string; className: string; } | { label: string; placeholder: string; className: string; }'.
Property 'helpText' does not exist on type '{ label: string; placeholder: string; className: string; }'.
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 for your feedback. It seems like 'helpText' does not exist for all the field types in the FIELD_TEXT_MAP. If 'helpText' is not intended for the fields 'warehouse' and 'role', then the current implementation is ok because it will not cause 'helpText' to become undefined. However, if it should exist for each field type, then we may need to adjust the FIELD_TEXT_MAP to include 'helpText' for every field.
superset-frontend/plugins/plugin-chart-echarts/src/Bubble/transformProps.ts
Outdated
Show resolved
Hide resolved
@@ -197,7 +197,7 @@ export function fetchObjectsByTagIds( | |||
{ | |||
tagIds = [], | |||
types, | |||
}: { tagIds: number[] | undefined; types: string | null }, | |||
}: { tagIds: (number | undefined)[] | string; types: string | null }, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
@korbit-ai The original input would be [tagId?.id] | ''
and this will always yield [undefined]
or [number]
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.
Hi @hainenber, thanks for your response. I see where you're coming from and appreciate your reasoning. However, to help ensure that our code is clean and minimizes potential confusion, could we perhaps consider using explicit types based on the actual API requirements? For example refactoring our tagIds parameter to be either all numbers or all strings. This would help eliminate any risk of the calling function passing in an invalid value.
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.
@hainenber Do we actually receive an array that might contain undefined
values?
const nativeFilters = Object.keys(filters).reduce( | ||
(acc, key) => { | ||
acc[key] = pick(filters[key], ['chartsInScope']); | ||
return acc; | ||
}, | ||
{} as Record<string, Pick<Filter | Divider, 'chartsInScope'>>, | ||
); |
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.
Incorrect Type Union in Native Filters Reduction ![category Functionality](https://camo.githubusercontent.com/be66cdb454480bb0cbb9d568c5947d38543421fabac2bcbd8b17a41babf9d7f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46756e6374696f6e616c6974792d303238346337)
Tell me more
What is the issue?
The type assertion allows 'Divider' type which cannot have 'chartsInScope' property, potentially causing runtime errors.
Why this matters
If a Divider type is encountered during runtime, accessing 'chartsInScope' will fail as this property doesn't exist on Divider objects, leading to potential undefined behavior or crashes.
Suggested change ∙ Feature Preview
Remove the Divider type from the type assertion as it's not applicable for this operation:
const nativeFilters = Object.keys(filters).reduce(
(acc, key) => {
acc[key] = pick(filters[key], ['chartsInScope']);
return acc;
},
{} as Record<string, Pick<Filter, 'chartsInScope'>>,
);
💡 Does this comment miss the mark? Tell us why and Korbit will adapt to your team’s feedback.
💬 Chat with Korbit by mentioning @korbit-ai.
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.
@korbit-ai 72th line has this type for the assigned value: Pick<Filter | Divider, "chartsInScope">
. Removing Filter
doesn't really make sense for the inferred type.
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.
Hi @hainenber, thank you for your reply. You're correct that the assigned value has the type Pick<Filter | Divider, 'chartsInScope'>
. I see the potential for misinterpretation, as the Filter
objects surely have the 'chartsInScope' field but the Divider
objects do not. For the sake of clarity and to prevent any runtime issues, would it be possible to add some error handling or validation to ensure that the Divider
type is not being used in a context where 'chartsInScope' is accessed? This would make the code more resilient to errors caused by type mismatches.
superset-frontend/src/SqlLab/utils/reduxStateToLocalStorageHelper.ts
Outdated
Show resolved
Hide resolved
Hi @hainenber. Thank you for the amazing PR ❤️
Can you bump @typescript-eslint/typescript-estree given that newer versions support Typescript 5.7.3? |
superset-frontend/packages/superset-ui-chart-controls/src/types.ts
Outdated
Show resolved
Hide resolved
…s.ts from Michael's suggestion Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
I tried out I'll see if it's feasible within this PR. |
If this is not feasible, an alternative would be to use a Typescript version <5.2.0 such as 5.1.6. |
I tried a quick attempt at Beside, the PR is pretty full so the less mental burden for reviewers, the better :D |
…ted Typescript version Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
There seems to be a hanging E2E test process at the moment :D |
Signed-off-by: hainenber <dotronghai96@gmail.com>
superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/utils.ts
Outdated
Show resolved
Hide resolved
superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
Show resolved
Hide resolved
Signed-off-by: hainenber <dotronghai96@gmail.com>
superset-frontend/src/dashboard/components/ColorSchemeControlWrapper.jsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/dashboard/components/ColorSchemeControlWrapper.jsx
Outdated
Show resolved
Hide resolved
@@ -197,7 +197,7 @@ export function fetchObjectsByTagIds( | |||
{ | |||
tagIds = [], | |||
types, | |||
}: { tagIds: number[] | undefined; types: string | null }, | |||
}: { tagIds: (number | undefined)[] | string; types: string | null }, |
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.
@hainenber Do we actually receive an array that might contain undefined
values?
Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
…Ids` function Signed-off-by: hainenber <dotronghai96@gmail.com>
Yes, previously in the codebase, there is this reference. I've changed it so as there will be empty string in place of undefined Tag object :D |
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.
Amazing work @hainenber! Thanks for improving the codebase and addressing the comments.
@hainenber @kgabryje Can we try to fix it forward? |
chart?.queriesResponse?.rejected_filters !== | ||
prevChart?.queriesResponse?.rejected_filters || | ||
chart?.queriesResponse?.applied_filters !== | ||
prevChart?.queriesResponse?.applied_filters || |
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.
Confirmed that the filter's badge disappeared due to this change - queriesResponse is an array so we need that [0]
. Fix in progress
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!
Yikes, this one slipped off my radar. Thanks @kgabryje for doing the fix forward! |
No problem @hainenber! |
Signed-off-by: hainenber <dotronghai96@gmail.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
feat(fe): upgrade
superset-frontend
to Typescript v5SUMMARY
Refactor the whole
superset-frontend
codebase to be compatible with Typescript v5. Most changes are simply casting index key to proper signature, i.e.a as keyof typeof B
and defining Record types. However, there are a few hard roadblocks that I had to rely on//@ts-ignore
to bypass; I have added explanation for each of them.Sanity testing from 1st glance looks OK
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION