codeant-ai-for-open-source[bot] commented on code in PR #40905:
URL: https://github.com/apache/superset/pull/40905#discussion_r3500511938
##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.tsx:
##########
@@ -64,6 +70,106 @@ const CleanFormItem = styled(FormItem)`
margin-bottom: 0;
`;
+/** Resolves the saved or default initial value for a control. */
+function resolveInitialValue(
+ controlItem: CustomControlItem,
+ filterToEdit?: ControlItemsProps['filterToEdit'],
+ customizationToEdit?: ControlItemsProps['customizationToEdit'],
+) {
+ return (
+ filterToEdit?.controlValues?.[controlItem.name] ??
+ customizationToEdit?.controlValues?.[controlItem.name] ??
+ controlItem?.config?.default ??
+ null
+ );
+}
+
+/** Renders a StyledLabel with an optional description tooltip. */
+function ControlLabel({
+ label,
+ description,
+}: {
+ label?: BaseControlConfig['label'];
+ description?: BaseControlConfig['description'];
+}) {
+ const resolvedLabel =
+ typeof label === 'function' ? (label as () => ReactNode)() : label;
+ const resolvedDescription =
+ typeof description === 'function'
+ ? (description as () => ReactNode)()
+ : description;
Review Comment:
**Suggestion:** `BaseControlConfig` allows `label`/`description` functions
that expect control state arguments, but this code invokes them with no
arguments. Any plugin control that dereferences those parameters will throw at
render time, breaking the filter config modal. Pass the expected arguments from
the control context (or avoid eagerly invoking callback labels/descriptions
here) to preserve the control API contract. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Native filter config modal crashes for dynamic-label controls.
- ⚠️ Third-party native filter plugins cannot safely use label callbacks.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Note the BaseControlConfig contract in
packages/superset-ui-chart-controls/src/types.ts
lines 242-251, where `label?` and `description?` are typed as either
`ReactNode` or
`(state: ControlPanelState, controlState: ControlState, chartState?:
AnyDict) =>
ReactNode`, meaning callback labels expect at least the `state` and
`controlState`
arguments.
2. Observe an existing control config that uses this callback form, e.g.
`xAxisSortControl` in
packages/superset-ui-chart-controls/src/shared-controls/customControls.tsx
lines 4-12,
where `label: (state: ControlPanelState) => state.form_data?.orientation ===
'horizontal'
? ...` directly dereferences `state.form_data`, assuming `state` is defined.
3. In the native filters configuration flow, FiltersConfigModal at
src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx
lines
98-118 renders FiltersConfigForm, which calls `getControlItemsMap` in
getControlItemsMap.tsx lines 173-190 to build `controlItems` for the
selected `filterType`
using the shared chart control panel registry (via
`getChartControlPanelRegistry` and
`getControlItems`).
4. When any control item used in this context provides a functional
`config.label` or
`config.description`, `ControlLabel` in getControlItemsMap.tsx lines 88-112
resolves it by
calling `typeof label === 'function' ? (label as () => ReactNode)() :
label;` and
similarly for description (lines 95-100), passing no arguments; for callback
labels like
the `xAxisSortControl` example, this results in `state` being `undefined`
and a runtime
`TypeError` when the implementation evaluates `state.form_data`, causing the
native filter
configuration modal to crash when rendering that control.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=fbac678afc684f44825d56d43d56ca18&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=fbac678afc684f44825d56d43d56ca18&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.tsx
**Line:** 95:100
**Comment:**
*Api Mismatch: `BaseControlConfig` allows `label`/`description`
functions that expect control state arguments, but this code invokes them with
no arguments. Any plugin control that dereferences those parameters will throw
at render time, breaking the filter config modal. Pass the expected arguments
from the control context (or avoid eagerly invoking callback
labels/descriptions here) to preserve the control API contract.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40905&comment_hash=90d25d7828167be9f1c7190999ece59b4830a264f4a86b2850e93f7005ca0c92&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40905&comment_hash=90d25d7828167be9f1c7190999ece59b4830a264f4a86b2850e93f7005ca0c92&reaction=dislike'>👎</a>
--
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]