codeant-ai-for-open-source[bot] commented on code in PR #43275: URL: https://github.com/apache/superset/pull/43275#discussion_r3799902138
########## superset-frontend/src/dashboard/components/gridComponents/FilterHolder/FilterHolder.tsx: ########## @@ -0,0 +1,583 @@ +/** + * 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, useMemo, useState, ReactNode } from 'react'; +import cx from 'classnames'; +import { useDispatch, useSelector } from 'react-redux'; +import { ResizeCallback, ResizeStartCallback } from 're-resizable'; +import { css, useTheme } from '@apache-superset/core/theme'; +import { t } from '@apache-superset/core/translation'; +import { DataMask, Filter } from '@superset-ui/core'; +import { Button, Select } from '@superset-ui/core/components'; +import { Icons } from '@superset-ui/core/components/Icons'; +import PopoverDropdown from '@superset-ui/core/components/PopoverDropdown'; +import { FilterBarOrientation, LayoutItem, RootState } from 'src/dashboard/types'; +import { updateDataMask } from 'src/dataMask/actions'; +import { Draggable } from 'src/dashboard/components/dnd/DragDroppable'; +import DragHandle from 'src/dashboard/components/dnd/DragHandle'; +import HoverMenu from 'src/dashboard/components/menu/HoverMenu'; +import IconButton from 'src/dashboard/components/IconButton'; +import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu'; +import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton'; +import ResizableContainer from 'src/dashboard/components/resizable/ResizableContainer'; +import FilterControl from 'src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl'; +import { COLUMN_TYPE, ROW_TYPE } from 'src/dashboard/util/componentTypes'; +import { + GRID_BASE_UNIT, + GRID_MIN_COLUMN_COUNT, + GRID_MIN_ROW_UNITS, + GRID_COLUMN_COUNT, +} from 'src/dashboard/util/constants'; + +interface FilterHolderProps { + id: string; + parentId: string; + component: LayoutItem; + parentComponent: LayoutItem; + index: number; + depth: number; + editMode: boolean; + + // grid related + availableColumnCount: number; + columnWidth: number; + onResizeStart: ResizeStartCallback; + onResize: ResizeCallback; + onResizeStop: ResizeCallback; + + // dnd + deleteComponent: (id: string, parentId: string) => void; + updateComponents: (updates: Record<string, LayoutItem>) => void; + handleComponentDrop: (...args: unknown[]) => unknown; +} + +const FilterHolder = ({ + id, + parentId, + component, + parentComponent, + index, + depth, + availableColumnCount, + columnWidth, + onResizeStart, + onResize, + onResizeStop, + editMode, + deleteComponent, + updateComponents, + handleComponentDrop, +}: FilterHolderProps) => { + const theme = useTheme(); + const dispatch = useDispatch(); + + const [isFocused, setIsFocused] = useState(false); + const [stagedDataMask, setStagedDataMask] = useState<DataMask | null>(null); + + const nativeFilters = useSelector( + (state: RootState) => state.nativeFilters?.filters || {}, + ); + const dataMask = useSelector((state: RootState) => state.dataMask || {}); + + const filterId = component.meta?.filterId as string | undefined; + const filter = filterId ? (nativeFilters[filterId] as Filter | undefined) : undefined; + + const titlePosition = (component.meta?.titlePosition as 'top' | 'left') || 'top'; + const applyMode = (component.meta?.applyMode as 'instant' | 'manual') || 'instant'; + const buttonPlacement = + (component.meta?.buttonPlacement as 'bottom' | 'right' | 'stacked_right') || + 'bottom'; + + const filterWithDataMask = useMemo(() => { + if (!filter) return null; + return { + ...filter, + dataMask: stagedDataMask || dataMask[filter.id], + inCanvas: true, + } as Filter & { inCanvas: boolean }; + }, [filter, dataMask, stagedDataMask]); + + const updateMeta = useCallback( + (metaUpdates: Record<string, unknown>) => { + updateComponents({ + [component.id]: { + ...component, + meta: { + ...component.meta, + ...metaUpdates, + }, + }, + }); + }, + [component, updateComponents], + ); + + const handleChangeTitlePosition = useCallback( + (nextPosition: string) => { + updateMeta({ titlePosition: nextPosition }); + }, + [updateMeta], + ); + + const handleChangeApplyMode = useCallback( + (nextApplyMode: string) => { + setStagedDataMask(null); + updateMeta({ applyMode: nextApplyMode }); + }, + [updateMeta], + ); + + const handleChangeButtonPlacement = useCallback( + (nextPlacement: string) => { + updateMeta({ buttonPlacement: nextPlacement }); + }, + [updateMeta], + ); + + const handleSelectFilter = useCallback( + (nextFilterId: string) => { + setStagedDataMask(null); + updateMeta({ filterId: nextFilterId }); + }, + [updateMeta], + ); + + const handleFilterSelectionChange = useCallback( + (targetFilter: Filter, nextDataMask: DataMask) => { + if (applyMode === 'manual') { + setStagedDataMask(nextDataMask); + } else { + dispatch(updateDataMask(targetFilter.id, nextDataMask)); + } + }, + [applyMode, dispatch], + ); + + const handleApplyStagedFilter = useCallback(() => { + if (filter && stagedDataMask) { + dispatch(updateDataMask(filter.id, stagedDataMask)); + setStagedDataMask(null); + } + }, [dispatch, filter, stagedDataMask]); + + const handleClearStagedFilter = useCallback(() => { + if (filter) { + const clearedValue = + filter.filterType === 'filter_range' ? [null, null] : undefined; + const clearedMask: DataMask = { + filterState: { value: clearedValue }, + extraFormData: {}, + }; + dispatch(updateDataMask(filter.id, clearedMask)); + setStagedDataMask(null); + } + }, [dispatch, filter]); + + const handleDelete = useCallback(() => { + deleteComponent(id, parentId); + }, [deleteComponent, id, parentId]); + + const availableFilters = useMemo( + () => + Object.values(nativeFilters).map((f: Filter) => ({ + label: f.name || f.id, + value: f.id, + })), + [nativeFilters], + ); + + const widthMultiple = + parentComponent.type === COLUMN_TYPE + ? parentComponent.meta.width || GRID_MIN_COLUMN_COUNT + : component.meta.width || GRID_MIN_COLUMN_COUNT; + + const labelOptions = useMemo( + () => [ + { value: 'top', label: t('Label: Top') }, + { value: 'left', label: t('Label: Left') }, + ], + [], + ); + + const applyOptions = useMemo( + () => [ + { value: 'instant', label: t('Apply: Instant') }, + { value: 'manual', label: t('Apply: Button') }, + ], + [], + ); + + const buttonPlacementOptions = useMemo( + () => [ + { value: 'bottom', label: t('Buttons: Bottom') }, + { value: 'right', label: t('Buttons: Right (Inline)') }, + { value: 'stacked_right', label: t('Buttons: Right (Stacked)') }, + ], + [], + ); + + const popoverMenuItems = useMemo( + () => [ + <PopoverDropdown + key="title-position" + id={`${component.id}-title-position`} + options={labelOptions} + value={titlePosition} + onChange={val => handleChangeTitlePosition(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.TagsOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + <PopoverDropdown + key="apply-mode" + id={`${component.id}-apply-mode`} + options={applyOptions} + value={applyMode} + onChange={val => handleChangeApplyMode(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.CheckCircleOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ...(applyMode === 'manual' + ? [ + <PopoverDropdown + key="button-placement" + id={`${component.id}-button-placement`} + options={buttonPlacementOptions} + value={buttonPlacement} + onChange={val => handleChangeButtonPlacement(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.AppstoreOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ] + : []), + ...(availableFilters.length > 0 + ? [ + <PopoverDropdown + key="filter-binding" + id={`${component.id}-filter-binding`} + options={availableFilters} + value={filterId || ''} + onChange={val => handleSelectFilter(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;`}> + <Icons.FilterOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ] + : []), + ], + [ + availableFilters, + component.id, + filterId, + handleChangeApplyMode, + handleChangeButtonPlacement, + handleChangeTitlePosition, + handleSelectFilter, + applyMode, + applyOptions, + buttonPlacement, + buttonPlacementOptions, + labelOptions, + titlePosition, + ], + ); + + const renderChild = useCallback( + ({ dragSourceRef }) => ( + <ResizableContainer + id={component.id} + adjustableWidth={parentComponent.type === ROW_TYPE} + adjustableHeight + widthStep={columnWidth} + widthMultiple={widthMultiple} + heightStep={GRID_BASE_UNIT} + heightMultiple={component.meta.height ?? GRID_MIN_ROW_UNITS} + minWidthMultiple={GRID_MIN_COLUMN_COUNT} + minHeightMultiple={GRID_MIN_ROW_UNITS} + maxWidthMultiple={Math.min( + availableColumnCount + widthMultiple, + GRID_COLUMN_COUNT, + )} + onResizeStart={onResizeStart} + onResize={onResize} + onResizeStop={onResizeStop} + editMode={editMode} + > + <WithPopoverMenu + isFocused={isFocused} + onChangeFocus={setIsFocused} + disableClick + menuItems={popoverMenuItems} + editMode={editMode} + style={{ width: '100%', height: '100%' }} + > + <div + ref={dragSourceRef} + data-test="dashboard-component-filter-holder" + className={cx( + 'dashboard-component', + 'dashboard-component-filter-holder', + titlePosition === 'left' && 'dashboard-component-filter-holder--label-left', + )} + css={css` + background: ${theme.colorBgContainer}; + border-radius: ${theme.borderRadius}px; + padding: 4px ${theme.sizeUnit * 2}px; + height: 100%; + min-height: 32px; + display: flex; + flex-direction: column; + justifyContent: center; Review Comment: **Suggestion:** The CSS template uses `justifyContent` instead of the CSS property `justify-content`. Browsers ignore this declaration, so the filter holder and its inner control container are not vertically centered as intended, producing incorrect layout for short canvas filters. [css layout issue] <details> <summary><b>Severity Level:</b> Minor ๐งน</summary> ```mdx - โ ๏ธ Canvas filter content is not vertically centered. - โ ๏ธ Short filters can appear misaligned within their cards. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c4a82650b558439f9799c3fb746098c1&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=c4a82650b558439f9799c3fb746098c1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <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/gridComponents/FilterHolder/FilterHolder.tsx **Line:** 359:359 **Comment:** *Css Layout Issue: The CSS template uses `justifyContent` instead of the CSS property `justify-content`. Browsers ignore this declaration, so the filter holder and its inner control container are not vertically centered as intended, producing incorrect layout for short canvas filters. 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%2F43275&comment_hash=953785f249acf1cc2a36919ec91fdcc833f7afcbe1a98a173c74209b122434e5&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43275&comment_hash=953785f249acf1cc2a36919ec91fdcc833f7afcbe1a98a173c74209b122434e5&reaction=dislike'>๐</a> ########## superset-frontend/src/dashboard/components/resizable/ResizableContainer.tsx: ########## @@ -178,6 +178,11 @@ const StyledResizable = styled(Resizable)` & .resizable-container-handle--bottom { bottom: 0 !important; + left: 0 !important; + width: 100% !important; + height: 12px !important; + cursor: row-resize !important; + z-index: 30 !important; } Review Comment: **Suggestion:** This makes the bottom resize handle a 12-pixel, full-width, high-z-index overlay for every component when resizing is enabled. On short filter cards, the strip covers controls and buttons at the bottom edge, so clicks are interpreted as resize gestures instead of activating the control. Restrict the enlarged hit area to an explicit resize interaction region or avoid placing it over content controls. [css layout issue] <details> <summary><b>Severity Level:</b> Major โ ๏ธ</summary> ```mdx - โ ๏ธ Edit-mode canvas buttons near bottoms become hard to click. - โ ๏ธ Bottom resize gestures can intercept filter interactions. - โ ๏ธ Small-height components are affected most visibly. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dce7308b6c324a878a2e434e69d92577&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=dce7308b6c324a878a2e434e69d92577&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <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/resizable/ResizableContainer.tsx **Line:** 179:186 **Comment:** *Css Layout Issue: This makes the bottom resize handle a 12-pixel, full-width, high-z-index overlay for every component when resizing is enabled. On short filter cards, the strip covers controls and buttons at the bottom edge, so clicks are interpreted as resize gestures instead of activating the control. Restrict the enlarged hit area to an explicit resize interaction region or avoid placing it over content controls. 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%2F43275&comment_hash=3fc11e324c41395a0eb89d492138354a37bbc9b63dba5502d8c9dea40bbb9d77&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43275&comment_hash=3fc11e324c41395a0eb89d492138354a37bbc9b63dba5502d8c9dea40bbb9d77&reaction=dislike'>๐</a> ########## superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.tsx: ########## @@ -219,38 +328,30 @@ export default function getControlItemsMap({ }, }); } - if (controlItem.config.resetConfig) { - setNativeFilterFieldValues(form, filterId, { - defaultDataMask: null, - }); - } - formChanged(); - forceUpdate(); + updateValue(checked); Review Comment: **Suggestion:** `Checkbox` is re-exported from Ant Design, whose `onChange` callback receives a change event rather than a boolean. Storing `checked` directly therefore writes the event object into `controlValues` instead of the checkbox state, causing invalid filter configuration values. Use the event's checked property before calling `updateValue` (and when updating `requiredFirst`). [type error] <details> <summary><b>Severity Level:</b> Major โ ๏ธ</summary> ```mdx - โ Render-trigger checkbox values become invalid objects. - โ Native-filter control configuration saves incorrect state. - โ ๏ธ Required-first settings can also persist event objects. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b54cae6906724b61962fc3f335b86c38&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=b54cae6906724b61962fc3f335b86c38&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <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:** 331:331 **Comment:** *Type Error: `Checkbox` is re-exported from Ant Design, whose `onChange` callback receives a change event rather than a boolean. Storing `checked` directly therefore writes the event object into `controlValues` instead of the checkbox state, causing invalid filter configuration values. Use the event's checked property before calling `updateValue` (and when updating `requiredFirst`). 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%2F43275&comment_hash=3b7ba136266d2dfd69042779afe432490bd964951de95beb1b535e368d388215&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43275&comment_hash=3b7ba136266d2dfd69042779afe432490bd964951de95beb1b535e368d388215&reaction=dislike'>๐</a> ########## superset-frontend/src/dashboard/components/gridComponents/FilterHolder/FilterHolder.tsx: ########## @@ -0,0 +1,583 @@ +/** + * 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, useMemo, useState, ReactNode } from 'react'; +import cx from 'classnames'; +import { useDispatch, useSelector } from 'react-redux'; +import { ResizeCallback, ResizeStartCallback } from 're-resizable'; +import { css, useTheme } from '@apache-superset/core/theme'; +import { t } from '@apache-superset/core/translation'; +import { DataMask, Filter } from '@superset-ui/core'; +import { Button, Select } from '@superset-ui/core/components'; +import { Icons } from '@superset-ui/core/components/Icons'; +import PopoverDropdown from '@superset-ui/core/components/PopoverDropdown'; +import { FilterBarOrientation, LayoutItem, RootState } from 'src/dashboard/types'; +import { updateDataMask } from 'src/dataMask/actions'; +import { Draggable } from 'src/dashboard/components/dnd/DragDroppable'; +import DragHandle from 'src/dashboard/components/dnd/DragHandle'; +import HoverMenu from 'src/dashboard/components/menu/HoverMenu'; +import IconButton from 'src/dashboard/components/IconButton'; +import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu'; +import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton'; +import ResizableContainer from 'src/dashboard/components/resizable/ResizableContainer'; +import FilterControl from 'src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl'; +import { COLUMN_TYPE, ROW_TYPE } from 'src/dashboard/util/componentTypes'; +import { + GRID_BASE_UNIT, + GRID_MIN_COLUMN_COUNT, + GRID_MIN_ROW_UNITS, + GRID_COLUMN_COUNT, +} from 'src/dashboard/util/constants'; + +interface FilterHolderProps { + id: string; + parentId: string; + component: LayoutItem; + parentComponent: LayoutItem; + index: number; + depth: number; + editMode: boolean; + + // grid related + availableColumnCount: number; + columnWidth: number; + onResizeStart: ResizeStartCallback; + onResize: ResizeCallback; + onResizeStop: ResizeCallback; + + // dnd + deleteComponent: (id: string, parentId: string) => void; + updateComponents: (updates: Record<string, LayoutItem>) => void; + handleComponentDrop: (...args: unknown[]) => unknown; +} + +const FilterHolder = ({ + id, + parentId, + component, + parentComponent, + index, + depth, + availableColumnCount, + columnWidth, + onResizeStart, + onResize, + onResizeStop, + editMode, + deleteComponent, + updateComponents, + handleComponentDrop, +}: FilterHolderProps) => { + const theme = useTheme(); + const dispatch = useDispatch(); + + const [isFocused, setIsFocused] = useState(false); + const [stagedDataMask, setStagedDataMask] = useState<DataMask | null>(null); + + const nativeFilters = useSelector( + (state: RootState) => state.nativeFilters?.filters || {}, + ); + const dataMask = useSelector((state: RootState) => state.dataMask || {}); + + const filterId = component.meta?.filterId as string | undefined; + const filter = filterId ? (nativeFilters[filterId] as Filter | undefined) : undefined; + + const titlePosition = (component.meta?.titlePosition as 'top' | 'left') || 'top'; + const applyMode = (component.meta?.applyMode as 'instant' | 'manual') || 'instant'; + const buttonPlacement = + (component.meta?.buttonPlacement as 'bottom' | 'right' | 'stacked_right') || + 'bottom'; + + const filterWithDataMask = useMemo(() => { + if (!filter) return null; + return { + ...filter, + dataMask: stagedDataMask || dataMask[filter.id], + inCanvas: true, + } as Filter & { inCanvas: boolean }; + }, [filter, dataMask, stagedDataMask]); + + const updateMeta = useCallback( + (metaUpdates: Record<string, unknown>) => { + updateComponents({ + [component.id]: { + ...component, + meta: { + ...component.meta, + ...metaUpdates, + }, + }, + }); + }, + [component, updateComponents], + ); + + const handleChangeTitlePosition = useCallback( + (nextPosition: string) => { + updateMeta({ titlePosition: nextPosition }); + }, + [updateMeta], + ); + + const handleChangeApplyMode = useCallback( + (nextApplyMode: string) => { + setStagedDataMask(null); + updateMeta({ applyMode: nextApplyMode }); + }, + [updateMeta], + ); + + const handleChangeButtonPlacement = useCallback( + (nextPlacement: string) => { + updateMeta({ buttonPlacement: nextPlacement }); + }, + [updateMeta], + ); + + const handleSelectFilter = useCallback( + (nextFilterId: string) => { + setStagedDataMask(null); + updateMeta({ filterId: nextFilterId }); + }, + [updateMeta], + ); + + const handleFilterSelectionChange = useCallback( + (targetFilter: Filter, nextDataMask: DataMask) => { + if (applyMode === 'manual') { + setStagedDataMask(nextDataMask); + } else { + dispatch(updateDataMask(targetFilter.id, nextDataMask)); + } + }, + [applyMode, dispatch], + ); + + const handleApplyStagedFilter = useCallback(() => { + if (filter && stagedDataMask) { + dispatch(updateDataMask(filter.id, stagedDataMask)); + setStagedDataMask(null); + } + }, [dispatch, filter, stagedDataMask]); + + const handleClearStagedFilter = useCallback(() => { + if (filter) { + const clearedValue = + filter.filterType === 'filter_range' ? [null, null] : undefined; + const clearedMask: DataMask = { + filterState: { value: clearedValue }, + extraFormData: {}, + }; + dispatch(updateDataMask(filter.id, clearedMask)); + setStagedDataMask(null); + } + }, [dispatch, filter]); + + const handleDelete = useCallback(() => { + deleteComponent(id, parentId); + }, [deleteComponent, id, parentId]); + + const availableFilters = useMemo( + () => + Object.values(nativeFilters).map((f: Filter) => ({ + label: f.name || f.id, + value: f.id, + })), + [nativeFilters], + ); + + const widthMultiple = + parentComponent.type === COLUMN_TYPE + ? parentComponent.meta.width || GRID_MIN_COLUMN_COUNT + : component.meta.width || GRID_MIN_COLUMN_COUNT; + + const labelOptions = useMemo( + () => [ + { value: 'top', label: t('Label: Top') }, + { value: 'left', label: t('Label: Left') }, + ], + [], + ); + + const applyOptions = useMemo( + () => [ + { value: 'instant', label: t('Apply: Instant') }, + { value: 'manual', label: t('Apply: Button') }, + ], + [], + ); + + const buttonPlacementOptions = useMemo( + () => [ + { value: 'bottom', label: t('Buttons: Bottom') }, + { value: 'right', label: t('Buttons: Right (Inline)') }, + { value: 'stacked_right', label: t('Buttons: Right (Stacked)') }, + ], + [], + ); + + const popoverMenuItems = useMemo( + () => [ + <PopoverDropdown + key="title-position" + id={`${component.id}-title-position`} + options={labelOptions} + value={titlePosition} + onChange={val => handleChangeTitlePosition(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.TagsOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + <PopoverDropdown + key="apply-mode" + id={`${component.id}-apply-mode`} + options={applyOptions} + value={applyMode} + onChange={val => handleChangeApplyMode(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.CheckCircleOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ...(applyMode === 'manual' + ? [ + <PopoverDropdown + key="button-placement" + id={`${component.id}-button-placement`} + options={buttonPlacementOptions} + value={buttonPlacement} + onChange={val => handleChangeButtonPlacement(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px;`}> + <Icons.AppstoreOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ] + : []), + ...(availableFilters.length > 0 + ? [ + <PopoverDropdown + key="filter-binding" + id={`${component.id}-filter-binding`} + options={availableFilters} + value={filterId || ''} + onChange={val => handleSelectFilter(String(val))} + renderButton={(opt: { label: ReactNode }) => ( + <span css={css`display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;`}> + <Icons.FilterOutlined iconSize="s" /> + {opt.label} + </span> + )} + />, + ] + : []), + ], + [ + availableFilters, + component.id, + filterId, + handleChangeApplyMode, + handleChangeButtonPlacement, + handleChangeTitlePosition, + handleSelectFilter, + applyMode, + applyOptions, + buttonPlacement, + buttonPlacementOptions, + labelOptions, + titlePosition, + ], + ); + + const renderChild = useCallback( + ({ dragSourceRef }) => ( + <ResizableContainer + id={component.id} + adjustableWidth={parentComponent.type === ROW_TYPE} + adjustableHeight + widthStep={columnWidth} + widthMultiple={widthMultiple} + heightStep={GRID_BASE_UNIT} + heightMultiple={component.meta.height ?? GRID_MIN_ROW_UNITS} + minWidthMultiple={GRID_MIN_COLUMN_COUNT} + minHeightMultiple={GRID_MIN_ROW_UNITS} + maxWidthMultiple={Math.min( + availableColumnCount + widthMultiple, + GRID_COLUMN_COUNT, + )} + onResizeStart={onResizeStart} + onResize={onResize} + onResizeStop={onResizeStop} + editMode={editMode} + > + <WithPopoverMenu + isFocused={isFocused} + onChangeFocus={setIsFocused} + disableClick + menuItems={popoverMenuItems} + editMode={editMode} + style={{ width: '100%', height: '100%' }} + > + <div + ref={dragSourceRef} + data-test="dashboard-component-filter-holder" + className={cx( + 'dashboard-component', + 'dashboard-component-filter-holder', + titlePosition === 'left' && 'dashboard-component-filter-holder--label-left', + )} + css={css` + background: ${theme.colorBgContainer}; + border-radius: ${theme.borderRadius}px; + padding: 4px ${theme.sizeUnit * 2}px; + height: 100%; + min-height: 32px; + display: flex; + flex-direction: column; + justifyContent: center; + box-sizing: border-box; + border: 1px solid ${editMode ? theme.colorBorder : 'transparent'}; + overflow: visible !important; + position: relative; + z-index: 10; + &:focus-within { + z-index: 100; + } + + /* Reset Ant Form Item spacing so vertically shrunk filters fit cleanly */ + .ant-form-item { + margin-bottom: 0 !important; + margin: 0 !important; + width: 100%; + } + .ant-form-item-control-input { + min-height: unset !important; + } + .ant-form-item-label { + padding-bottom: 2px !important; + } + + .hover-menu--top { + display: flex; + flex-direction: row; + align-items: center; + gap: ${theme.sizeUnit}px; + padding: 2px ${theme.sizeUnit}px; + background: ${theme.colorBgContainer}; + border: 1px solid ${theme.colorBorderSecondary}; + border-radius: ${theme.borderRadius}px; + box-shadow: ${theme.boxShadowTertiary || '0 2px 8px rgba(0,0,0,0.08)'}; + right: 8px !important; + left: auto !important; + transform: none !important; + top: -12px !important; + z-index: 12; + } + `} + > + {editMode && ( + <HoverMenu position="top"> + <DragHandle position="top" /> + <IconButton + onClick={() => setIsFocused(true)} + icon={<Icons.SettingOutlined iconSize="m" />} + /> + <DeleteComponentButton onDelete={handleDelete} /> + </HoverMenu> + )} + + {filterWithDataMask ? ( + <div + css={css` + width: 100%; + height: 100%; + display: flex; + flex-direction: ${buttonPlacement === 'bottom' + ? 'column' + : 'row'}; + align-items: ${buttonPlacement === 'bottom' + ? 'stretch' + : 'center'}; + justifyContent: center; + gap: ${theme.sizeUnit}px; + `} + > + <div + css={css` + flex: 1; + min-width: 0; + width: 100%; + `} + > + <FilterControl + filter={filterWithDataMask} + orientation={ + titlePosition === 'left' + ? FilterBarOrientation.Horizontal + : FilterBarOrientation.Vertical + } + inView + onFilterSelectionChange={handleFilterSelectionChange} + /> Review Comment: **Suggestion:** The canvas passes the data mask only through `filter.dataMask` and omits `dataMaskSelected`. `FilterValue` uses `dataMaskSelected` to resolve cascading-parent dependencies and readiness, so a canvas-bound filter with dependencies will fetch without its parent selections or remain in the wrong readiness state. Pass the current data-mask map, including staged state where appropriate, through the expected prop. [api mismatch] <details> <summary><b>Severity Level:</b> Major โ ๏ธ</summary> ```mdx - โ Cascading canvas filters omit parent selections. - โ Child filter option requests use incomplete dependencies. - โ ๏ธ Canvas readiness can remain incorrect during parent initialization. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aa276550e9f44a9186472bdfe5b14c2a&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=aa276550e9f44a9186472bdfe5b14c2a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <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/gridComponents/FilterHolder/FilterHolder.tsx **Line:** 434:443 **Comment:** *Api Mismatch: The canvas passes the data mask only through `filter.dataMask` and omits `dataMaskSelected`. `FilterValue` uses `dataMaskSelected` to resolve cascading-parent dependencies and readiness, so a canvas-bound filter with dependencies will fetch without its parent selections or remain in the wrong readiness state. Pass the current data-mask map, including staged state where appropriate, through the expected prop. 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%2F43275&comment_hash=3b38ef3ccf0a703043afb399c807399360057b450610b032aa9eb1e72fc293d9&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43275&comment_hash=3b38ef3ccf0a703043afb399c807399360057b450610b032aa9eb1e72fc293d9&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]
