Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 1363x 1363x 1363x 1363x 54x 1363x 2110x 9x | import {
SimulationObjectRetrieveRead
} from "@/api/apiStore.gen";
import SelectInput from "@/ahuora-design-system/inputs/SelectInput";
import { Label } from "@/ahuora-design-system/ui/label";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import { useSearchParam } from "@/hooks/searchParams";
import {
ArrowRightToLine,
PlusCircle,
Trash2,
Unlink
} from "lucide-react";
type OptionsObject = {
name: string;
id: number;
};
type ConnectionProps = {
displayName: string; // connection label
currentObject?: SimulationObjectRetrieveRead; // current connection simulation object, so we can go to the object
current?: number; // current connection id
options: OptionsObject[];
onConnectionChange: (id: number) => void;
onDisconnect: () => void;
onAdd?: () => void;
onDelete?: () => void;
};
export function Connection(props: ConnectionProps) {
const {
displayName,
currentObject,
current,
options,
onConnectionChange,
onDisconnect,
onAdd,
onDelete,
} = props;
const labelId = `displayName-${displayName}`;
const [searchParam, setSearchParam] = useSearchParam("object");
const goToObject = () => {
// switch to that object
setSearchParam(currentObject?.id.toString());
};
return (
<div className="w-full">
<div className="flex flex-row items-center justify-between">
<Label htmlFor={labelId}>{displayName}</Label>
<div className="flex flex-row items-center gap-2">
{currentObject && (
<ToolTipCover
content={`View ${currentObject.componentName} details.`}
asChild
>
<div
className="cursor-pointer ml-2 hover:opacity-50"
onClick={goToObject}
aria-label={`View ${displayName} details`}
>
<ArrowRightToLine size={16} />
</div>
</ToolTipCover>
)}
{current && (
<ToolTipCover content={`Disconnect ${displayName}.`} asChild>
<div
onClick={onDisconnect}
aria-label={`Disconnect ${displayName}.`}
>
<Unlink
size={16}
className="h-4 w-4 text-red-500 cursor-pointer ml-2 hover:opacity-50"
/>
</div>
</ToolTipCover>
)}
{onAdd && !current && (
<ToolTipCover content={`Add a new ${displayName}.`} asChild>
<div onClick={onAdd} aria-label={`Add a new ${displayName}.`}>
<PlusCircle
size={16}
className="h-4 w-4 text-green-500 cursor-pointer ml-2 hover:opacity-50"
/>
</div>
</ToolTipCover>
)}
{onDelete && (
<ToolTipCover content={`Delete ${displayName}.`} asChild>
<div onClick={onDelete} aria-label={`Delete ${displayName}.`}>
<Trash2
size={16}
className="h-4 w-4 text-red-500 cursor-pointer ml-2 hover:opacity-50"
/>
</div>
</ToolTipCover>
)}
</div>
</div>
<div className="flex flex-row">
<SelectInput
id={labelId}
disabled={options.length == 0}
title={`Select ${displayName}`}
value={current ? current.toString() : ""}
data={options.map((option) => ({
value: option.id.toString(),
label: option.name,
}))}
handleChange={(value) => onConnectionChange(parseInt(value))}
/>
</div>
</div>
);
} |