From f611a508a7c149d5bfcb5caabb3b87d0dbedc488 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Thu, 4 Jan 2024 15:34:21 +0530 Subject: [PATCH] MINOR: fix the sample data value displayed on UI (#14571) * fix the sample data value displayed on UI * empty string should fallback to no-data-placeholder * changes as per commments --- .../SampleDataTable/RowData.test.tsx | 22 ++++++++++- .../components/SampleDataTable/RowData.tsx | 37 +++++++++++++------ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.test.tsx index a71f2ff81d4..aac4c3aaeee 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.test.tsx @@ -41,7 +41,7 @@ describe('Test RowData Component', () => { expect(await findByTestId('schema-modal')).toBeInTheDocument(); }); - it('Should render string data if data is not a tyeopf object', async () => { + it('Should render string data if data is not a typeof object', async () => { const { findByTestId } = render(, { wrapper: MemoryRouter, }); @@ -51,6 +51,16 @@ describe('Test RowData Component', () => { expect(stringData).toBeInTheDocument(); }); + it('Should render string data if data value is 0', async () => { + const { findByTestId } = render(, { + wrapper: MemoryRouter, + }); + + const stringData = await findByTestId('string-data'); + + expect(stringData).toBeInTheDocument(); + }); + it('Should render fallback data if no data is there', async () => { const { findByTestId } = render(, { wrapper: MemoryRouter, @@ -60,4 +70,14 @@ describe('Test RowData Component', () => { expect(emptyData).toBeInTheDocument(); }); + + it('Should render fallback data if the data is empty string', async () => { + const { findByTestId } = render(, { + wrapper: MemoryRouter, + }); + + const emptyData = await findByTestId('empty-data'); + + expect(emptyData).toBeInTheDocument(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.tsx b/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.tsx index 0bf45a0cdc6..1797df71300 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/SampleDataTable/RowData.tsx @@ -11,34 +11,47 @@ * limitations under the License. */ -import React, { Fragment, useState } from 'react'; +import { Typography } from 'antd'; +import { isNil, isObject } from 'lodash'; +import React, { Fragment, useCallback, useMemo, useState } from 'react'; +import { NO_DATA_PLACEHOLDER } from '../../constants/constants'; import SchemaModal from '../Modals/SchemaModal/SchemaModal'; import { SampleDataType } from './SampleData.interface'; export const RowData = ({ data }: { data: SampleDataType }) => { const [isFullView, setIsFullView] = useState(false); - const onClose = () => setIsFullView(false); - const onOpen = () => setIsFullView(true); + const onClose = useCallback(() => setIsFullView(false), []); + const onOpen = useCallback(() => setIsFullView(true), []); - const getDataElement = (rowValue: SampleDataType) => { - if (typeof rowValue === 'object') { + const dataElementRenderer = useMemo(() => { + if (isNil(data) || data === '') { return ( -

+ {NO_DATA_PLACEHOLDER} + + ); + } else if (isObject(data)) { + return ( + - {JSON.stringify(rowValue)} -

+ {JSON.stringify(data)} + + ); + } else { + return ( + + {data.toString()} + ); } - - return

{rowValue.toString()}

; - }; + }, [data, onOpen]); return ( - {data ? getDataElement(data) :

--

} + {dataElementRenderer} {isFullView && ( )}