Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
TextDataGroup behavior should match behavior of StringCell
Browse files Browse the repository at this point in the history
  • Loading branch information
yyassi-heartex committed Jan 30, 2024
1 parent 6e8c048 commit e80e01d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/DataGroups/TextDataGroup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const valueToString = (value) => {
import { format, isValid } from "date-fns";
import { dateTimeFormat } from "../CellViews/DateTimeCell";

export const valueToString = (value) => {
if (typeof value === "string") return value;
/* if undefined or null we'll treat it as empty string */
if (value === undefined || value === null) return "";
if (value instanceof Date && isValid(value)) return format(value, dateTimeFormat);

try {
/* JSON.stringify will handle JSON and non-strings, non-null, non-undefined */
return JSON.stringify(value);
} catch {
return (value ?? "").toString();
return 'Error: Invalid JSON';
}
};

Expand Down

0 comments on commit e80e01d

Please sign in to comment.