From 81e6e137640ed3b0c374cffbf31deee3162d9718 Mon Sep 17 00:00:00 2001 From: Pedro Carreno <34664891+Pkcarreno@users.noreply.github.com> Date: Sun, 6 Oct 2024 12:38:35 -0400 Subject: [PATCH] fix(output): improve render value behavior now can handle more values like 'undefined' --- .../components/output/format-output.tsx | 60 ++++++------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/src/features/editor/components/output/format-output.tsx b/src/features/editor/components/output/format-output.tsx index b23828e..458bbe8 100644 --- a/src/features/editor/components/output/format-output.tsx +++ b/src/features/editor/components/output/format-output.tsx @@ -5,62 +5,40 @@ import type { Loggable } from '@/features/editor/types'; import { JsonView } from './json-view-wrapper'; interface Props { - value: Loggable; + value: Loggable | Record; + topLevel?: boolean; } -export const FormatOutput: React.FC = ({ value }) => { - if (typeof value === 'string') { - return {value}; +export const FormatOutput: React.FC = ({ value, topLevel = true }) => { + if (typeof value === 'string' && value === '') { + return empty; } - if (value && Array.isArray(value) && value.length > 0) { - return value.map((subValue, index) => { - if (subValue && typeof subValue === 'string') { - return ( -
- {subValue} -
- ); - } + if (Array.isArray(value) && topLevel) { + return value.map((subValue, index) => ( + + )); + } - if (subValue && typeof subValue === 'number') { - return ( -
- - {subValue} - -
- ); - } + if (typeof value === 'string') { + return {value}; + } - if ( - subValue && - (typeof subValue === 'object' || Array.isArray(subValue)) - ) { - return ( -
- -
- ); - } - }); + if (typeof value === 'number') { + return {value}; } if (value && (typeof value === 'object' || Array.isArray(value))) { return ( -
+
); } - if (value && Array.isArray(value) && value.length === 0) { - return ( -
- empty -
- ); + if (!value) { + return {String(value)}; } - // return <>{value}; + return {String(value)}; };