EnxDev commented on code in PR #41907:
URL: https://github.com/apache/superset/pull/41907#discussion_r3966752876


##########
superset-frontend/src/components/Chart/DrillDown/useDrillDownState.ts:
##########
@@ -0,0 +1,497 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  useCallback,
+  useEffect,
+  useLayoutEffect,
+  useMemo,
+  useRef,
+  useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import {
+  BinaryQueryObjectFilterClause,
+  ensureIsArray,
+  getClientErrorObject,
+  QueryData,
+  QueryFormData,
+} from '@superset-ui/core';
+import { simpleFilterToAdhoc } from 'src/utils/simpleFilterToAdhoc';
+import {
+  getChartDataRequest,
+  handleChartDataResponse,
+} from 'src/components/Chart/chartAction';
+import { DrillDownLevel } from './types';
+
+/**
+ * The form-data field name that stores the ordered list of drill columns.
+ * The chart starts at hierarchy[0] and advances one level per click.
+ */
+const HIERARCHY_FIELD = 'drilldown_hierarchy';
+const HIERARCHY_FIELD_CAMEL = 'drilldownHierarchy';
+
+/**
+ * Default form-data field that holds the chart's grouping dimension.
+ * Most echarts plugins use 'groupby'; Sunburst uses 'columns'. The click
+ * handler can override this on a per-event basis.
+ */
+const DEFAULT_GROUPBY_FIELD = 'groupby';
+const DEFAULT_ADHOC_FILTERS_FIELD = 'adhoc_filters';
+
+/**
+ * Drill navigation is kept in a module-level store keyed by chart id so it
+ * survives incidental remounts of the chart component. On a dashboard, an
+ * unrelated filter change (e.g. removing another chart's cross-filter) can
+ * cause the grid to re-render and remount the chart, which would otherwise
+ * reset the local React state and make the breadcrumb vanish mid-drill,
+ * stranding the user with no way to navigate back up. The store is process
+ * memory only — a full page reload still starts fresh.
+ */
+interface StoredDrillState {
+  drillStack: DrillDownLevel[];
+  selectedLeaf?: string;
+  /** Filters for the value selected at the deepest level, if any. */
+  selectedLeafFilters?: BinaryQueryObjectFilterClause[];
+}
+const drillStateStore = new Map<string | number, StoredDrillState>();
+
+/**
+ * Clear persisted drill state. Without arguments clears everything (used by
+ * tests to isolate cases); with a chart id clears just that chart.
+ */
+export function clearDrillDownState(chartKey?: string | number): void {
+  if (chartKey === undefined) {
+    drillStateStore.clear();
+  } else {
+    drillStateStore.delete(chartKey);
+  }
+}
+
+interface UseDrillDownStateArgs {
+  /** Unique chart instance id (dashboard grid assigns one per slot). */
+  chartId: string | number;
+  formData: QueryFormData;
+  /** Original chart data, shown when the drill stack is empty */
+  baseQueriesResponse?: QueryData[] | null;
+}
+
+interface UseDrillDownStateResult {
+  /** True if the user has drilled at least one level deep */
+  isDrilling: boolean;
+  /** The breadcrumb path showing where the user is in the hierarchy */
+  drillStack: DrillDownLevel[];
+  /** Value selected at the deepest level */
+  selectedLeaf?: string;
+  /** The computed hierarchy of column names */
+  hierarchy: string[];
+  /** form_data adjusted for the current drill level */
+  effectiveFormData: QueryFormData;
+  /** Chart data for the current drill level (or base data when not drilling) 
*/
+  effectiveQueriesResponse: QueryData[] | null | undefined;
+  /** True while the next-level data is being fetched */
+  isLoading: boolean;
+  /** Error message if the drill query failed */
+  error?: string;
+  /** Whether the chart has a configured drill-down hierarchy */
+  hasHierarchy: boolean;
+  /**
+   * Push a new level onto the drill stack. Called from the chart's click
+   * handler with the filters that identify the clicked data point.
+   */
+  drillDown: (filters: BinaryQueryObjectFilterClause[], label: string) => void;
+  /** Truncate the drill stack to the given depth (0 = back to start) */
+  resetTo: (depth: number) => void;
+}
+
+/**
+ * Hook that manages a chart's drill-down state. Owns the drill stack,
+ * computes the effective form_data for the current level, fetches the
+ * data for that level, and exposes navigation helpers (drillDown / resetTo).
+ *
+ * The hook never mutates the upstream Redux store: closing or refreshing
+ * the dashboard wipes the drill state and restores the original chart.
+ */
+export function useDrillDownState({
+  chartId,
+  formData,
+  baseQueriesResponse,
+}: UseDrillDownStateArgs): UseDrillDownStateResult {
+  const chartKey = chartId;
+
+  // Drill state intentionally persists in drillStateStore across unmounts
+  // (dashboard virtualization scroll-out, tab switches, filter re-layouts) so
+  // it stays in sync with the cross-filter the drill emits into Redux. 
Evicting
+  // it on unmount previously left the emitted cross-filter orphaned — the 
drill
+  // appeared to reset while the filter lingered. The store is cleared on chart
+  // reconfigure (the layout effect below) and via clearDrillDownState.
+
+  const [drillStack, setDrillStack] = useState<DrillDownLevel[]>(

Review Comment:
   **[P1] Scope persisted drill state to the dashboard data mask and 
configuration.** This map survives every unmount and is keyed only by 
`chartId`; on dashboards that is the saved slice id (`gridComponents/Chart` 
passes `props.id`). Dashboard unmount clears Redux data masks, and users can 
also remove this chart cross-filter from the filter bar, but neither path 
clears this store. A remount then restores the old drill stack and fires a 
drilled query while linked charts are back at root. `prevConfigKeyRef` cannot 
catch a different configuration on remount because it initializes to the new 
key. Could we include dashboard/config identity in the stored record and reset 
it when the owning data mask is cleared? A drill → unmount/clear → remount test 
with the same chart id would pin this.



##########
superset-frontend/src/components/Chart/DrillDown/useDrillDownState.ts:
##########
@@ -0,0 +1,497 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  useCallback,
+  useEffect,
+  useLayoutEffect,
+  useMemo,
+  useRef,
+  useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import {
+  BinaryQueryObjectFilterClause,
+  ensureIsArray,
+  getClientErrorObject,
+  QueryData,
+  QueryFormData,
+} from '@superset-ui/core';
+import { simpleFilterToAdhoc } from 'src/utils/simpleFilterToAdhoc';
+import {
+  getChartDataRequest,
+  handleChartDataResponse,
+} from 'src/components/Chart/chartAction';
+import { DrillDownLevel } from './types';
+
+/**
+ * The form-data field name that stores the ordered list of drill columns.
+ * The chart starts at hierarchy[0] and advances one level per click.
+ */
+const HIERARCHY_FIELD = 'drilldown_hierarchy';
+const HIERARCHY_FIELD_CAMEL = 'drilldownHierarchy';
+
+/**
+ * Default form-data field that holds the chart's grouping dimension.
+ * Most echarts plugins use 'groupby'; Sunburst uses 'columns'. The click
+ * handler can override this on a per-event basis.
+ */
+const DEFAULT_GROUPBY_FIELD = 'groupby';
+const DEFAULT_ADHOC_FILTERS_FIELD = 'adhoc_filters';
+
+/**
+ * Drill navigation is kept in a module-level store keyed by chart id so it
+ * survives incidental remounts of the chart component. On a dashboard, an
+ * unrelated filter change (e.g. removing another chart's cross-filter) can
+ * cause the grid to re-render and remount the chart, which would otherwise
+ * reset the local React state and make the breadcrumb vanish mid-drill,
+ * stranding the user with no way to navigate back up. The store is process
+ * memory only — a full page reload still starts fresh.
+ */
+interface StoredDrillState {
+  drillStack: DrillDownLevel[];
+  selectedLeaf?: string;
+  /** Filters for the value selected at the deepest level, if any. */
+  selectedLeafFilters?: BinaryQueryObjectFilterClause[];
+}
+const drillStateStore = new Map<string | number, StoredDrillState>();
+
+/**
+ * Clear persisted drill state. Without arguments clears everything (used by
+ * tests to isolate cases); with a chart id clears just that chart.
+ */
+export function clearDrillDownState(chartKey?: string | number): void {
+  if (chartKey === undefined) {
+    drillStateStore.clear();
+  } else {
+    drillStateStore.delete(chartKey);
+  }
+}
+
+interface UseDrillDownStateArgs {
+  /** Unique chart instance id (dashboard grid assigns one per slot). */
+  chartId: string | number;
+  formData: QueryFormData;
+  /** Original chart data, shown when the drill stack is empty */
+  baseQueriesResponse?: QueryData[] | null;
+}
+
+interface UseDrillDownStateResult {
+  /** True if the user has drilled at least one level deep */
+  isDrilling: boolean;
+  /** The breadcrumb path showing where the user is in the hierarchy */
+  drillStack: DrillDownLevel[];
+  /** Value selected at the deepest level */
+  selectedLeaf?: string;
+  /** The computed hierarchy of column names */
+  hierarchy: string[];
+  /** form_data adjusted for the current drill level */
+  effectiveFormData: QueryFormData;
+  /** Chart data for the current drill level (or base data when not drilling) 
*/
+  effectiveQueriesResponse: QueryData[] | null | undefined;
+  /** True while the next-level data is being fetched */
+  isLoading: boolean;
+  /** Error message if the drill query failed */
+  error?: string;
+  /** Whether the chart has a configured drill-down hierarchy */
+  hasHierarchy: boolean;
+  /**
+   * Push a new level onto the drill stack. Called from the chart's click
+   * handler with the filters that identify the clicked data point.
+   */
+  drillDown: (filters: BinaryQueryObjectFilterClause[], label: string) => void;
+  /** Truncate the drill stack to the given depth (0 = back to start) */
+  resetTo: (depth: number) => void;
+}
+
+/**
+ * Hook that manages a chart's drill-down state. Owns the drill stack,
+ * computes the effective form_data for the current level, fetches the
+ * data for that level, and exposes navigation helpers (drillDown / resetTo).
+ *
+ * The hook never mutates the upstream Redux store: closing or refreshing
+ * the dashboard wipes the drill state and restores the original chart.
+ */
+export function useDrillDownState({
+  chartId,
+  formData,
+  baseQueriesResponse,
+}: UseDrillDownStateArgs): UseDrillDownStateResult {
+  const chartKey = chartId;
+
+  // Drill state intentionally persists in drillStateStore across unmounts
+  // (dashboard virtualization scroll-out, tab switches, filter re-layouts) so
+  // it stays in sync with the cross-filter the drill emits into Redux. 
Evicting
+  // it on unmount previously left the emitted cross-filter orphaned — the 
drill
+  // appeared to reset while the filter lingered. The store is cleared on chart
+  // reconfigure (the layout effect below) and via clearDrillDownState.
+
+  const [drillStack, setDrillStack] = useState<DrillDownLevel[]>(
+    () =>
+      (chartKey != null
+        ? drillStateStore.get(chartKey)?.drillStack
+        : undefined) ?? [],
+  );
+  const [selectedLeaf, setSelectedLeaf] = useState<string | undefined>(() =>
+    chartKey != null ? drillStateStore.get(chartKey)?.selectedLeaf : undefined,
+  );
+  // Filters for the value picked at the deepest level. Applied to the drilled
+  // chart's own query so it narrows to the selected leaf (a single bar),
+  // independent of the dashboard's cross-filter scope config. Without this the
+  // drilled chart keeps showing the full leaf distribution and only charts 
that
+  // happen to include themselves in their cross-filter scope look "filtered".
+  const [selectedLeafFilters, setSelectedLeafFilters] = useState<
+    BinaryQueryObjectFilterClause[] | undefined
+  >(() =>
+    chartKey != null
+      ? drillStateStore.get(chartKey)?.selectedLeafFilters
+      : undefined,
+  );
+  const [drillData, setDrillData] = useState<QueryData[] | null>(null);
+  const [isLoading, setIsLoading] = useState(false);
+  const [error, setError] = useState<string | undefined>();
+
+  // Persist drill navigation synchronously so it survives remounts (see
+  // drillStateStore) without racing. Writing on a deferred effect would let a
+  // remount triggered by the same interaction (e.g. clearing a cross-filter)
+  // restore stale state before the effect runs, so the mutators below write
+  // through this helper immediately instead.
+  const persist = useCallback(
+    (
+      stack: DrillDownLevel[],
+      leaf: string | undefined,
+      leafFilters: BinaryQueryObjectFilterClause[] | undefined,
+    ) => {
+      if (chartKey == null) {
+        return;
+      }
+      if (stack.length === 0 && !leaf) {
+        drillStateStore.delete(chartKey);
+      } else {
+        drillStateStore.set(chartKey, {
+          drillStack: stack,
+          selectedLeaf: leaf,
+          selectedLeafFilters: leafFilters,
+        });
+      }
+    },
+    [chartKey],
+  );
+
+  // Reset when the drill configuration changes, not just chart id or viz type.
+  // The drill stack is anchored to the primary dimension (x_axis or groupby)
+  // and the hierarchy list, so editing either — even without a viz-type change
+  // — must clear stale state whose next dimension no longer exists. A ref 
guard
+  // ensures the initial mount (which restores persisted state) does not wipe
+  // it, and that incidental re-renders from filter changes don't either.
+  // useLayoutEffect runs synchronously before paint so the stale drill state
+  // is cleared without a visible flash when the chart is reconfigured.
+  const configFd = formData as Record<string, unknown>;
+  const configKey = JSON.stringify([
+    chartId,
+    formData.viz_type,
+    configFd.x_axis ?? configFd.xAxis,
+    configFd[HIERARCHY_FIELD] ?? configFd[HIERARCHY_FIELD_CAMEL],
+    configFd[DEFAULT_GROUPBY_FIELD],
+  ]);
+  const prevConfigKeyRef = useRef(configKey);
+  useLayoutEffect(() => {
+    if (prevConfigKeyRef.current === configKey) {
+      return;
+    }
+    prevConfigKeyRef.current = configKey;
+    if (chartKey != null) {
+      drillStateStore.delete(chartKey);
+    }
+    setDrillStack([]);
+    setSelectedLeaf(undefined);
+    setSelectedLeafFilters(undefined);
+    setDrillData(null);
+    setError(undefined);
+  }, [configKey, chartKey]);
+
+  const hierarchy = useMemo<string[]>(() => {
+    const fd = formData as Record<string, unknown>;
+    const xAxis = fd.x_axis ?? fd.xAxis;
+
+    // Primary source: the dedicated `drilldown_hierarchy` control. The chart's
+    // own primary dimension (x_axis for axis charts, the first groupby column
+    // for groupby charts) is the top level and is prepended automatically when
+    // the author lists only the deeper levels.
+    const drillLevels = ensureIsArray(
+      fd[HIERARCHY_FIELD] ?? fd[HIERARCHY_FIELD_CAMEL],
+    ) as string[];
+    if (drillLevels.length > 0) {
+      // The primary dimension is always the initial (index 0) level, even if
+      // the author listed it later in the control; normalize it to the front
+      // (deduped) so the first drill advances off the primary dimension.
+      const xAxisStr = typeof xAxis === 'string' ? xAxis : undefined;
+      if (xAxisStr) {
+        return [xAxisStr, ...drillLevels.filter(col => col !== xAxisStr)];
+      }
+      const firstGroupby = ensureIsArray(fd[DEFAULT_GROUPBY_FIELD]).find(
+        col => typeof col === 'string',
+      ) as string | undefined;
+      if (firstGroupby) {
+        return [
+          firstGroupby,
+          ...drillLevels.filter(col => col !== firstGroupby),
+        ];
+      }
+      return drillLevels;
+    }
+
+    return [];
+  }, [formData]);
+
+  // A hierarchy needs at least two levels to be drillable; a single column
+  // (e.g. the author listed only the chart's own dimension) is a no-op that
+  // would otherwise hijack the normal cross-filter click without ever
+  // advancing.
+  const hasHierarchy = hierarchy.length >= 2;
+  const currentDepth = drillStack.length;
+
+  const effectiveFormData = useMemo<QueryFormData>(() => {
+    if (currentDepth === 0) {
+      return formData;
+    }
+    const nextColumn = hierarchy[currentDepth];
+
+    // Merge accumulated filters from every level into adhoc_filters.
+    const accumulatedFilters = drillStack.flatMap(level => level.filters);
+    const baseAdhoc = ensureIsArray(
+      (formData as Record<string, unknown>)[DEFAULT_ADHOC_FILTERS_FIELD],
+    );
+
+    const fdRecord = formData as Record<string, unknown>;
+
+    // Swap the field the hierarchy is anchored to. When the chart has an
+    // x-axis, the hierarchy is x-axis driven (the groupby, if any, is only a
+    // series breakdown and must be preserved), so swap x_axis. Only groupby-
+    // based charts (Pie/Funnel/…, no x_axis) swap the groupby.
+    const xAxisIsSet =
+      typeof fdRecord.x_axis === 'string' || typeof fdRecord.xAxis === 
'string';
+    const groupbyValue = fdRecord[DEFAULT_GROUPBY_FIELD];
+
+    const updated = { ...formData } as Record<string, unknown>;
+
+    if (xAxisIsSet) {
+      // Axis charts (Bar/Line/Area/…): advance the x-axis column.
+      if (typeof fdRecord.x_axis === 'string') {
+        updated.x_axis = nextColumn;
+      }
+      if (typeof fdRecord.xAxis === 'string') {
+        updated.xAxis = nextColumn;
+      }
+    } else {
+      // Groupby-based charts: advance the grouping dimension.
+      updated[DEFAULT_GROUPBY_FIELD] = Array.isArray(groupbyValue)
+        ? [nextColumn]
+        : nextColumn;
+    }
+
+    // At the deepest level a picked value narrows the chart to that single
+    // leaf (matching the breadcrumb selection), rather than showing the full
+    // leaf distribution. Only apply the leaf filters while a leaf is actually
+    // selected so that navigating back (resetTo) or drilling deeper never
+    // leaves stale leaf filters in effectiveFormData. Test presence, not
+    // truthiness, so an empty-string category still counts as a selection.
+    const leafFilters = selectedLeaf != null ? (selectedLeafFilters ?? []) : 
[];
+
+    updated[DEFAULT_ADHOC_FILTERS_FIELD] = [
+      ...baseAdhoc,
+      ...accumulatedFilters.map(f => simpleFilterToAdhoc(f)),
+      ...leafFilters.map(f => simpleFilterToAdhoc(f)),
+    ];
+
+    return updated as QueryFormData;
+  }, [
+    formData,
+    drillStack,
+    currentDepth,
+    hierarchy,
+    selectedLeaf,
+    selectedLeafFilters,
+  ]);
+
+  // Keep the latest effective form-data reachable from the fetch effect
+  // without listing the object itself as a dependency (its identity churns on
+  // every unrelated dashboard re-render).
+  const effectiveFormDataRef = useRef(effectiveFormData);
+  effectiveFormDataRef.current = effectiveFormData;
+
+  // Re-run the fetch only when the *content* of the drill query changes, not
+  // when an unrelated re-render (e.g. a cross-filter update elsewhere on the
+  // dashboard) hands us a new formData object with identical values. Without
+  // this guard those identity-only changes re-run the effect and cancel the
+  // in-flight request before it can clear the loading flag, leaving the chart
+  // spinning until the 60s query timeout.
+  // Only serialize while actually drilling — at depth 0 effectiveFormData is
+  // just the base formData and the fetch effect early-returns, so there is no
+  // need to stringify it on every render of every chart in the app.
+  const effectiveFormDataKey = useMemo(
+    () => (currentDepth > 0 ? JSON.stringify(effectiveFormData) : ''),
+    [currentDepth, effectiveFormData],
+  );
+
+  // Fetch data whenever the user drills (stack changes and is non-empty).
+  useEffect(() => {
+    if (currentDepth === 0) {
+      setDrillData(null);
+      setError(undefined);
+      return undefined;
+    }
+
+    const activeFormData = effectiveFormDataRef.current;
+    let cancelled = false;
+    setIsLoading(true);
+    setError(undefined);
+
+    const extractMessage = async (err: unknown): Promise<string> => {
+      let message = (err as { message?: string })?.message;
+      try {
+        const clientError = await getClientErrorObject(
+          err as Parameters<typeof getClientErrorObject>[0],
+        );
+        message =
+          clientError?.message ||
+          clientError?.error ||
+          (clientError?.errors && clientError.errors[0]?.message) ||
+          message;
+      } catch {
+        // fall back to err.message
+      }
+      return message || t('Failed to load chart data');
+    };
+
+    // The backend can intermittently fail under the burst of concurrent chart
+    // queries a drill click triggers (it also emits a cross-filter, which
+    // re-queries every dashboard chart at once). These failures are transient,
+    // so retry a few times with a short backoff before surfacing the error.
+    const MAX_ATTEMPTS = 3;
+    const RETRY_DELAY_MS = 400;
+
+    const runWithRetry = async () => {
+      for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt += 1) {
+        try {
+          // eslint-disable-next-line no-await-in-loop
+          const { response, json } = await getChartDataRequest({
+            formData: activeFormData,
+          });
+          // eslint-disable-next-line no-await-in-loop
+          const queriesResponse = await handleChartDataResponse(response, 
json);

Review Comment:
   **[P0] Move the drill fetch onto the resolved chart-data API.** The failing 
`lint-frontend` job is `TS2554` on this call: `master` changed 
`handleChartDataResponse` to require a refetch callback (and an optional abort 
signal). Adding a dummy third argument would compile, but it would leave drill 
requests outside the new async/cancellation path. Could we call 
`requestChartDataResolved({ formData: activeFormData }, controller.signal)` 
here and abort in the effect cleanup, matching `exploreJSON`? That should 
restore `tsc` and keep drill-down working when `GLOBAL_ASYNC_QUERIES` is 
enabled.



##########
superset-frontend/src/components/Chart/DrillDown/DrillDownBreadcrumb.tsx:
##########
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { ReactNode } from 'react';
+import { css, useTheme } from '@apache-superset/core/theme';
+import { t } from '@apache-superset/core/translation';
+import { Breadcrumb } from '@superset-ui/core/components';
+import { DrillDownLevel } from './types';
+
+interface DrillDownBreadcrumbProps {
+  /** Ordered list of column names from the chart's drill-down hierarchy */
+  hierarchy: string[];
+  /** The drill levels the user has navigated through */
+  drillStack: DrillDownLevel[];
+  /** Value selected at the deepest level (shown but not clickable) */
+  selectedLeaf?: string;
+  /** Reset the drill-down to the given depth (0 = back to the start) */
+  onJumpTo: (depth: number) => void;
+}
+
+/**
+ * Compact breadcrumb shown above the chart while the user is drilled into
+ * a hierarchy. Clicking any segment jumps back up the stack.
+ *
+ *   country › USA › region › Texas
+ */
+export function DrillDownBreadcrumb({
+  hierarchy,
+  drillStack,
+  selectedLeaf,
+  onJumpTo,
+}: DrillDownBreadcrumbProps) {
+  const theme = useTheme();
+
+  if (drillStack.length === 0 && !selectedLeaf) {
+    return null;
+  }
+
+  const linkCss = css`
+    cursor: pointer;
+    color: ${theme.colorPrimary};
+    background: none;
+    border: none;
+    padding: 0;
+    font: inherit;
+    &:hover {
+      text-decoration: underline;
+    }
+  `;
+
+  // Render a navigable segment as a native button since antd's Breadcrumb 
items
+  // are otherwise inert text; a button is keyboard-operable out of the box.
+  const clickable = (label: string, depth: number): { title: ReactNode } => ({
+    title: (
+      <button type="button" onClick={() => onJumpTo(depth)} css={linkCss}>
+        {label}
+      </button>
+    ),
+  });
+
+  // Build the breadcrumb trail: the hierarchy root, every drilled level, and
+  // the picked leaf (if any). The deepest shown level (last drilled level with
+  // no leaf, or the leaf itself) is inert.
+  const items: { title: ReactNode }[] = [clickable(hierarchy[0] ?? '', 0)];
+  drillStack.forEach((level, index) => {
+    const isLast = index === drillStack.length - 1 && !selectedLeaf;
+    items.push(
+      isLast
+        ? { title: <span>{level.label}</span> }
+        : clickable(level.label, index + 1),
+    );
+  });
+  if (selectedLeaf) {

Review Comment:
   **[P2] Preserve the empty leaf in the breadcrumb too.** The state path was 
updated to treat `""` as a valid selection, but this truthiness check still 
treats it as absent. Clicking an empty-string leaf applies the filter, yet the 
breadcrumb does not add the leaf and leaves the previous segment looking like 
the active level. Could we use `selectedLeaf != null` here (and render a small 
`(empty)` label if a blank item would be ambiguous) plus extend the new 
empty-leaf test through the breadcrumb?



-- 
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]

Reply via email to