From fe8eaa44e3f8f66697827fe7d3205d4971e49776 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 8 Jul 2022 18:51:58 -0400 Subject: [PATCH] fix(striker-ui): correct NIC name sort, correct NIC state display --- striker-ui/lib/sumstring.ts | 11 +++++++++++ striker-ui/pages/init/index.tsx | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 striker-ui/lib/sumstring.ts diff --git a/striker-ui/lib/sumstring.ts b/striker-ui/lib/sumstring.ts new file mode 100644 index 00000000..3a349374 --- /dev/null +++ b/striker-ui/lib/sumstring.ts @@ -0,0 +1,11 @@ +const sumstring = (value: string): number => { + let sum = 0; + + for (let index = 0; index < value.length; index += 1) { + sum += value.codePointAt(index) || 0; + } + + return sum; +}; + +export default sumstring; diff --git a/striker-ui/pages/init/index.tsx b/striker-ui/pages/init/index.tsx index 4274b6d4..7cc715d4 100644 --- a/striker-ui/pages/init/index.tsx +++ b/striker-ui/pages/init/index.tsx @@ -12,11 +12,12 @@ import { import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import { TEXT } from '../../lib/consts/DEFAULT_THEME'; +import Decorator from '../../components/Decorator'; import { Panel, PanelHeader } from '../../components/Panels'; import periodicFetch from '../../lib/fetchers/periodicFetch'; import Spinner from '../../components/Spinner'; +import sumstring from '../../lib/sumstring'; import { BodyText, BodyTextProps, HeaderText } from '../../components/Text'; -import Decorator from '../../components/Decorator'; const MOCK_NICS: NetworkInterfaceOverviewMetadata[] = [ { @@ -84,6 +85,7 @@ const NETWORK_INTERFACE_COLUMNS: MUIDataGridProps['columns'] = [ ), + sortComparator: (v1, v2) => sumstring(v1) - sumstring(v2), }, { field: 'networkInterfaceMACAddress', @@ -91,6 +93,19 @@ const NETWORK_INTERFACE_COLUMNS: MUIDataGridProps['columns'] = [ headerName: 'MAC', renderCell: ({ value }) => , }, + { + field: 'networkInterfaceState', + headerName: 'State', + renderCell: ({ value }) => { + const state = String(value); + + return ( + + ); + }, + }, { field: 'networkInterfaceSpeed', flex: 1,