Skip to content

Commit

Permalink
[Fix][WRS-2227] Display cells values correctly for data source model (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
psamusev authored Jan 14, 2025
1 parent ab73954 commit a45da0c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/components/dataSource/DataSourceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AvailableIcons, Icon, LoadingIcon, Table, useInfiniteScrolling } from '@chili-publish/grafx-shared-components';
import { DataItem } from '@chili-publish/studio-sdk';
import { useMemo } from 'react';
import { Center, EmptyStateText, ErrorTextBox, ErrorTextMsg, TableWrapper } from './DataSourceTable.styles';

interface DataSourceTableProps {
Expand Down Expand Up @@ -27,14 +28,38 @@ function DataSourceTable({
onNextPageRequested,
);

// TODO: Remove/Adopt type casting in context of https://chilipublishintranet.atlassian.net/browse/WRS-2253
const transformedData = useMemo(() => {
return data.map((di) =>
Object.entries(di).reduce((transformed, [key, value]) => {
if (typeof value === 'string' || typeof value === 'number') {
// eslint-disable-next-line no-param-reassign
transformed[key] = value;
}
if (value instanceof Date) {
// eslint-disable-next-line no-param-reassign
transformed[key] = value.toISOString();
}
if (typeof value === 'boolean') {
// eslint-disable-next-line no-param-reassign
transformed[key] = `${value}`;
}
if (value === null) {
// eslint-disable-next-line no-param-reassign
transformed[key] = '';
}
return transformed;
}, {} as Record<string, string | number>),
);
}, [data]);

return (
<>
{!error && data.length > 0 && (
<TableWrapper>
<Table
defaultSelectedRow={selectedRow}
// Type casting is necessary since currently table supports only string and number
rows={data as Record<string, string | number>[]}
rows={transformedData}
onSelectedRowChanged={onSelectedRowChanged}
/>
</TableWrapper>
Expand Down

0 comments on commit a45da0c

Please sign in to comment.