Skip to content

Commit ec32bc4

Browse files
committed
✨ Upgrade @dnd-kit/sortable, refactor migration-targets
Upgrade `@dnd-kit` and `@dnd-kit/sortable` to latest. Refactor the migration-targets page and target card components. Simplified the components for more streamlined use on the custom migration targets page and on the analysis wizard target selection step. The migration-targets page layout updated to use `Gallery` instead of the custom grid. Signed-off-by: Scott J Dickerson <[email protected]>
1 parent a18b8a3 commit ec32bc4

File tree

10 files changed

+117
-183
lines changed

10 files changed

+117
-183
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"dependencies": {
2323
"@dnd-kit/core": "^6.3.1",
24-
"@dnd-kit/sortable": "^7.0.2",
24+
"@dnd-kit/sortable": "^10.0.0",
2525
"@hookform/resolvers": "^2.9.11",
2626
"@hot-loader/react-dom": "^17.0.2",
2727
"@patternfly/patternfly": "5.2.1",

client/src/app/components/target-card/target-card.tsx

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
DropdownItem,
88
Flex,
99
FlexItem,
10-
Button,
11-
ButtonVariant,
1210
Label,
1311
CardHeader,
1412
PanelMain,
@@ -18,7 +16,7 @@ import {
1816
StackItem,
1917
Bullseye,
2018
} from "@patternfly/react-core";
21-
import { GripVerticalIcon, InfoCircleIcon } from "@patternfly/react-icons";
19+
import { InfoCircleIcon } from "@patternfly/react-icons";
2220
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
2321
import { useTranslation } from "react-i18next";
2422

@@ -41,8 +39,8 @@ export interface TargetCardProps {
4139
) => void;
4240
onSelectedCardTargetChange?: (value: string) => void;
4341
selectedTargetLabels?: TargetLabel[];
44-
handleProps?: any;
4542
readOnly?: boolean;
43+
dndSortHandle?: React.ReactNode;
4644
onEdit?: () => void;
4745
onDelete?: () => void;
4846
}
@@ -60,7 +58,7 @@ export const TargetCard: React.FC<TargetCardProps> = ({
6058
selectedTargetLabels,
6159
onCardClick,
6260
onSelectedCardTargetChange,
63-
handleProps,
61+
dndSortHandle,
6462
onEdit,
6563
onDelete,
6664
}) => {
@@ -149,37 +147,20 @@ export const TargetCard: React.FC<TargetCardProps> = ({
149147
</CardHeader>
150148
<CardBody>
151149
<Flex>
152-
<FlexItem>
153-
{!readOnly && (
154-
<Button
155-
className="grabbable"
156-
id="drag-button"
157-
aria-label="drag button"
158-
variant={ButtonVariant.plain}
159-
{...handleProps}
160-
{...handleProps?.listeners}
161-
{...handleProps?.attributes}
162-
>
163-
<GripVerticalIcon />
164-
</Button>
165-
)}
166-
</FlexItem>
150+
<FlexItem>{dndSortHandle}</FlexItem>
167151
<FlexItem className={spacing.mlAuto}>
168-
{readOnly && target.custom ? (
169-
<Label color="grey">Custom</Label>
170-
) : (
171-
target.custom && (
172-
<KebabDropdown
173-
dropdownItems={[
174-
<DropdownItem key="edit-custom-card" onClick={onEdit}>
175-
{t("actions.edit")}
176-
</DropdownItem>,
177-
<DropdownItem key="delete-custom-card" onClick={onDelete}>
178-
{t("actions.delete")}
179-
</DropdownItem>,
180-
]}
181-
/>
182-
)
152+
{target.custom && readOnly && <Label color="grey">Custom</Label>}
153+
{target.custom && !readOnly && (
154+
<KebabDropdown
155+
dropdownItems={[
156+
<DropdownItem key="edit-custom-card" onClick={onEdit}>
157+
{t("actions.edit")}
158+
</DropdownItem>,
159+
<DropdownItem key="delete-custom-card" onClick={onDelete}>
160+
{t("actions.delete")}
161+
</DropdownItem>,
162+
]}
163+
/>
183164
)}
184165
</FlexItem>
185166
</Flex>

client/src/app/pages/migration-targets/components/dnd/grid.css

Lines changed: 0 additions & 53 deletions
This file was deleted.

client/src/app/pages/migration-targets/components/dnd/grid.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

client/src/app/pages/migration-targets/components/dnd/item.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
import React from "react";
22
import { useSortable } from "@dnd-kit/sortable";
33
import { CSS } from "@dnd-kit/utilities";
4-
import { Item } from "./item";
5-
interface SortableItemProps {
4+
import { Target } from "@app/api/models";
5+
import { TargetItem } from "./target-item";
6+
7+
interface SortableTargetItemProps {
68
style?: React.CSSProperties;
7-
id: number;
9+
target: Target;
810
onEdit?: () => void;
911
onDelete?: () => void;
1012
}
11-
export const SortableItem: React.FC<SortableItemProps> = (
12-
{ style, id, onEdit, onDelete },
13-
...props
14-
) => {
13+
14+
export const SortableTargetItem: React.FC<SortableTargetItemProps> = ({
15+
style,
16+
target,
17+
onEdit,
18+
onDelete,
19+
}) => {
1520
const {
1621
attributes,
1722
listeners,
1823
setNodeRef,
1924
transform,
2025
transition,
2126
setActivatorNodeRef,
22-
} = useSortable({ id: id });
27+
} = useSortable({ id: target.id });
2328

24-
const inlineStyles = {
29+
const itemStyles = {
2530
transform: CSS.Transform.toString(transform),
2631
transition: [transition].filter(Boolean).join(", "),
27-
height: 410,
28-
width: "20em",
2932
...style,
3033
} as React.CSSProperties;
3134

3235
return (
33-
<Item
36+
<TargetItem
3437
ref={setNodeRef}
35-
style={inlineStyles}
36-
handleProps={{
37-
ref: setActivatorNodeRef,
38-
listeners: listeners,
39-
attributes: attributes,
40-
}}
38+
style={itemStyles}
4139
onEdit={onEdit}
4240
onDelete={onDelete}
43-
{...props}
44-
id={id}
41+
target={target}
42+
activatorNodeRef={setActivatorNodeRef}
43+
{...attributes}
44+
{...listeners}
4545
/>
4646
);
4747
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { forwardRef } from "react";
2+
import { Button, ButtonVariant } from "@patternfly/react-core";
3+
import { GripVerticalIcon } from "@patternfly/react-icons";
4+
5+
import { TargetCard } from "@app/components/target-card/target-card";
6+
import { Target } from "@app/api/models";
7+
8+
interface TargetItemProps {
9+
target: Target;
10+
style?: React.CSSProperties;
11+
onEdit?: () => void;
12+
onDelete?: () => void;
13+
activatorNodeRef?: (element: HTMLElement | null) => void;
14+
}
15+
16+
export const TargetItem = forwardRef<HTMLDivElement, TargetItemProps>(
17+
(
18+
{ target, style, onEdit, onDelete, activatorNodeRef, ...draggableProps },
19+
draggableContainerRef
20+
) => {
21+
return (
22+
<div style={style} ref={draggableContainerRef}>
23+
<TargetCard
24+
item={target}
25+
dndSortHandle={
26+
<Button
27+
ref={activatorNodeRef}
28+
className="grabbable"
29+
id="drag-button"
30+
aria-label="drag button"
31+
variant={ButtonVariant.plain}
32+
{...draggableProps}
33+
>
34+
<GripVerticalIcon />
35+
</Button>
36+
}
37+
onEdit={onEdit}
38+
onDelete={onDelete}
39+
/>
40+
</div>
41+
);
42+
}
43+
);
44+
45+
TargetItem.displayName = "Item";

client/src/app/pages/migration-targets/migration-targets.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)