codeant-ai-for-open-source[bot] commented on code in PR #43400:
URL: https://github.com/apache/superset/pull/43400#discussion_r3832462356
##########
superset-frontend/src/core/dashboard/widgetHeaderControl.tsx:
##########
@@ -126,10 +166,113 @@ function CarouselAddSlide({ nodeId }: { nodeId: string
}): ReactElement {
);
}
-const HEADER_CONTROLS: Record<string, (nodeId: string) => ReactElement> = {
- collapsible: nodeId => <CollapsibleToggle nodeId={nodeId} />,
- carousel: nodeId => <CarouselAddSlide nodeId={nodeId} />,
-};
+/**
+ * Every query-bound type's own header control — `echarts`, `ag-grid-table`,
+ * and `metric-tile` alike, since all three merge
+ * `collectActiveFilters.ts`'s scan into their own query the identical way
+ * (see each widget's own comment). Not an action so much as a light: on
+ * whenever this widget's own query is currently narrowed by some other
+ * node's resolved value — type-agnostic, so a `filter.select`, a
+ * `filter.bar`'s filter, or another chart's own cross-filter all count the
+ * same way — or, only for a type that can emit one itself (`echarts`
+ * today, via `ChartWidget`'s `crossFilter`), by this widget's own
+ * cross-filter click. The receiving half of the same general bus a click
+ * already demonstrates on the sending side — a widget being filtered
+ * otherwise has no visible sign of it at all beyond its data quietly
+ * changing. `null` for a widget neither filtered nor filtering, which is
+ * most of the time.
+ *
+ * Only ever a real control (clickable, clearing the selection) when
+ * there's something *this* widget can clear — its own cross-filter, the
+ * same effect clicking the same data point again already has. This never
+ * happens for `ag-grid-table`/`metric-tile` today, since neither emits one
+ * of its own — nothing here needs to know that; `hasOwnCrossFilter` is
+ * simply always false for a node that's never called `dashboard.emit` on
+ * itself. An incoming filter's source (another widget, a `filter.select`,
+ * a `filter.bar`) isn't this control's to reach into and reset, so that
+ * case is informational only, not a button with nothing to do.
+ */
+function FilterActivityIndicator({
+ nodeId,
+}: {
+ nodeId: string;
+}): ReactElement | null {
+ const node = provider.getNode(nodeId);
+ const datasetId = (
+ node?.props?.dataBinding as { datasetId?: number } | undefined
+ )?.datasetId;
+
+ const incomingFilters =
+ datasetId != null ? getActiveFiltersForDataset(datasetId, nodeId) : [];
+ const hasIncomingFilter = incomingFilters.length > 0;
Review Comment:
**Suggestion:** The activity indicator recomputes
`getActiveFiltersForDataset` during every query-bound widget render. That
function traverses the entire dashboard tree, while each chart, table, and
metric widget already performs the same traversal for its query binding, making
every filter event perform an O(number of query widgets × number of dashboard
nodes) scan and causing avoidable quadratic work on larger dashboards. Reuse a
shared computed filter snapshot for the revision or otherwise traverse the tree
once per dashboard revision. [performance]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Filter changes repeatedly scan all dashboard nodes.
- ⚠️ Large dashboards experience slower filter updates.
- ⚠️ Query widgets duplicate the same resolution work.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/widgetHeaderControl.tsx
**Line:** 205:207
**Comment:**
*Performance: The activity indicator recomputes
`getActiveFiltersForDataset` during every query-bound widget render. That
function traverses the entire dashboard tree, while each chart, table, and
metric widget already performs the same traversal for its query binding, making
every filter event perform an O(number of query widgets × number of dashboard
nodes) scan and causing avoidable quadratic work on larger dashboards. Reuse a
shared computed filter snapshot for the revision or otherwise traverse the tree
once per dashboard revision.
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%2F43400&comment_hash=ab344f5d1f6834c201f56f3d580800c723023adce3dbb68907917a9ab6cc58d9&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43400&comment_hash=ab344f5d1f6834c201f56f3d580800c723023adce3dbb68907917a9ab6cc58d9&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]