bito-code-review[bot] commented on code in PR #40474:
URL: https://github.com/apache/superset/pull/40474#discussion_r3337717972
##########
superset-frontend/src/features/semanticLayers/SemanticLayerModal.tsx:
##########
@@ -307,20 +330,44 @@ export default function SemanticLayerModal({
data: Record<string, unknown>;
errors?: ErrorObject[];
}) => {
- setFormData(data);
+ // When a dependency of a dynamic field changes, clear that field's
+ // value so we don't carry a stale selection across the refresh (e.g.
+ // ``schema=PUBLIC`` lingering after the user switches database).
+ const dynamicDeps = dynamicDepsRef.current;
+ let nextData = data;
+ if (Object.keys(dynamicDeps).length > 0) {
+ const cleared: Record<string, unknown> = {};
+ for (const [field, deps] of Object.entries(dynamicDeps)) {
+ // Self-deps don't count — a field shouldn't wipe its own value
+ // every time the user picks something in it.
+ const externalDeps = deps.filter(dep => dep !== field);
+ if (externalDeps.length === 0) continue;
+ const depsChanged = externalDeps.some(
+ dep => JSON.stringify(formData[dep]) !== JSON.stringify(data[dep]),
+ );
+ if (depsChanged && data[field] !== undefined && data[field] !== '') {
+ cleared[field] = undefined;
+ }
+ }
+ if (Object.keys(cleared).length > 0) {
+ nextData = { ...data, ...cleared };
+ }
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>New clearing logic untested</b></div>
<div id="fix">
The clearing logic (lines 339-354) for dependent fields when their
dependencies change is completely dead code on the current test paths. The only
mock schema uses `x-dependsOn: ['warehouse']` (self-dep), which means
`externalDeps` is always empty and triggers `continue` at line 344. The 1
existing test only verifies debounce behavior and never exercises the clearing
logic.
</div>
</div>
<small><i>Code Review Run #f944fa</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]