Skip to content

Commit

Permalink
CNV-39781: search by mac address
Browse files Browse the repository at this point in the history
  • Loading branch information
upalatucci committed Mar 22, 2024
1 parent b2b2563 commit f5fe99a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions locales/en/plugin__nmstate-console-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"Scheduling will not be possible at this state": "Scheduling will not be possible at this state",
"Search": "Search",
"Search by IP address...": "Search by IP address...",
"Search by MAC address...": "Search by MAC address...",
"selector key": "selector key",
"selector value": "selector value",
"Server": "Server",
Expand Down
7 changes: 6 additions & 1 deletion src/views/states/list/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InterfaceType, NodeNetworkConfigurationInterface } from '@types';
import { isEmpty } from '@utils/helpers';

import { FILTER_TYPES, LLDP_ENABLED } from '../constants';
import { searchInterfaceByIP } from '../utilts';
import { searchInterfaceByIP, searchInterfaceByMAC } from '../utilts';

export const interfaceFilters: Record<
string,
Expand Down Expand Up @@ -31,6 +31,11 @@ export const interfaceFilters: Record<
status === LLDP_ENABLED ? Boolean(obj?.lldp?.enabled) : !obj?.lldp?.enabled,
);
},
[FILTER_TYPES.MAC_ADDRESS]: (selectedInput, obj) => {
const searchMACAddress = selectedInput?.[0];

return searchInterfaceByMAC(searchMACAddress, obj);
},
} as const;

export const filterInterfaces = (
Expand Down
1 change: 1 addition & 0 deletions src/views/states/list/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getResourceUrl } from '@utils/helpers';
export const baseListUrl = getResourceUrl({ model: NodeNetworkStateModel });

export const FILTER_TYPES = {
MAC_ADDRESS: 'mac-address',
INTERFACE_STATE: 'interface-state',
INTERFACE_TYPE: 'interface-type',
IP_FILTER: 'ip-filter',
Expand Down
16 changes: 15 additions & 1 deletion src/views/states/list/hooks/useStateFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InterfaceType, NodeNetworkConfigurationInterface, V1beta1NodeNetworkSta
import { isEmpty } from '@utils/helpers';

import { FILTER_TYPES, LLDP_DISABLED, LLDP_ENABLED } from '../constants';
import { searchInterfaceByIP } from '../utilts';
import { searchInterfaceByIP, searchInterfaceByMAC } from '../utilts';

export const useStateSearchFilters = (): RowSearchFilter<V1beta1NodeNetworkState>[] => {
const { t } = useNMStateTranslation();
Expand All @@ -24,6 +24,20 @@ export const useStateSearchFilters = (): RowSearchFilter<V1beta1NodeNetworkState
filterGroupName: t('IP address'),
placeholder: t('Search by IP address...'),
},
{
type: FILTER_TYPES.MAC_ADDRESS,
filter: (searchText, obj) => {
const searchMACAddress = searchText?.selected?.[0];
if (!searchMACAddress) return true;

const interfaces = obj?.status?.currentState
?.interfaces as NodeNetworkConfigurationInterface[];

return interfaces?.some((iface) => searchInterfaceByMAC(searchMACAddress, iface));
},
filterGroupName: t('MAC address'),
placeholder: t('Search by MAC address...'),
},
];
};

Expand Down
9 changes: 9 additions & 0 deletions src/views/states/list/utilts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ export const searchInterfaceByIP = (

return addresses?.some((address) => address?.toLowerCase().includes(searchIPAddress));
};

export const searchInterfaceByMAC = (
searchMACAddress: string,
iface: NodeNetworkConfigurationInterface,
) => {
if (!searchMACAddress) return true;

return iface?.['mac-address']?.includes(searchMACAddress) || false;
};

0 comments on commit f5fe99a

Please sign in to comment.