codeant-ai-for-open-source[bot] commented on code in PR #44907:
URL: https://github.com/apache/superset/pull/44907#discussion_r4170066284
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/TextCellRenderer.tsx:
##########
@@ -51,6 +61,24 @@ export const TextCellRenderer = (params: CellRendererProps)
=> {
}
}
+ // Object and array JSON is interactive. Plain text, URLs, and opt-in HTML
+ // stay on the paths below.
+ const parsedJson = parseJsonCellValue(value);
+ if (parsedJson) {
+ return (
+ <JsonCellRenderer
+ value={parsedJson}
+ rawText={typeof value === 'string' ? value : undefined}
+ colId={colDef?.field || colDef?.colId || 'json'}
+ autoHeight={Boolean(colDef?.autoHeight)}
+ jsonInCell={jsonInCell}
+ api={api}
+ node={node}
+ eGridCell={params.eGridCell}
+ />
+ );
Review Comment:
**Suggestion:** JSON values bypass `valueFormatted`, so column formatters,
custom labels, and formatting applied by AG Grid are discarded whenever the raw
value parses as an object or array.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Api mismatch`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=41bee45b24204d7cbd3d8c4d8654778b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=41bee45b24204d7cbd3d8c4d8654778b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/TextCellRenderer.tsx
**Line:** 66:79
**Comment:**
*Api Mismatch: JSON values bypass `valueFormatted`, so column
formatters, custom labels, and formatting applied by AG Grid are discarded
whenever the raw value parses as an object or array.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44907&comment_hash=53278d2367bfadde88f748032ab79ce06e15f5e838f5866f20d251899fb5a591&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44907&comment_hash=53278d2367bfadde88f748032ab79ce06e15f5e838f5866f20d251899fb5a591&reaction=dislike'>๐</a>
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/JsonCellRenderer.tsx:
##########
@@ -0,0 +1,589 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+ type ReactNode,
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useRef,
+ useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import { styled } from '@apache-superset/core/theme';
+import { Button, Icons, Modal } from '@superset-ui/core/components';
+import { type JsonContainer, jsonCellPreview } from './parseJsonCellValue';
+import { syncJsonCellRowHeight } from './jsonCellRowHeight';
+
+const MAX_JSON_DEPTH = 32;
+const JSON_CELL_ROW_CHROME_PX = 12;
+const ARROW_CLICK_MS = 250;
+
+type JsonCellGridApi = {
+ resetRowHeights?: () => void;
+ onRowHeightChanged?: () => void;
+ isDestroyed?: () => boolean;
+};
+
+type JsonCellRowNode = {
+ setRowHeight?: (height: number | null | undefined) => void;
+};
+
+export type JsonCellRendererProps = {
+ value: JsonContainer;
+ rawText?: string;
+ colId: string;
+ autoHeight: boolean;
+ jsonInCell?: boolean;
+ api?: JsonCellGridApi;
+ node?: JsonCellRowNode;
+ eGridCell?: HTMLElement | null;
+};
+
+const Root = styled.div`
+ ${({ theme }) => `
+ display: flex;
+ flex-direction: column;
+ gap: ${theme.sizeUnit / 2}px;
+ width: 100%;
+ min-width: 0;
+ white-space: inherit;
+ word-break: inherit;
+ `}
+`;
+
+const Toolbar = styled.div`
+ ${({ theme }) => `
+ display: flex;
+ align-items: center;
+ gap: ${theme.sizeUnit}px;
+ min-width: 0;
+ `}
+`;
+
+const Preview = styled.span`
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ flex: 1;
+ min-width: 0;
+`;
+
+const JsonToggle = styled.button`
+ ${({ theme }) => `
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: ${theme.sizeUnit * 4}px;
+ height: ${theme.sizeUnit * 4}px;
+ padding: 0;
+ border: none;
+ background: transparent;
+ color: ${theme.colorTextSecondary};
+ cursor: pointer;
+ flex: none;
+
+ &:hover,
+ &:focus-visible {
+ color: ${theme.colorPrimary};
+ }
+ `}
+`;
+
+const TextToggle = styled.button`
+ display: block;
+ width: 100%;
+ min-width: 0;
+ padding: 0;
+ border: none;
+ background: transparent;
+ color: inherit;
+ font: inherit;
+ text-align: inherit;
+ cursor: pointer;
+ white-space: inherit;
+ word-break: inherit;
+`;
+
+const JsonBlock = styled.div`
+ ${({ theme }) => `
+ display: flex;
+ flex-direction: column;
+ min-width: 0;
+ font-family: ${theme.fontFamilyCode};
+ `}
+`;
+
+const JsonLine = styled.div`
+ display: flex;
+ align-items: flex-start;
+ gap: 4px;
+ min-width: 0;
+`;
+
+const JsonIndent = styled.div`
+ ${({ theme }) => `
+ padding-left: ${theme.sizeUnit * 4}px;
+ `}
+`;
+
+const JsonKey = styled.span`
+ ${({ theme }) => `
+ color: ${theme.colorText};
+ flex: none;
+ `}
+`;
+
+const JsonMuted = styled.span`
+ ${({ theme }) => `
+ color: ${theme.colorTextSecondary};
+ `}
+`;
+
+const StringValue = styled.span`
+ ${({ theme }) => `
+ color: ${theme.colorSuccess};
+ `}
+`;
+
+const NumberValue = styled.span`
+ ${({ theme }) => `
+ color: ${theme.colorPrimary};
+ `}
+`;
+
+const BooleanValue = styled.span`
+ ${({ theme }) => `
+ color: ${theme.colorWarning};
+ `}
+`;
+
+const Tree = styled.div`
+ ${({ theme }) => `
+ font-family: ${theme.fontFamilyCode};
+ font-size: ${theme.fontSizeSM}px;
+ white-space: pre-wrap;
+ word-break: break-word;
+ `}
+`;
+
+// AG Grid selects the row from a listener on the row container. React's
+// delegated click handler runs at the React root, after that listener, so the
+// control stops the native event on the button itself.
+const AG_GRID_STOP_PROPAGATION = '__ag_Grid_Stop_Propagation';
+
+function stopGridPointer(event: Event) {
+ event.stopPropagation();
+ Object.assign(event, { [AG_GRID_STOP_PROPAGATION]: true });
+}
+
+function JsonActionButton({
+ label,
+ expanded,
+ onActivate,
+ plain = false,
+ testId,
+ children,
+}: {
+ label?: string;
+ expanded?: boolean;
+ onActivate: () => void;
+ plain?: boolean;
+ testId?: string;
+ children: ReactNode;
+}) {
+ const ref = useRef<HTMLButtonElement>(null);
+
+ useLayoutEffect(() => {
+ const node = ref.current;
+ if (!node) {
+ return undefined;
+ }
+ const stop = (event: Event) => {
+ stopGridPointer(event);
+ };
+ const onClick = (event: Event) => {
+ stopGridPointer(event);
+ onActivate();
+ };
+ node.addEventListener('pointerdown', stop);
+ node.addEventListener('mousedown', stop);
+ node.addEventListener('click', onClick);
+ node.addEventListener('dblclick', stop);
+ return () => {
+ node.removeEventListener('pointerdown', stop);
+ node.removeEventListener('mousedown', stop);
+ node.removeEventListener('click', onClick);
+ node.removeEventListener('dblclick', stop);
+ };
+ }, [onActivate]);
+
+ const Toggle = plain ? TextToggle : JsonToggle;
+ return (
+ <Toggle
+ ref={ref}
+ type="button"
+ aria-expanded={expanded}
+ aria-label={label}
+ data-json-cell-action
+ data-test={testId}
+ >
+ {children}
+ </Toggle>
+ );
+}
+
+function JsonPrimitive({ value }: { value: unknown }) {
+ if (typeof value === 'string') {
+ return <StringValue>{JSON.stringify(value)}</StringValue>;
+ }
+ if (typeof value === 'number' || typeof value === 'bigint') {
+ return <NumberValue>{String(value)}</NumberValue>;
+ }
+ if (typeof value === 'boolean') {
+ return <BooleanValue>{String(value)}</BooleanValue>;
+ }
+ if (value === null) {
+ return <JsonMuted>null</JsonMuted>;
+ }
+ return <JsonMuted>{String(value)}</JsonMuted>;
+}
+
+function containerEntries(
+ value: JsonContainer,
+): Array<readonly [string, unknown]> {
+ if (Array.isArray(value)) {
+ return value.map((item, index) => [String(index), item] as const);
+ }
+ return Object.entries(value);
+}
+
+function containerSummary(value: JsonContainer): string {
+ if (Array.isArray(value)) {
+ return t('%s items', value.length);
+ }
+ return t('%s keys', Object.keys(value).length);
+}
+
+function JsonNode({
+ value,
+ name,
+ depth,
+ initialOpen = false,
+ onLayoutChange,
+}: {
+ value: unknown;
+ name?: string;
+ depth: number;
+ initialOpen?: boolean;
+ onLayoutChange?: () => void;
+}) {
+ const [open, setOpen] = useState(initialOpen);
+ const isContainer =
+ value !== null &&
+ typeof value === 'object' &&
+ (Array.isArray(value) || Object.getPrototypeOf(value) ===
Object.prototype);
+
+ if (!isContainer || depth >= MAX_JSON_DEPTH) {
+ return (
+ <JsonLine>
+ {name !== undefined && <JsonKey>{name}: </JsonKey>}
+ {isContainer ? (
+ <JsonMuted>โฆ</JsonMuted>
+ ) : (
+ <JsonPrimitive value={value} />
+ )}
+ </JsonLine>
+ );
+ }
+
+ const container = value as JsonContainer;
+ const entries = containerEntries(container);
+ const openBrace = Array.isArray(container) ? '[' : '{';
+ const closeBrace = Array.isArray(container) ? ']' : '}';
+ const label = name !== undefined ? name : 'JSON';
+ const actionLabel = open ? t('Collapse %s', label) : t('Expand %s', label);
+
+ return (
+ <JsonBlock>
+ <JsonLine>
+ <JsonActionButton
+ label={actionLabel}
+ expanded={open}
+ onActivate={() => {
+ setOpen(current => !current);
+ onLayoutChange?.();
+ }}
+ >
+ {open ? (
+ <Icons.CaretDownOutlined iconSize="xs" />
+ ) : (
+ <Icons.CaretRightOutlined iconSize="xs" />
+ )}
+ </JsonActionButton>
+ {name !== undefined && <JsonKey>{name}: </JsonKey>}
+ <span>{openBrace}</span>
+ {!open && (
+ <>
+ <JsonMuted>{containerSummary(container)}</JsonMuted>
+ <span>{closeBrace}</span>
+ </>
+ )}
+ </JsonLine>
+ {open && (
+ <>
+ <JsonIndent>
+ {entries.map(([key, child]) => (
+ <JsonNode
+ key={key}
+ name={key}
+ value={child}
+ depth={depth + 1}
+ onLayoutChange={onLayoutChange}
+ />
+ ))}
+ </JsonIndent>
+ <JsonLine>{closeBrace}</JsonLine>
+ </>
+ )}
+ </JsonBlock>
+ );
+}
+
+export function JsonCellRenderer({
+ value,
+ rawText,
+ colId,
+ autoHeight,
+ jsonInCell = false,
+ api,
+ node,
+ eGridCell,
+}: JsonCellRendererProps) {
+ const [expanded, setExpanded] = useState(false);
+ const [layoutTick, setLayoutTick] = useState(0);
+ const [modalOpen, setModalOpen] = useState(false);
+ const [copied, setCopied] = useState(false);
+ const rootRef = useRef<HTMLDivElement>(null);
+ const arrowClickTimer = useRef<number | undefined>(undefined);
+ const hasAdjustedHeight = useRef(false);
+ const latest = useRef({
+ expanded,
+ autoHeight,
+ api,
+ node,
+ colId,
+ });
+
+ const showTree = jsonInCell && expanded;
+ const preview = jsonCellPreview(value, rawText);
+ const originalText = rawText ?? JSON.stringify(value);
+ const openBrace = Array.isArray(value) ? '[' : '{';
+ const closeBrace = Array.isArray(value) ? ']' : '}';
+ const entries = containerEntries(value);
+
+ const bumpLayout = useCallback(() => {
+ setLayoutTick(tick => tick + 1);
+ }, []);
+
+ useLayoutEffect(() => {
+ latest.current = { expanded: showTree, autoHeight, api, node, colId };
+ const cell = eGridCell ?? null;
+ cell?.classList.toggle('json-cell-expanded', showTree);
+
+ const shouldSync = showTree || hasAdjustedHeight.current;
+ const setRowHeight = node?.setRowHeight;
+ if (shouldSync && !api?.isDestroyed?.()) {
+ hasAdjustedHeight.current = showTree;
+ if (autoHeight) {
+ api?.resetRowHeights?.();
+ } else if (setRowHeight && api?.onRowHeightChanged) {
+ const measured = rootRef.current?.scrollHeight ?? 0;
+ const height =
+ showTree && measured > 0 ? measured + JSON_CELL_ROW_CHROME_PX : 0;
+ syncJsonCellRowHeight(
+ { setRowHeight },
+ { onRowHeightChanged: () => api.onRowHeightChanged?.() },
+ colId,
+ height,
Review Comment:
**Suggestion:** Each synchronization passes a new wrapper object, so the
WeakMap cannot find the expansion entry and collapsed rows remain at their
expanded height.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `State/lifecycle
and layout`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5a525f46e2624e67a29954109bc762b4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5a525f46e2624e67a29954109bc762b4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/JsonCellRenderer.tsx
**Line:** 419:423
**Comment:**
*State Lifecycle And Layout: Each synchronization passes a new wrapper
object, so the WeakMap cannot find the expansion entry and collapsed rows
remain at their expanded height.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44907&comment_hash=00beb82e181945284a07197009ab25c59a58959b53834e18de40a811d6bcc09c&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44907&comment_hash=00beb82e181945284a07197009ab25c59a58959b53834e18de40a811d6bcc09c&reaction=dislike'>๐</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]