Skip to content

Commit

Permalink
fix: display boolean and zero values correctly in value renderers (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 committed Oct 16, 2023
1 parent cb14d47 commit 10c65fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/components/info-panel/InfoPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Table } from '../table/Table';

export interface InfoPanelData {
description: string;
data: Record<string, string | number | object | any>;
data: Record<string, string | number | object | boolean | any>;
}

interface InfoPanelProps {
Expand Down Expand Up @@ -130,8 +130,10 @@ export function InfoPanel(props: InfoPanelProps) {
* @param value - ValueRenderers value.
* @returns - ValueRenderers component.
*/
function valueCell(value: number | string | object) {
function valueCell(value: number | string | object | boolean) {
switch (typeof value) {
case 'boolean':
return <ValueRenderers.Boolean value={value} />;
case 'number':
return <ValueRenderers.Number value={value} />;
case 'object':
Expand All @@ -150,15 +152,20 @@ function valueCell(value: number | string | object) {
* @param search - Value to search for.
* @returns - If search exist in value
*/
function valueSearch(value: number | string | object, search: string): boolean {
function valueSearch(
value: number | string | object | boolean,
search: string,
): boolean {
switch (typeof value) {
case 'number':
return String(value).includes(search);
case 'boolean':
return String(value).includes(search);
case 'object':
return JSON.stringify(value).includes(search);
case 'string':
return value.includes(search);
default:
return false;
return true;
}
}
4 changes: 3 additions & 1 deletion src/components/value-renderers/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface NumberProps extends ValueRenderersProps {

export function Number({ value, fixed, ...other }: NumberProps) {
return (
<div {...other}>{value ? (fixed ? value.toFixed(fixed) : value) : ''}</div>
<div {...other}>
{value !== undefined ? (fixed ? value.toFixed(fixed) : value) : ''}
</div>
);
}
2 changes: 2 additions & 0 deletions stories/components/info-panel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const data: InfoPanelData[] = [
data: {
frequency: '400 MHz',
solvent: 'CDCl3',
isFi: false,
temperature: 0,
},
},
];
Expand Down

0 comments on commit 10c65fe

Please sign in to comment.