From bb46594d844903d1d8442edc1e09acd68e11a908 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 22 Nov 2021 11:32:26 +0100 Subject: [PATCH] filter out unknown mappers (#1559) --- src/client-scopes/details/MapperList.tsx | 40 ++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/client-scopes/details/MapperList.tsx b/src/client-scopes/details/MapperList.tsx index 8e6aff04e5..59dbc48c80 100644 --- a/src/client-scopes/details/MapperList.tsx +++ b/src/client-scopes/details/MapperList.tsx @@ -56,22 +56,30 @@ export const MapperList = ({ setAddMapperDialogOpen(!addMapperDialogOpen); }; - const loader = async () => - Promise.resolve( - (mapperList || []) - .map((mapper) => { - const mapperType = mapperTypes.filter( - (type) => type.id === mapper.protocolMapper - )[0]; - return { - ...mapper, - category: mapperType.category, - type: mapperType.name, - priority: mapperType.priority, - } as Row; - }) - .sort((a, b) => a.priority - b.priority) - ); + const loader = async () => { + if (!mapperList) { + return []; + } + + const list = mapperList.reduce((rows, mapper) => { + const mapperType = mapperTypes.find( + ({ id }) => id === mapper.protocolMapper + ); + + if (!mapperType) { + return rows; + } + + return rows.concat({ + ...mapper, + category: mapperType.category, + type: mapperType.name, + priority: mapperType.priority, + }); + }, []); + + return list.sort((a, b) => a.priority - b.priority); + }; const MapperLink = ({ id, name }: Row) => ( {name}