From 362dbb3a6d043841f7a7bf27436de54a9aae82e3 Mon Sep 17 00:00:00 2001 From: David Edler Date: Wed, 18 Dec 2024 17:27:03 +0100 Subject: [PATCH] feat(network) key search will hide empty sections. add no results found message Signed-off-by: David Edler --- src/pages/networks/forms/NetworkForm.tsx | 18 +- .../networks/forms/NetworkFormBridge.tsx | 100 +++---- src/pages/networks/forms/NetworkFormDns.tsx | 142 +++++----- src/pages/networks/forms/NetworkFormIpv4.tsx | 218 ++++++++-------- src/pages/networks/forms/NetworkFormIpv6.tsx | 244 +++++++++--------- src/pages/networks/forms/NetworkFormOvn.tsx | 62 ++--- 6 files changed, 407 insertions(+), 377 deletions(-) diff --git a/src/pages/networks/forms/NetworkForm.tsx b/src/pages/networks/forms/NetworkForm.tsx index dc2e9bc67c..f5d43919e8 100644 --- a/src/pages/networks/forms/NetworkForm.tsx +++ b/src/pages/networks/forms/NetworkForm.tsx @@ -173,15 +173,19 @@ const NetworkForm: FC = ({ const { data: settings } = useSettings(); const isClustered = isClusteredServer(settings); const [query, setQuery] = useState(""); + const [hasEmptySearchResult, setEmptySearchResult] = useState(false); const filterRows = (rows: MainTableRow[]) => { if (!query) { return rows; } - - return rows.filter((row) => { + const filteredRows = rows.filter((row) => { return row.name?.toString()?.toLowerCase().includes(query); }); + if (filteredRows.length > 0) { + setEmptySearchResult(false); + } + return filteredRows; }; const availableSections = [GENERAL]; @@ -226,7 +230,7 @@ const NetworkForm: FC = ({ dependencies={[notify.notification]} belowIds={["form-footer", "status-bar"]} > - {!formik.values.isCreating && ( + {!formik.values.isCreating && query.length < 1 && ( )}
@@ -292,12 +296,18 @@ const NetworkForm: FC = ({ /> )} + {hasEmptySearchResult && ( +
No configuration found matching this search.
+ )} {section !== slugify(YAML_CONFIGURATION) && (
{ + setQuery(inputValue); + setEmptySearchResult(true); + }} value={query} name="search-setting" type="text" diff --git a/src/pages/networks/forms/NetworkFormBridge.tsx b/src/pages/networks/forms/NetworkFormBridge.tsx index 3052ec4a00..d65b106640 100644 --- a/src/pages/networks/forms/NetworkFormBridge.tsx +++ b/src/pages/networks/forms/NetworkFormBridge.tsx @@ -14,60 +14,64 @@ interface Props { } const NetworkFormBridge: FC = ({ formik, filterRows }) => { - return ( - <> -

- Bridge -

- , - }), + const rows = filterRows([ + getConfigurationRow({ + formik, + name: "bridge_mtu", + label: "MTU", + defaultValue: "", + children: , + }), + + getConfigurationRow({ + formik, + name: "bridge_hwaddr", + label: "Hardware address", + defaultValue: "", + children: , + }), + ...(formik.values.networkType === "bridge" + ? [ getConfigurationRow({ formik, - name: "bridge_hwaddr", - label: "Hardware address", + name: "bridge_driver", + label: "Bridge driver", defaultValue: "", - children: , + children: ( + - ), - }), - ] - : []), - ])} - /> + if (rows.length === 0) { + return null; + } + + return ( + <> +

+ Bridge +

+ ); }; diff --git a/src/pages/networks/forms/NetworkFormDns.tsx b/src/pages/networks/forms/NetworkFormDns.tsx index 695b4f3754..30e52a7fbc 100644 --- a/src/pages/networks/forms/NetworkFormDns.tsx +++ b/src/pages/networks/forms/NetworkFormDns.tsx @@ -14,80 +14,84 @@ interface Props { } const NetworkFormDns: FC = ({ formik, filterRows }) => { + const rows = filterRows([ + ...(formik.values.networkType !== "physical" + ? [ + getConfigurationRow({ + formik, + name: "dns_domain", + label: "DNS domain", + defaultValue: "", + children: , + }), + ] + : []), + + ...(formik.values.networkType === "bridge" + ? [ + getConfigurationRow({ + formik, + name: "dns_mode", + label: "DNS mode", + defaultValue: "", + children: ( + , + }), + ] + : [ + getConfigurationRow({ + formik, + name: "dns_search", + label: "DNS search", + defaultValue: "", + children: