Skip to content

Commit

Permalink
Merge pull request #173 from srl-labs/feat/ui-create-sheet
Browse files Browse the repository at this point in the history
Feat/UI create sheet
  • Loading branch information
carlmontanari authored Aug 29, 2024
2 parents a102a13 + 2359fda commit c8d758f
Show file tree
Hide file tree
Showing 14 changed files with 2,375 additions and 7 deletions.
155 changes: 154 additions & 1 deletion ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
},
"dependencies": {
"@hey-api/client-fetch": "^0.2.3",
"@hookform/resolvers": "^3.9.0",
"@kubernetes/client-node": "^0.21.0",
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@tanstack/react-query": "^5.51.23",
"@tanstack/react-table": "^8.20.1",
"@xyflow/react": "^12.0.4",
Expand All @@ -30,11 +35,13 @@
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.53.0",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"undici": "^6.19.7",
"use-resize-observer": "^9.1.0",
"web-worker": "^1.3.0"
"web-worker": "^1.3.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand Down
122 changes: 122 additions & 0 deletions ui/src/components/pullsecrets-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { listNamespacedPullSecrets } from "@/lib/kubernetes";
import { useQuery } from "@tanstack/react-query";
import { ChevronDown, TriangleAlert } from "lucide-react";
import type { ReactElement } from "react";

interface PullSecretsSelectorProps {
readonly namespace: string;
readonly pullSecrets: string[];
readonly placeholder: string;
readonly setPullSecrets: (secrets: string[]) => void;
}

function renderDropdownMenuTrigger(
data: string[],
secrets: string[],
namespace: string,
placeholder: string,
): ReactElement {
if (data.length === 0) {
return (
<>
<span>No pull secrets in namespace {namespace}</span>
<TriangleAlert className="ml-2 h-4 w-4 fill-red-500 opacity-50" />
</>
);
}

if (secrets.length > 0) {
return <span>{secrets.join(", ")}</span>;
}

return (
<>
<span>{placeholder}</span>
</>
);
}

export function PullSecretsSelector(props: PullSecretsSelectorProps): ReactElement {
const { namespace, placeholder, pullSecrets, setPullSecrets } = props;

const { data, isPending, isError, error } = useQuery<string[], Error>({
queryFn: async () => {
const response = await listNamespacedPullSecrets(namespace);

return JSON.parse(response);
},
queryKey: ["pullsecrets", { namespace: namespace }],
});

if (isPending) {
return (
<div className="flex justify-end">
<Button
className="flex w-full justify-between"
variant="outline"
>
<span>Loading...</span>
<ChevronDown className="ml-2 h-4 w-4 opacity-50" />
</Button>
</div>
);
}

if (isError) {
return <span>Error: {error.message}</span>;
}

return (
<DropdownMenu>
<DropdownMenuTrigger
asChild={true}
className="col-span-3"
>
<div className="flex justify-end">
<Button
className="flex w-full justify-between"
variant="outline"
>
{renderDropdownMenuTrigger(data, pullSecrets, namespace, placeholder)}
<ChevronDown className="ml-2 h-4 w-4 opacity-50" />
</Button>
</div>
</DropdownMenuTrigger>
<DropdownMenuContent style={{ minWidth: "30vw" }}>
{data.map((curSecret: string) => {
return (
<DropdownMenuCheckboxItem
checked={pullSecrets.includes(curSecret)}
key={curSecret}
disabled={data.length === 0}
onClick={() => {
const clonedSecrets = [...pullSecrets];

if (pullSecrets.includes(curSecret)) {
setPullSecrets(
clonedSecrets.filter((element) => {
return element !== curSecret;
}),
);
return;
}

clonedSecrets.push(curSecret);
setPullSecrets(clonedSecrets);
}}
>
{curSecret}
</DropdownMenuCheckboxItem>
);
})}
</DropdownMenuContent>
</DropdownMenu>
);
}
Loading

0 comments on commit c8d758f

Please sign in to comment.