bito-code-review[bot] commented on code in PR #37880:
URL: https://github.com/apache/superset/pull/37880#discussion_r2838660714
##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx:
##########
@@ -45,41 +49,55 @@ export type DndSelectLabelProps = {
displayGhostButton?: boolean;
onClickGhostButton: () => void;
isLoading?: boolean;
+ // For sortable items - the type string and count to generate sortable IDs
+ sortableType?: string;
+ itemCount?: number;
};
export default function DndSelectLabel({
displayGhostButton = true,
accept,
valuesRenderer,
isLoading,
+ sortableType,
+ itemCount = 0,
...props
}: DndSelectLabelProps) {
const canDropProp = props.canDrop;
const canDropValueProp = props.canDropValue;
+ const acceptTypes = useMemo(
+ () => (Array.isArray(accept) ? accept : [accept]),
+ [accept],
+ );
+
const dropValidator = useCallback(
(item: DatasourcePanelDndItem) =>
canDropProp(item) && (canDropValueProp?.(item.value) ?? true),
[canDropProp, canDropValueProp],
);
- const [{ isOver, canDrop }, datasourcePanelDrop] = useDrop({
- accept: isLoading ? [] : accept,
-
- drop: (item: DatasourcePanelDndItem) => {
- props.onDrop(item);
- props.onDropValue?.(item.value);
+ const { setNodeRef, isOver, active } = useDroppable({
+ id: `dropzone-${props.name}`,
+ disabled: isLoading,
+ data: {
+ accept: acceptTypes,
+ onDrop: props.onDrop,
+ onDropValue: props.onDropValue,
},
-
- canDrop: dropValidator,
-
- collect: monitor => ({
- isOver: monitor.isOver(),
- canDrop: monitor.canDrop(),
- type: monitor.getItemType(),
- }),
});
+ // Check if the active dragged item can be dropped here
+ const canDrop = useMemo(() => {
+ if (!active?.data.current) return false;
+ const activeData = active.data.current as { type: string; value: unknown };
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Logic Bug: Incorrect canDrop for sortable drags</b></div>
<div id="fix">
The canDrop logic evaluates all drags, including internal sortable reorders,
but sortable drags (with dragIndex) are handled separately in ExploreDndContext
and shouldn't show as droppable here.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
const activeData = active.data.current as { type: string; value: unknown
};
// Skip sortable drags (internal reordering) - they have dragIndex
if ('dragIndex' in activeData) return false;
````
</div>
</details>
</div>
<small><i>Code Review Run #4b724e</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.test.tsx:
##########
@@ -29,35 +29,66 @@ test('renders with default props', async () => {
onShiftOptions={jest.fn()}
label="Option"
/>,
- { useDnd: true },
+ { useDndKit: true },
);
expect(container).toBeInTheDocument();
expect(await screen.findByRole('img', { name: 'close'
})).toBeInTheDocument();
});
-test('triggers onShiftOptions on drop', async () => {
- const onShiftOptions = jest.fn();
+test('renders label correctly', async () => {
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing drag-and-drop test coverage</b></div>
<div id="fix">
The component uses @dnd-kit for drag and drop, but the test suite no longer
covers this behavior after migration. Consider adding a test that simulates
dragging an option to trigger onShiftOptions, as this is core functionality for
reordering columns.
</div>
</div>
<small><i>Code Review Run #4b724e</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]