korbit-ai[bot] commented on code in PR #33523:
URL: https://github.com/apache/superset/pull/33523#discussion_r2096389652
##########
superset-frontend/src/components/Datasource/DatasourceModal.tsx:
##########
@@ -225,6 +225,11 @@ const DatasourceModal:
FunctionComponent<DatasourceModalProps> = ({
t('An error has occurred while syncing virtual dataset columns'),
);
}
+ // Fetch refreshed dataset to get metric IDs
+ const { json: refreshed } = await SupersetClient.get({
+ endpoint: `/api/v1/dataset/${currentDatasource.id}`,
+ });
+ currentDatasource.metrics = refreshed.result.metrics;
Review Comment:
### Mutable State Update for Metrics <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
Direct assignment of refreshed metrics might cause state inconsistency if
the metrics array contains references used by other parts of the component.
###### Why this matters
React's state updates should be treated as immutable. Directly mutating the
metrics array could lead to rendering issues or unexpected behavior in other
component parts that depend on this data.
###### Suggested change ∙ *Feature Preview*
Use setCurrentDatasource to update the metrics in an immutable way:
```typescript
setCurrentDatasource(prevState => ({
...prevState,
metrics: refreshed.result.metrics
}));
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9cc40c75-864a-402c-906e-3d2094ebaebb/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9cc40c75-864a-402c-906e-3d2094ebaebb?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9cc40c75-864a-402c-906e-3d2094ebaebb?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9cc40c75-864a-402c-906e-3d2094ebaebb?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9cc40c75-864a-402c-906e-3d2094ebaebb)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:b95de88e-9a46-4652-8b64-7bc844038d11 -->
[](b95de88e-9a46-4652-8b64-7bc844038d11)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]