msyavuz commented on code in PR #33831:
URL: https://github.com/apache/superset/pull/33831#discussion_r2340850175


##########
superset-frontend/src/dashboard/components/GroupByBadge/index.tsx:
##########
@@ -0,0 +1,362 @@
+/**
+ * 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 { memo, useMemo, useState, useRef } from 'react';
+import { useSelector } from 'react-redux';
+import { styled, t, useTheme } from '@superset-ui/core';
+import { Icons, Badge, Tooltip, Tag } from '@superset-ui/core/components';
+import { ClassNames } from '@emotion/react';
+import { getFilterValueForDisplay } from '../nativeFilters/utils';
+import { ChartCustomizationItem } from 
'../nativeFilters/ChartCustomization/types';
+import { RootState } from '../../types';
+import { isChartWithoutGroupBy } from '../../util/charts/chartTypeLimitations';
+
+export interface GroupByBadgeProps {
+  chartId: number;
+}
+
+const StyledTag = styled(Tag)`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    cursor: pointer;
+    margin-left: ${theme.sizeUnit * 2}px;
+    margin-right: ${theme.sizeUnit}px;
+    padding: ${theme.sizeUnit}px ${theme.sizeUnit * 2}px;
+    background: ${theme.colorBgContainer};
+    border: 1px solid ${theme.colorBorder};
+    border-radius: 4px;
+    height: 100%;
+
+    .anticon {
+      vertical-align: middle;
+      color: ${theme.colorTextSecondary};
+      margin-right: ${theme.sizeUnit}px;
+      &:hover {
+        color: ${theme.colorText};
+      }
+    }
+
+    &:hover {
+      background: ${theme.colorBgTextHover};
+    }
+
+    &:focus-visible {
+      outline: 2px solid ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const StyledBadge = styled(Badge)`
+  ${({ theme }) => `
+    margin-left: ${theme.sizeUnit}px;
+    &>sup.ant-badge-count {
+      padding: 0 ${theme.sizeUnit}px;
+      min-width: ${theme.sizeUnit * 4}px;
+      height: ${theme.sizeUnit * 4}px;
+      line-height: 1.5;
+      font-weight: ${theme.fontWeightStrong};
+      font-size: ${theme.fontSizeSM - 1}px;
+      box-shadow: none;
+      padding: 0 ${theme.sizeUnit}px;
+    }
+  `}
+`;
+
+const TooltipContent = styled.div`
+  ${({ theme }) => `
+    min-width: 200px;
+    max-width: 300px;
+    overflow-x: hidden;
+    color: ${theme.colorText};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const SectionName = styled.span`
+  ${({ theme }) => `
+    font-weight: ${theme.fontWeightStrong};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const GroupByInfo = styled.div`
+  ${({ theme }) => `
+    margin-top: ${theme.sizeUnit}px;
+    &:not(:last-child) {
+      padding-bottom: ${theme.sizeUnit * 3}px;
+    }
+  `}
+`;
+
+const GroupByItem = styled.div`
+  ${({ theme }) => `
+    font-size: ${theme.fontSizeSM}px;
+    margin-bottom: ${theme.sizeUnit}px;
+
+    &:last-child {
+      margin-bottom: 0;
+    }
+  `}
+`;
+
+const GroupByName = styled.span`
+  ${({ theme }) => `
+    padding-right: ${theme.sizeUnit}px;
+    font-style: italic;
+  `}
+`;
+
+const GroupByValue = styled.span`
+  max-width: 100%;
+  flex-grow: 1;
+  overflow: auto;
+`;
+
+export const GroupByBadge = ({ chartId }: GroupByBadgeProps) => {
+  const [tooltipVisible, setTooltipVisible] = useState(false);
+  const triggerRef = useRef<HTMLDivElement>(null);
+  const theme = useTheme();
+
+  const chartCustomizationItems = useSelector<
+    RootState,
+    ChartCustomizationItem[]
+  >(
+    ({ dashboardInfo }) =>
+      dashboardInfo.metadata?.chart_customization_config || [],
+  );
+
+  const chartDataset = useSelector<RootState, string | null>(state => {
+    const chart = state.charts[chartId];
+    if (!chart?.latestQueryFormData?.datasource) {
+      return null;
+    }
+    const chartDatasetParts = String(
+      chart.latestQueryFormData.datasource,
+    ).split('__');
+    return chartDatasetParts[0];
+  });
+
+  const applicableGroupBys = useMemo(() => {
+    if (!chartDataset) {
+      return [];
+    }
+
+    return chartCustomizationItems.filter(item => {
+      if (item.removed) return false;
+
+      const targetDataset = item.customization?.dataset;
+      if (!targetDataset) return false;
+
+      const targetDatasetId = String(targetDataset);
+      const matchesDataset = chartDataset === targetDatasetId;
+
+      const hasColumn = item.customization?.column;
+
+      return matchesDataset && hasColumn;
+    });
+  }, [chartCustomizationItems, chartDataset]);
+
+  const chart = useSelector<RootState, any>(state => state.charts[chartId]);
+  const chartType = chart?.latestQueryFormData?.viz_type;
+
+  const effectiveGroupBys = useMemo(() => {
+    if (!chartType || applicableGroupBys.length === 0) {
+      return [];
+    }
+
+    if (isChartWithoutGroupBy(chartType)) {
+      return [];
+    }
+
+    const chartFormData = chart?.latestQueryFormData;
+    if (!chartFormData) {
+      return applicableGroupBys;
+    }
+
+    const existingColumns = new Set<string>();
+
+    const existingGroupBy = Array.isArray(chartFormData.groupby)
+      ? chartFormData.groupby
+      : chartFormData.groupby
+        ? [chartFormData.groupby]
+        : [];
+    existingGroupBy.forEach((col: string) => existingColumns.add(col));
+
+    if (chartFormData.x_axis) {
+      existingColumns.add(chartFormData.x_axis);
+    }
+
+    const metrics = chartFormData.metrics || [];
+    metrics.forEach((metric: any) => {
+      if (typeof metric === 'string') {
+        existingColumns.add(metric);
+      } else if (metric && typeof metric === 'object' && 'column' in metric) {
+        const metricColumn = metric.column;
+        if (typeof metricColumn === 'string') {
+          existingColumns.add(metricColumn);
+        } else if (
+          metricColumn &&
+          typeof metricColumn === 'object' &&
+          'column_name' in metricColumn
+        ) {
+          existingColumns.add(metricColumn.column_name);
+        }
+      }
+    });
+
+    if (chartFormData.series) {
+      existingColumns.add(chartFormData.series);
+    }
+    if (chartFormData.entity) {
+      existingColumns.add(chartFormData.entity);
+    }
+    if (chartFormData.source) {
+      existingColumns.add(chartFormData.source);
+    }
+    if (chartFormData.target) {
+      existingColumns.add(chartFormData.target);
+    }

Review Comment:
   This feels like it could be a map but this is also fine for me



##########
superset-frontend/src/dashboard/components/nativeFilters/ChartCustomization/ChartCustomizationTitleContainer.tsx:
##########
@@ -0,0 +1,192 @@
+/**
+ * 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 { FC, forwardRef, MouseEvent } from 'react';
+import { styled, t, css, useTheme } from '@superset-ui/core';
+import { Icons, Flex } from '@superset-ui/core/components';
+import { ChartCustomizationItem } from './types';
+
+interface Props {
+  items: ChartCustomizationItem[];
+  currentId: string | null;
+  onChange: (id: string) => void;
+  onRemove: (id: string) => void;
+  restoreItem: (id: string) => void;
+  removedItems: Record<string, { isPending: boolean; timerId?: number } | 
null>;
+  erroredItems?: string[];
+}
+
+const FilterTitle = styled.div<{ selected: boolean; errored: boolean }>`
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  padding: ${({ theme }) => theme.sizeUnit * 2}px
+    ${({ theme }) => theme.sizeUnit * 3}px;
+  background-color: ${({ theme, selected }) =>
+    selected ? theme.colorPrimaryBg : theme.colorBgTextHover};
+  border: 1px solid
+    ${({ theme, selected }) => (selected ? theme.colorPrimary : 
'transparent')};
+  border-radius: ${({ theme }) => theme.sizeUnit}px;
+  cursor: pointer;
+
+  &:hover {
+    background-color: ${({ theme }) => theme.colorBgTextHover};
+  }
+
+  ${({ theme, errored }) =>
+    errored &&
+    `
+    &.errored div, &.errored .warning {
+      color: ${theme.colorErrorText};
+    }
+  `}
+`;
+
+const LabelWrapper = styled.div`
+  display: flex;
+  align-items: center;
+  flex: 1;
+  overflow: hidden;
+`;
+
+const TitleText = styled.div`
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+`;
+
+const UndoButton = styled.span`
+  margin-left: auto;
+  color: ${({ theme }) => theme.colorPrimary};
+  cursor: pointer;
+  font-size: ${({ theme }) => theme.fontSizeSM}px;
+
+  &:hover {
+    text-decoration: underline;
+  }
+`;
+
+const TrashIcon = styled(Icons.DeleteOutlined)`
+  cursor: pointer;
+  margin-left: ${({ theme }) => theme.sizeUnit * 2}px;
+  color: ${({ theme }) => theme.colorTextSecondary};
+
+  &:hover {
+    color: ${({ theme }) => theme.colorErrorText};
+  }
+`;
+
+const StyledWarning = styled(Icons.ExclamationCircleOutlined)`
+  margin-left: ${({ theme }) => theme.sizeUnit * 2}px;
+  color: ${({ theme }) => theme.colorErrorText};
+`;
+
+const ChartCustomizationTitleContainer: FC<Props> = forwardRef(
+  (
+    {
+      items,
+      currentId,
+      onChange,
+      onRemove,
+      restoreItem,
+      removedItems,
+      erroredItems = [],
+    },
+    ref,
+  ) => {
+    const theme = useTheme();
+    return (
+      <Flex
+        css={css`
+          flex-direction: column;
+          gap: ${theme.sizeUnit * 2}px;
+        `}
+        ref={ref as any}
+      >
+        {items.map(item => {
+          const isRemoved = !!removedItems[item.id];
+          const selected = item.id === currentId;
+          const isErrored = erroredItems.includes(item.id);
+          const displayName =
+            item.customization.name?.trim() || t('[untitled]');
+          const classNames = [];
+
+          if (isErrored) {
+            classNames.push('errored');
+          }
+          if (selected) {
+            classNames.push('active');
+          }

Review Comment:
   I am also fine with this but maybe we should use the css prop instead?



##########
superset-frontend/src/dashboard/util/charts/getFormDataWithExtraFilters.ts:
##########
@@ -104,11 +114,409 @@ const createFilterDataMapping = (
   return filterDataMapping;
 };
 
+function processGroupByCustomizations(

Review Comment:
   This looks like a function too big, there is also some code duplication that 
can be avoided by splitting this up



##########
superset-frontend/src/dashboard/components/GroupByBadge/index.tsx:
##########
@@ -0,0 +1,362 @@
+/**
+ * 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 { memo, useMemo, useState, useRef } from 'react';
+import { useSelector } from 'react-redux';
+import { styled, t, useTheme } from '@superset-ui/core';
+import { Icons, Badge, Tooltip, Tag } from '@superset-ui/core/components';
+import { ClassNames } from '@emotion/react';
+import { getFilterValueForDisplay } from '../nativeFilters/utils';
+import { ChartCustomizationItem } from 
'../nativeFilters/ChartCustomization/types';
+import { RootState } from '../../types';
+import { isChartWithoutGroupBy } from '../../util/charts/chartTypeLimitations';
+
+export interface GroupByBadgeProps {
+  chartId: number;
+}
+
+const StyledTag = styled(Tag)`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    cursor: pointer;
+    margin-left: ${theme.sizeUnit * 2}px;
+    margin-right: ${theme.sizeUnit}px;
+    padding: ${theme.sizeUnit}px ${theme.sizeUnit * 2}px;
+    background: ${theme.colorBgContainer};
+    border: 1px solid ${theme.colorBorder};
+    border-radius: 4px;
+    height: 100%;
+
+    .anticon {
+      vertical-align: middle;
+      color: ${theme.colorTextSecondary};
+      margin-right: ${theme.sizeUnit}px;
+      &:hover {
+        color: ${theme.colorText};
+      }
+    }
+
+    &:hover {
+      background: ${theme.colorBgTextHover};
+    }
+
+    &:focus-visible {
+      outline: 2px solid ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const StyledBadge = styled(Badge)`
+  ${({ theme }) => `
+    margin-left: ${theme.sizeUnit}px;
+    &>sup.ant-badge-count {
+      padding: 0 ${theme.sizeUnit}px;
+      min-width: ${theme.sizeUnit * 4}px;
+      height: ${theme.sizeUnit * 4}px;
+      line-height: 1.5;
+      font-weight: ${theme.fontWeightStrong};
+      font-size: ${theme.fontSizeSM - 1}px;
+      box-shadow: none;
+      padding: 0 ${theme.sizeUnit}px;
+    }
+  `}
+`;
+
+const TooltipContent = styled.div`
+  ${({ theme }) => `
+    min-width: 200px;
+    max-width: 300px;
+    overflow-x: hidden;
+    color: ${theme.colorText};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const SectionName = styled.span`
+  ${({ theme }) => `
+    font-weight: ${theme.fontWeightStrong};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const GroupByInfo = styled.div`
+  ${({ theme }) => `
+    margin-top: ${theme.sizeUnit}px;
+    &:not(:last-child) {
+      padding-bottom: ${theme.sizeUnit * 3}px;
+    }
+  `}
+`;
+
+const GroupByItem = styled.div`
+  ${({ theme }) => `
+    font-size: ${theme.fontSizeSM}px;
+    margin-bottom: ${theme.sizeUnit}px;
+
+    &:last-child {
+      margin-bottom: 0;
+    }
+  `}
+`;
+
+const GroupByName = styled.span`
+  ${({ theme }) => `
+    padding-right: ${theme.sizeUnit}px;
+    font-style: italic;
+  `}
+`;
+
+const GroupByValue = styled.span`
+  max-width: 100%;
+  flex-grow: 1;
+  overflow: auto;
+`;
+
+export const GroupByBadge = ({ chartId }: GroupByBadgeProps) => {
+  const [tooltipVisible, setTooltipVisible] = useState(false);
+  const triggerRef = useRef<HTMLDivElement>(null);
+  const theme = useTheme();
+
+  const chartCustomizationItems = useSelector<
+    RootState,
+    ChartCustomizationItem[]
+  >(
+    ({ dashboardInfo }) =>
+      dashboardInfo.metadata?.chart_customization_config || [],
+  );
+
+  const chartDataset = useSelector<RootState, string | null>(state => {
+    const chart = state.charts[chartId];
+    if (!chart?.latestQueryFormData?.datasource) {
+      return null;
+    }
+    const chartDatasetParts = String(
+      chart.latestQueryFormData.datasource,
+    ).split('__');
+    return chartDatasetParts[0];
+  });
+
+  const applicableGroupBys = useMemo(() => {
+    if (!chartDataset) {
+      return [];
+    }
+
+    return chartCustomizationItems.filter(item => {
+      if (item.removed) return false;
+
+      const targetDataset = item.customization?.dataset;
+      if (!targetDataset) return false;
+
+      const targetDatasetId = String(targetDataset);
+      const matchesDataset = chartDataset === targetDatasetId;
+
+      const hasColumn = item.customization?.column;
+
+      return matchesDataset && hasColumn;
+    });
+  }, [chartCustomizationItems, chartDataset]);
+
+  const chart = useSelector<RootState, any>(state => state.charts[chartId]);
+  const chartType = chart?.latestQueryFormData?.viz_type;
+
+  const effectiveGroupBys = useMemo(() => {
+    if (!chartType || applicableGroupBys.length === 0) {
+      return [];
+    }
+
+    if (isChartWithoutGroupBy(chartType)) {
+      return [];
+    }
+
+    const chartFormData = chart?.latestQueryFormData;
+    if (!chartFormData) {
+      return applicableGroupBys;
+    }
+
+    const existingColumns = new Set<string>();
+
+    const existingGroupBy = Array.isArray(chartFormData.groupby)
+      ? chartFormData.groupby
+      : chartFormData.groupby
+        ? [chartFormData.groupby]
+        : [];
+    existingGroupBy.forEach((col: string) => existingColumns.add(col));
+
+    if (chartFormData.x_axis) {
+      existingColumns.add(chartFormData.x_axis);
+    }
+
+    const metrics = chartFormData.metrics || [];
+    metrics.forEach((metric: any) => {
+      if (typeof metric === 'string') {
+        existingColumns.add(metric);
+      } else if (metric && typeof metric === 'object' && 'column' in metric) {
+        const metricColumn = metric.column;
+        if (typeof metricColumn === 'string') {
+          existingColumns.add(metricColumn);
+        } else if (
+          metricColumn &&
+          typeof metricColumn === 'object' &&
+          'column_name' in metricColumn
+        ) {
+          existingColumns.add(metricColumn.column_name);
+        }
+      }
+    });
+
+    if (chartFormData.series) {
+      existingColumns.add(chartFormData.series);
+    }
+    if (chartFormData.entity) {
+      existingColumns.add(chartFormData.entity);
+    }
+    if (chartFormData.source) {
+      existingColumns.add(chartFormData.source);
+    }
+    if (chartFormData.target) {
+      existingColumns.add(chartFormData.target);
+    }
+
+    if (chartType === 'pivot_table_v2') {
+      const pivotColumns = chartFormData.groupbyColumns || [];
+      if (Array.isArray(pivotColumns)) {
+        pivotColumns.forEach((col: any) => {
+          if (typeof col === 'string') {
+            existingColumns.add(col);
+          } else if (col && typeof col === 'object' && 'column_name' in col) {
+            existingColumns.add(col.column_name);
+          }
+        });
+      }
+    }
+
+    if (chartType === 'box_plot') {
+      const boxPlotColumns = chartFormData.columns || [];
+      if (Array.isArray(boxPlotColumns)) {
+        boxPlotColumns.forEach((col: any) => {
+          if (typeof col === 'string') {
+            existingColumns.add(col);
+          } else if (col && typeof col === 'object' && 'column_name' in col) {
+            existingColumns.add(col.column_name);
+          }
+        });
+      }
+    }

Review Comment:
   We can also dry this up a bit more



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx:
##########
@@ -128,6 +140,88 @@ const FilterControls: FC<FilterControlsProps> = ({
   const dashboardHasTabs = useDashboardHasTabs();
   const showCollapsePanel = dashboardHasTabs && filtersWithValues.length > 0;
 
+  const [sectionsOpen, setSectionsOpen] = useState({
+    filters: true,
+    chartCustomization: true,
+  });
+
+  const toggleSection = useCallback((section: keyof typeof sectionsOpen) => {
+    setSectionsOpen(prev => ({
+      ...prev,
+      [section]: !prev[section],
+    }));
+  }, []);
+
+  const sectionContainerStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      margin-bottom: ${theme.sizeUnit * 3}px;
+    `,
+    [],
+  );
+
+  const sectionHeaderStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      display: flex;
+      align-items: center;
+      justify-content: space-between;
+      padding: ${theme.sizeUnit * 2}px 0;
+      cursor: pointer;
+      user-select: none;
+
+      &:hover {
+        background: ${theme.colorBgTextHover};
+        margin: 0 -${theme.sizeUnit * 2}px;
+        padding: ${theme.sizeUnit * 2}px;
+        border-radius: ${theme.sizeUnit}px;
+      }
+    `,
+    [],
+  );
+
+  const sectionTitleStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      margin: 0;
+      font-size: ${theme.fontSize}px;
+      font-weight: ${theme.fontWeightNormal};
+      color: ${theme.colorText};
+      line-height: 1.3;
+    `,
+    [],
+  );
+
+  const sectionContentStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      padding: ${theme.sizeUnit * 2}px 0;
+    `,
+    [],
+  );
+
+  const dividerStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      height: 1px;
+      background: ${theme.colorSplit};
+      margin: ${theme.sizeUnit * 2}px 0;
+    `,
+    [],
+  );
+
+  const iconStyle = useCallback(
+    (isOpen: boolean, theme: SupersetTheme) => css`
+      transform: ${isOpen ? 'rotate(0deg)' : 'rotate(180deg)'};
+      transition: transform 0.2s ease;
+      color: ${theme.colorTextSecondary};
+    `,
+    [],
+  );
+
+  const chartCustomizationContentStyle = useCallback(
+    (theme: SupersetTheme) => css`
+      display: flex;
+      flex-direction: column;
+      gap: ${theme.sizeUnit * 2}px;
+    `,
+    [],
+  );

Review Comment:
   These styles seem out of place here



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx:
##########
@@ -147,14 +241,86 @@ const FilterControls: FC<FilterControlsProps> = ({
   const renderVerticalContent = useCallback(
     () => (
       <>
-        {filtersInScope.map(renderer)}
-        {showCollapsePanel && (
+        {filtersInScope.length > 0 && (
+          <div css={sectionContainerStyle}>
+            {!hideHeader && (
+              <div
+                css={sectionHeaderStyle}
+                onClick={() => toggleSection('filters')}
+                onKeyDown={e => {
+                  if (e.key === 'Enter' || e.key === ' ') {
+                    e.preventDefault();
+                    toggleSection('filters');
+                  }
+                }}
+                role="button"
+                tabIndex={0}
+              >
+                <h4 css={sectionTitleStyle}>{t('Filters')}</h4>

Review Comment:
   There is an antd Typography component



##########
superset-frontend/src/dashboard/components/GroupByBadge/index.tsx:
##########
@@ -0,0 +1,362 @@
+/**
+ * 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 { memo, useMemo, useState, useRef } from 'react';
+import { useSelector } from 'react-redux';
+import { styled, t, useTheme } from '@superset-ui/core';
+import { Icons, Badge, Tooltip, Tag } from '@superset-ui/core/components';
+import { ClassNames } from '@emotion/react';
+import { getFilterValueForDisplay } from '../nativeFilters/utils';
+import { ChartCustomizationItem } from 
'../nativeFilters/ChartCustomization/types';
+import { RootState } from '../../types';
+import { isChartWithoutGroupBy } from '../../util/charts/chartTypeLimitations';
+
+export interface GroupByBadgeProps {
+  chartId: number;
+}
+
+const StyledTag = styled(Tag)`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    cursor: pointer;
+    margin-left: ${theme.sizeUnit * 2}px;
+    margin-right: ${theme.sizeUnit}px;
+    padding: ${theme.sizeUnit}px ${theme.sizeUnit * 2}px;
+    background: ${theme.colorBgContainer};
+    border: 1px solid ${theme.colorBorder};
+    border-radius: 4px;
+    height: 100%;
+
+    .anticon {
+      vertical-align: middle;
+      color: ${theme.colorTextSecondary};
+      margin-right: ${theme.sizeUnit}px;
+      &:hover {
+        color: ${theme.colorText};
+      }
+    }
+
+    &:hover {
+      background: ${theme.colorBgTextHover};
+    }
+
+    &:focus-visible {
+      outline: 2px solid ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const StyledBadge = styled(Badge)`
+  ${({ theme }) => `
+    margin-left: ${theme.sizeUnit}px;
+    &>sup.ant-badge-count {
+      padding: 0 ${theme.sizeUnit}px;
+      min-width: ${theme.sizeUnit * 4}px;
+      height: ${theme.sizeUnit * 4}px;
+      line-height: 1.5;
+      font-weight: ${theme.fontWeightStrong};
+      font-size: ${theme.fontSizeSM - 1}px;
+      box-shadow: none;
+      padding: 0 ${theme.sizeUnit}px;
+    }
+  `}
+`;
+
+const TooltipContent = styled.div`
+  ${({ theme }) => `
+    min-width: 200px;
+    max-width: 300px;
+    overflow-x: hidden;
+    color: ${theme.colorText};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const SectionName = styled.span`
+  ${({ theme }) => `
+    font-weight: ${theme.fontWeightStrong};
+    font-size: ${theme.fontSizeSM}px;
+  `}
+`;
+
+const GroupByInfo = styled.div`
+  ${({ theme }) => `
+    margin-top: ${theme.sizeUnit}px;
+    &:not(:last-child) {
+      padding-bottom: ${theme.sizeUnit * 3}px;
+    }
+  `}
+`;
+
+const GroupByItem = styled.div`
+  ${({ theme }) => `
+    font-size: ${theme.fontSizeSM}px;
+    margin-bottom: ${theme.sizeUnit}px;
+
+    &:last-child {
+      margin-bottom: 0;
+    }
+  `}
+`;
+
+const GroupByName = styled.span`
+  ${({ theme }) => `
+    padding-right: ${theme.sizeUnit}px;
+    font-style: italic;
+  `}
+`;
+
+const GroupByValue = styled.span`
+  max-width: 100%;
+  flex-grow: 1;
+  overflow: auto;
+`;
+
+export const GroupByBadge = ({ chartId }: GroupByBadgeProps) => {
+  const [tooltipVisible, setTooltipVisible] = useState(false);
+  const triggerRef = useRef<HTMLDivElement>(null);
+  const theme = useTheme();
+
+  const chartCustomizationItems = useSelector<
+    RootState,
+    ChartCustomizationItem[]
+  >(
+    ({ dashboardInfo }) =>
+      dashboardInfo.metadata?.chart_customization_config || [],
+  );
+
+  const chartDataset = useSelector<RootState, string | null>(state => {
+    const chart = state.charts[chartId];
+    if (!chart?.latestQueryFormData?.datasource) {
+      return null;
+    }
+    const chartDatasetParts = String(
+      chart.latestQueryFormData.datasource,
+    ).split('__');
+    return chartDatasetParts[0];
+  });
+
+  const applicableGroupBys = useMemo(() => {
+    if (!chartDataset) {
+      return [];
+    }
+
+    return chartCustomizationItems.filter(item => {
+      if (item.removed) return false;
+
+      const targetDataset = item.customization?.dataset;
+      if (!targetDataset) return false;
+
+      const targetDatasetId = String(targetDataset);
+      const matchesDataset = chartDataset === targetDatasetId;
+
+      const hasColumn = item.customization?.column;
+
+      return matchesDataset && hasColumn;
+    });
+  }, [chartCustomizationItems, chartDataset]);
+
+  const chart = useSelector<RootState, any>(state => state.charts[chartId]);
+  const chartType = chart?.latestQueryFormData?.viz_type;
+
+  const effectiveGroupBys = useMemo(() => {
+    if (!chartType || applicableGroupBys.length === 0) {
+      return [];
+    }
+
+    if (isChartWithoutGroupBy(chartType)) {
+      return [];
+    }
+
+    const chartFormData = chart?.latestQueryFormData;
+    if (!chartFormData) {
+      return applicableGroupBys;
+    }
+
+    const existingColumns = new Set<string>();
+
+    const existingGroupBy = Array.isArray(chartFormData.groupby)
+      ? chartFormData.groupby
+      : chartFormData.groupby
+        ? [chartFormData.groupby]
+        : [];
+    existingGroupBy.forEach((col: string) => existingColumns.add(col));
+
+    if (chartFormData.x_axis) {
+      existingColumns.add(chartFormData.x_axis);
+    }
+
+    const metrics = chartFormData.metrics || [];
+    metrics.forEach((metric: any) => {
+      if (typeof metric === 'string') {
+        existingColumns.add(metric);
+      } else if (metric && typeof metric === 'object' && 'column' in metric) {
+        const metricColumn = metric.column;
+        if (typeof metricColumn === 'string') {
+          existingColumns.add(metricColumn);
+        } else if (
+          metricColumn &&
+          typeof metricColumn === 'object' &&
+          'column_name' in metricColumn
+        ) {
+          existingColumns.add(metricColumn.column_name);
+        }
+      }
+    });
+
+    if (chartFormData.series) {
+      existingColumns.add(chartFormData.series);
+    }
+    if (chartFormData.entity) {
+      existingColumns.add(chartFormData.entity);
+    }
+    if (chartFormData.source) {
+      existingColumns.add(chartFormData.source);
+    }
+    if (chartFormData.target) {
+      existingColumns.add(chartFormData.target);
+    }
+
+    if (chartType === 'pivot_table_v2') {
+      const pivotColumns = chartFormData.groupbyColumns || [];
+      if (Array.isArray(pivotColumns)) {
+        pivotColumns.forEach((col: any) => {
+          if (typeof col === 'string') {
+            existingColumns.add(col);
+          } else if (col && typeof col === 'object' && 'column_name' in col) {
+            existingColumns.add(col.column_name);
+          }
+        });
+      }
+    }
+
+    if (chartType === 'box_plot') {
+      const boxPlotColumns = chartFormData.columns || [];
+      if (Array.isArray(boxPlotColumns)) {
+        boxPlotColumns.forEach((col: any) => {
+          if (typeof col === 'string') {
+            existingColumns.add(col);
+          } else if (col && typeof col === 'object' && 'column_name' in col) {
+            existingColumns.add(col.column_name);
+          }
+        });
+      }
+    }
+
+    return applicableGroupBys.filter(item => {
+      if (!item.customization?.column) return false;
+
+      let columnNames: string[] = [];
+      if (typeof item.customization.column === 'string') {
+        columnNames = [item.customization.column];
+      } else if (Array.isArray(item.customization.column)) {
+        columnNames = item.customization.column.filter(
+          col => typeof col === 'string' && col.trim() !== '',
+        );
+      } else if (
+        typeof item.customization.column === 'object' &&
+        item.customization.column !== null
+      ) {
+        const columnObj = item.customization.column as any;
+        const columnName =
+          columnObj.column_name || columnObj.name || String(columnObj);
+        if (columnName && columnName.trim() !== '') {
+          columnNames = [columnName];
+        }
+      }
+
+      return columnNames.length > 0;
+    });
+  }, [applicableGroupBys, chartType, chart]);
+
+  const groupByCount = effectiveGroupBys.length;
+
+  if (groupByCount === 0) {
+    return null;
+  }
+  const tooltipContent = (
+    <TooltipContent>
+      <div>
+        <SectionName>
+          {t('Chart Customization (%d)', applicableGroupBys.length)}
+        </SectionName>
+        <GroupByInfo>
+          {effectiveGroupBys.map(groupBy => (
+            <GroupByItem key={groupBy.id}>
+              <div>
+                {groupBy.customization?.name &&
+                groupBy.customization?.column ? (
+                  <>
+                    <GroupByName>{groupBy.customization.name}: </GroupByName>
+                    <GroupByValue>
+                      {getFilterValueForDisplay(groupBy.customization.column)}
+                    </GroupByValue>
+                  </>
+                ) : (
+                  groupBy.customization?.name || t('None')
+                )}
+              </div>
+            </GroupByItem>
+          ))}
+        </GroupByInfo>
+      </div>
+    </TooltipContent>
+  );
+
+  return (
+    <ClassNames>
+      {({ css }) => (
+        <Tooltip
+          title={tooltipContent}
+          visible={tooltipVisible}
+          onVisibleChange={setTooltipVisible}
+          placement="bottom"
+          overlayClassName={css`
+            .ant-tooltip-inner {
+              color: ${theme.colorText} !important;
+              background-color: ${theme.colorBgContainer} !important;
+              border: 1px solid ${theme.colorBorder} !important;
+              box-shadow: ${theme.boxShadow} !important;
+            }
+            .ant-tooltip-arrow::before {
+              background-color: ${theme.colorBgContainer} !important;
+              border-color: ${theme.colorBorder} !important;
+            }

Review Comment:
   Do we need this much `!important`? We have overlayStyle prop which might 
work better



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