From f7753aa1b41bb00d02981c76acee7ae9f0b9fb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Thu, 16 Mar 2023 18:38:39 +0300 Subject: [PATCH] fix(SearchableJSONViewer): remove undefined values from filtered arrays --- .../web/src/components/SearchableJSONViewer/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/web/src/components/SearchableJSONViewer/index.tsx b/packages/web/src/components/SearchableJSONViewer/index.tsx index c381c2bd..fdfa9cba 100644 --- a/packages/web/src/components/SearchableJSONViewer/index.tsx +++ b/packages/web/src/components/SearchableJSONViewer/index.tsx @@ -3,6 +3,7 @@ import get from 'lodash/get'; import set from 'lodash/set'; import throttle from 'lodash/throttle'; import isEmpty from 'lodash/isEmpty'; +import toPath from 'lodash/toPath'; import { Box, Typography } from '@mui/material'; import { IJSONObject, IJSONValue } from '@automatisch/types'; @@ -61,6 +62,16 @@ const SearchableJSONViewer = ({ data }: JSONViewerProps) => { ) { const value = get(filteredData, key); set(newFilteredData, key, value); + const keyPath = toPath(key); + const parentKeyPath = keyPath.slice(0, keyPath.length - 1); + const parentKey = parentKeyPath.join('.'); + const parentValue = get(newFilteredData, parentKey); + if (Array.isArray(parentValue)) { + const filteredParentValue = parentValue.filter( + (item) => item !== undefined + ); + set(newFilteredData, parentKey, filteredParentValue); + } } });