diff --git a/frontend/src/AppBuilder/Widgets/Table/GenerateEachCellValue.jsx b/frontend/src/AppBuilder/Widgets/Table/GenerateEachCellValue.jsx index 312e57b760..0d2d8530c7 100644 --- a/frontend/src/AppBuilder/Widgets/Table/GenerateEachCellValue.jsx +++ b/frontend/src/AppBuilder/Widgets/Table/GenerateEachCellValue.jsx @@ -29,7 +29,7 @@ export default function GenerateEachCellValue({ const [showHighlightedCells, setHighlighterCells] = React.useState(globalFilter ? true : false); // const [isNullCellClicked, setIsNullCellClicked] = React.useState(false); - const columnTypeAllowToRenderMarkElement = ['text', 'string', 'default', 'number', 'json', undefined]; + const columnTypeAllowToRenderMarkElement = ['text', 'string', 'default', 'number', undefined]; const ref = useRef(); const [showOverlay, setShowOverlay] = useState(false); const [hovered, setHovered] = useState(false); diff --git a/frontend/src/AppBuilder/Widgets/Table/Json.jsx b/frontend/src/AppBuilder/Widgets/Table/Json.jsx new file mode 100644 index 0000000000..9eda847d3f --- /dev/null +++ b/frontend/src/AppBuilder/Widgets/Table/Json.jsx @@ -0,0 +1,191 @@ +/* eslint-disable no-undef */ +import React, { useState, useEffect } from 'react'; +import { determineJustifyContentValue } from '@/_helpers/utils'; +import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; + +const Json = ({ + isEditable, + darkMode, + handleCellValueChange, + cellTextColor, + cellValue, + column, + containerWidth, + cell, + horizontalAlignment, + isMaxRowHeightAuto, + cellSize, + maxRowHeightValue, +}) => { + const jsonIndentation = false; + const ref = React.useRef(null); + + const [hovered, setHovered] = useState(false); + const [isEditing, setIsEditing] = useState(false); + + const cellStyles = { + color: cellTextColor ?? 'inherit', + }; + + useEffect(() => { + if (!isEditable && isEditing) { + setIsEditing(false); + } + }, [isEditable]); + + function format(obj) { + if (typeof obj !== 'object' || obj === null) { + return typeof obj === 'string' ? `"${obj}"` : obj; + } + if (Array.isArray(obj)) { + return `[ ${obj.map(format).join(', ')} ]`; + } + return `{ ${Object.entries(obj) + .map(([key, value]) => `"${key}": ${format(value)}`) + .join(', ')} }`; + } + + const formatCellValue = (value, overlay = false) => { + try { + if (typeof value === 'object') { + if (jsonIndentation === true && !overlay) { + return JSON.stringify(value, null, 4).replace(/":/g, '": '); + } + const formattedJSON = format(value); + return formattedJSON; + } else { + if (jsonIndentation === true && !overlay) { + return JSON.stringify(JSON.parse(value), null, 4).replace(/":/g, '": '); + } + const formattedJSON = format(JSON.parse(value)); + return formattedJSON; + } + } catch (error) { + return value; + } + }; + + const _renderString = () => ( +