From 286745f74b6a151f7ffadbcab049846194f8a3d0 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Fri, 29 Mar 2024 23:49:49 +0800 Subject: [PATCH 1/2] feat(website): add rudimentary filters to hosts tabulation --- website/src/components/app/-app.tsx | 131 +++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 2 deletions(-) diff --git a/website/src/components/app/-app.tsx b/website/src/components/app/-app.tsx index a39fb64..35f5070 100644 --- a/website/src/components/app/-app.tsx +++ b/website/src/components/app/-app.tsx @@ -1,11 +1,12 @@ import { Card, CardBody, CardHeader } from '@nextui-org/card'; import { Chip } from '@nextui-org/chip'; import { Listbox, ListboxItem, ListboxSection } from '@nextui-org/listbox'; +import { Select, SelectItem, Selection } from '@nextui-org/react'; import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/table'; import Image from 'next/image'; import Link from 'next/link'; import { Just, Maybe, Nothing } from 'purify-ts/Maybe'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { LhpData } from './-data'; import { KVBox } from './-ui'; @@ -100,8 +101,134 @@ export function cloudIcon(x: string) { } export function TabulateHosts({ hosts, onHostSelect }: { hosts: LhpData[]; onHostSelect: (host: LhpData) => void }) { + const [filters, setFilters] = useState boolean>>({}); + const [filteredHosts, setFilteredHosts] = useState(hosts); + + useEffect(() => { + setFilteredHosts(hosts.filter((host) => Object.values(filters).reduce((acc, f) => acc && f(host), true))); + }, [filters, hosts]); + return (
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ Tags - + {(host) => ( From bb8b828ad7d2a7e395271d502bb9c41a68185f3d Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Sat, 30 Mar 2024 00:51:57 +0800 Subject: [PATCH 2/2] feat(website): add more filters to hosts tabulation --- website/src/components/app/-app.tsx | 181 +++++++++++++++++++++++++--- 1 file changed, 164 insertions(+), 17 deletions(-) diff --git a/website/src/components/app/-app.tsx b/website/src/components/app/-app.tsx index 35f5070..d93746f 100644 --- a/website/src/components/app/-app.tsx +++ b/website/src/components/app/-app.tsx @@ -1,7 +1,7 @@ import { Card, CardBody, CardHeader } from '@nextui-org/card'; import { Chip } from '@nextui-org/chip'; import { Listbox, ListboxItem, ListboxSection } from '@nextui-org/listbox'; -import { Select, SelectItem, Selection } from '@nextui-org/react'; +import { Radio, RadioGroup, Select, SelectItem, Selection, Slider } from '@nextui-org/react'; import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/table'; import Image from 'next/image'; import Link from 'next/link'; @@ -111,11 +111,11 @@ export function TabulateHosts({ hosts, onHostSelect }: { hosts: LhpData[]; onHos return (
-
+
-
+
-
+
+ +
+ +
-
+
-
+
+ +
+ +
+ x.hardware.cpuCount))} + maxValue={Math.max(...hosts.map((x) => x.hardware.cpuCount))} + defaultValue={[ + Math.min(...hosts.map((x) => x.hardware.cpuCount)), + Math.max(...hosts.map((x) => x.hardware.cpuCount)), + ]} + className="max-w-md" + onChange={(x) => { + if (Array.isArray(x)) { + const [mi, ma] = x; + setFilters({ + ...filters, + cpu: (h) => mi <= h.hardware.cpuCount && h.hardware.cpuCount <= ma, + }); + } + }} + /> +
+ +
+ x.hardware.ramTotal)))} + defaultValue={[0, Math.ceil(Math.max(...hosts.map((x) => x.hardware.ramTotal)))]} + className="max-w-md" + onChange={(x) => { + if (Array.isArray(x)) { + const [mi, ma] = x; + setFilters({ + ...filters, + ram: (h) => mi <= h.hardware.ramTotal && h.hardware.ramTotal <= ma, + }); + } + }} + /> +
+ +
+ x.hardware.diskRoot)))} + defaultValue={[0, Math.ceil(Math.max(...hosts.map((x) => x.hardware.diskRoot)))]} + className="max-w-md" + onChange={(x) => { + if (Array.isArray(x)) { + const [mi, ma] = x; + setFilters({ + ...filters, + disk: (h) => mi <= h.hardware.diskRoot && h.hardware.diskRoot <= ma, + }); + } + }} + /> +
+ +
+ { + setFilters({ + ...filters, + docker: + x === 'yes' + ? (h) => h.dockerContainers != null + : x === 'no' + ? (h) => h.dockerContainers == null + : () => true, + }); + }} + > + All + Yes + No + +
+ +