Skip to content

Commit

Permalink
fix drag drop and select
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Mar 13, 2024
1 parent 9ac034d commit 1b53aa5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,26 @@ export const ManageColumnsModal = ({
);
};

const onDrop = (sourceIndex: any, destinationIndex: any) => {
const onDrop = (sourceIndex: any, destinationIndex: any): boolean => {
if (
typeof sourceIndex !== "number" ||
typeof destinationIndex !== "number"
) {
return false;
}

const result = Array.from(editedColumns);
const [removed] = result.splice(sourceIndex, 1);
result.splice(destinationIndex, 0, removed);
setEditedColumns(result);

// Assuming the operation is successful
return true;
};

const onSelect = (id: any, isVisible: any) => {
console.log(`Toggling visibility for ${id}: ${isVisible}`);

setEditedColumns(
editedColumns.map((col) => ({
...col,
Expand Down Expand Up @@ -127,8 +139,7 @@ export const ManageColumnsModal = ({
</Button>,
]}
>
{/* <DragDrop onDrop={(source, dest) => onDrop(source.index, dest?.index)}> */}
<DragDrop>
<DragDrop onDrop={(source, dest) => onDrop(source.index, dest?.index)}>
<Droppable>
<DataList aria-label={title} id="table-column-management" isCompact>
{editedColumns.map(({ id, label, isVisible }, index) => (
Expand All @@ -140,7 +151,7 @@ export const ManageColumnsModal = ({
<DataListCheck
aria-labelledby={`check-${id}`}
checked={isVisible}
onChange={(checked) => onSelect(id, checked)}
onChange={(e, checked) => onSelect(id, checked)}
/>
</DataListControl>
<DataListItemCells
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export const ManageColumnsToolbar = ({
<ToolbarItem variant="overflow-menu">
<OverflowMenu breakpoint="md">
<OverflowMenuGroup groupType="button" isPersistent>
<OverflowMenuItem>
<Button variant="primary">Action</Button>
</OverflowMenuItem>
<OverflowMenuItem isPersistent>
<Button variant="link" onClick={() => setIsOpen(true)}>
Manage columns
Expand Down

0 comments on commit 1b53aa5

Please sign in to comment.