Skip to content

Commit

Permalink
chore: add connection item display and fix types for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Oct 2, 2024
1 parent 2f6ab9a commit 82a3629
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
30 changes: 30 additions & 0 deletions src/components/Connections/ConnectionIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Icon } from "@flanksource-ui/ui/Icons/Icon";
import { useMemo } from "react";
import { Connection } from "./ConnectionFormModal";
import { connectionTypes } from "./connectionTypes";

type ConnectionIconProps = {
connection: Pick<Connection, "type" | "name" | "id">;
showLabel?: boolean;
};
export default function ConnectionIcon({
connection,
showLabel = false
}: ConnectionIconProps) {
const icon = useMemo(() => {
return connectionTypes.find((item) => item.value === connection.type)?.icon;
}, [connection.type]);

return (
<div className="flex flex-row items-center gap-1">
{typeof icon === "string" ? (
<Icon name={icon} className="h-5" />
) : (
// if not a string, it's a react component
// eslint-disable-next-line react/jsx-no-useless-fragment
icon && <>{icon}</>
)}
{showLabel && <span>{connection.name}</span>}
</div>
);
}
9 changes: 2 additions & 7 deletions src/components/Connections/ConnectionLink.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getConnectionByID } from "@flanksource-ui/api/services/connections";
import { Icon } from "@flanksource-ui/ui/Icons/Icon";
import TextSkeletonLoader from "@flanksource-ui/ui/SkeletonLoader/TextSkeletonLoader";
import { useQuery } from "@tanstack/react-query";
import { Connection } from "./ConnectionFormModal";
import ConnectionIcon from "./ConnectionIcon";

type ConnectionLinkProps = {
connection?: Pick<Connection, "name" | "type" | "id">;
Expand All @@ -29,10 +29,5 @@ export default function ConnectionLink({
return null;
}

return (
<div className="flex flex-row items-center space-x-2">
<Icon name={connectionData.type} className="h-auto w-6" />
<div>{connectionData.name}</div>
</div>
);
return <ConnectionIcon showLabel connection={connectionData} />;
}
2 changes: 1 addition & 1 deletion src/components/Connections/connectionTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const enum ConnectionValueType {
export type ConnectionType = {
title: string;
value: ConnectionValueType;
icon?: React.ReactNode | string | null;
icon?: JSX.Element | string | null;
fields: ConnectionFormFields[];
convertToFormSpecificValue?: (data: Record<string, string>) => Connection;
preSubmitConverter?: (data: Record<string, string>) => object;
Expand Down

0 comments on commit 82a3629

Please sign in to comment.