You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by en...@apache.org on 2026/10/20 18:58:17 UTC

(superset) branch master updated: feat(action-log): open JSON payloads in a tree modal (#45337)

This is an automated email from the ASF dual-hosted git repository.

EnxDev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 875dcbb1bb0 feat(action-log): open JSON payloads in a tree modal (#45337)
875dcbb1bb0 is described below

commit 875dcbb1bb0fb0d60f168e7b3f9b41ae94136e25
Author: Enzo Martellucci <52...@users.noreply.github.com>
AuthorDate: Tue Oct 20 20:58:09 2026 +0200

    feat(action-log): open JSON payloads in a tree modal (#45337)
    
    Co-authored-by: Claude Opus 5.5 <no...@anthropic.com>
---
 .../src/components/JsonModal/JsonModal.test.tsx    | 18 +++++
 .../src/components/JsonModal/utils.ts              | 10 ++-
 .../src/pages/ActionLog/ActionLog.test.tsx         | 76 ++++++++++++++++++++++
 superset-frontend/src/pages/ActionLog/index.tsx    | 67 +++++++++++++------
 4 files changed, 151 insertions(+), 20 deletions(-)

diff --git a/superset-frontend/src/components/JsonModal/JsonModal.test.tsx b/superset-frontend/src/components/JsonModal/JsonModal.test.tsx
index 7344bb577f5..0eac8130be8 100644
--- a/superset-frontend/src/components/JsonModal/JsonModal.test.tsx
+++ b/superset-frontend/src/components/JsonModal/JsonModal.test.tsx
@@ -73,3 +73,21 @@ test('renders bigInt value in a number format', () => {
     '12345678901234567890',
   );
 });
+
+test('keeps quotes on numeric strings json-bigint would not have produced', () => {
+  // json-bigint only stores number literals longer than 15 characters as
+  // strings, so anything shorter was a string in the source JSON
+  expect(convertBigIntStrToNumber('"123"')).toBe('"123"');
+  expect(convertBigIntStrToNumber('"123456789012345"')).toBe(
+    '"123456789012345"',
+  );
+  expect(convertBigIntStrToNumber('"-12345678901234"')).toBe(
+    '"-12345678901234"',
+  );
+  expect(convertBigIntStrToNumber('"1234567890123456"')).toBe(
+    '1234567890123456',
+  );
+  expect(convertBigIntStrToNumber('"-123456789012345"')).toBe(
+    '-123456789012345',
+  );
+});
diff --git a/superset-frontend/src/components/JsonModal/utils.ts b/superset-frontend/src/components/JsonModal/utils.ts
index 31b4e33855a..f08df3fc21a 100644
--- a/superset-frontend/src/components/JsonModal/utils.ts
+++ b/superset-frontend/src/components/JsonModal/utils.ts
@@ -46,8 +46,16 @@ export function safeJsonObjectParse(
   }
 }
 
+// json-bigint (with storeAsString) keeps number literals longer than this as
+// strings; shorter quoted digits were strings in the source JSON
+const BIGINT_STR_MIN_LENGTH = 16;
+
 export function convertBigIntStrToNumber(value: string | number) {
-  if (typeof value === 'string' && /^"-?\d+"$/.test(value)) {
+  if (
+    typeof value === 'string' &&
+    /^"-?\d+"$/.test(value) &&
+    value.length - 2 >= BIGINT_STR_MIN_LENGTH
+  ) {
     return value.substring(1, value.length - 1);
   }
   return value;
diff --git a/superset-frontend/src/pages/ActionLog/ActionLog.test.tsx b/superset-frontend/src/pages/ActionLog/ActionLog.test.tsx
index 6cd732391f9..9eed9602282 100644
--- a/superset-frontend/src/pages/ActionLog/ActionLog.test.tsx
+++ b/superset-frontend/src/pages/ActionLog/ActionLog.test.tsx
@@ -22,6 +22,7 @@ import {
   screen,
   userEvent,
   waitFor,
+  within,
 } from 'spec/helpers/testing-library';
 import { MemoryRouter } from 'react-router-dom';
 import { QueryParamProvider } from 'use-query-params';
@@ -88,3 +89,78 @@ test('sorting by Action sends order_column=action as a positive control', async
     ).toBe(true),
   );
 });
+
+test('JSON column opens a tree modal for object payloads', async () => {
+  fetchMock.removeRoutes();
+  fetchMock.get('glob:*/api/v1/log/_info*', { permissions: ['can_read'] });
+  fetchMock.get(logEndpoint, {
+    result: [{ ...mockLogs[0], json: '{"path":"/superset/welcome/","n":1}' }],
+    count: 1,
+  });
+  renderActionLog();
+
+  await userEvent.click(
+    await screen.findByText('{"path":"/superset/welcome/","n":1}'),
+  );
+
+  // A raw string handed to the tree would render as one leaf, so check that
+  // each key and value gets its own node
+  const dialog = within(await screen.findByRole('dialog'));
+  expect(dialog.getByText('path:')).toBeInTheDocument();
+  expect(dialog.getByText('"/superset/welcome/"')).toBeInTheDocument();
+  expect(dialog.getByText('n:')).toBeInTheDocument();
+  expect(dialog.getByText('1')).toBeInTheDocument();
+});
+
+test('JSON tree keeps quotes on numeric strings', async () => {
+  fetchMock.removeRoutes();
+  fetchMock.get('glob:*/api/v1/log/_info*', { permissions: ['can_read'] });
+  fetchMock.get(logEndpoint, {
+    result: [{ ...mockLogs[0], json: '{"dashboard_id":"123","count":123}' }],
+    count: 1,
+  });
+  renderActionLog();
+
+  await userEvent.click(
+    await screen.findByText('{"dashboard_id":"123","count":123}'),
+  );
+
+  const dialog = within(await screen.findByRole('dialog'));
+  expect(dialog.getByText('"123"')).toBeInTheDocument();
+  expect(dialog.getByText('123')).toBeInTheDocument();
+});
+
+test('JSON trigger styling does not depend on data-test attributes', async () => {
+  fetchMock.removeRoutes();
+  fetchMock.get('glob:*/api/v1/log/_info*', { permissions: ['can_read'] });
+  fetchMock.get(logEndpoint, {
+    result: [{ ...mockLogs[0], json: '{"path":"/superset/welcome/"}' }],
+    count: 1,
+  });
+  renderActionLog();
+
+  const trigger = (
+    await screen.findByText('{"path":"/superset/welcome/"}')
+  ).closest('[role="button"]') as HTMLElement;
+  // Production builds strip data-test, so the ellipsis must survive without it
+  trigger.removeAttribute('data-test');
+
+  expect(trigger).toHaveStyle({
+    'white-space': 'nowrap',
+    'text-overflow': 'ellipsis',
+  });
+});
+
+test('JSON column keeps plain text for non-JSON payloads', async () => {
+  fetchMock.removeRoutes();
+  fetchMock.get('glob:*/api/v1/log/_info*', { permissions: ['can_read'] });
+  fetchMock.get(logEndpoint, {
+    result: [{ ...mockLogs[0], json: 'not json' }],
+    count: 1,
+  });
+  renderActionLog();
+
+  await userEvent.click(await screen.findByText('not json'));
+
+  expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+});
diff --git a/superset-frontend/src/pages/ActionLog/index.tsx b/superset-frontend/src/pages/ActionLog/index.tsx
index dba87a79d87..433dae5c9fd 100644
--- a/superset-frontend/src/pages/ActionLog/index.tsx
+++ b/superset-frontend/src/pages/ActionLog/index.tsx
@@ -18,7 +18,7 @@
  */
 import { useMemo } from 'react';
 import { t } from '@apache-superset/core/translation';
-import { css } from '@apache-superset/core/theme';
+import { css, styled } from '@apache-superset/core/theme';
 import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu';
 import { useListViewResource } from 'src/views/CRUD/hooks';
 import { useToasts } from 'src/components/MessageToasts/withToasts';
@@ -29,6 +29,8 @@ import {
 } from 'src/components/ListView';
 import { Typography } from '@superset-ui/core/components';
 import { fetchUserOptions } from 'src/features/groups/utils';
+import { JsonModal } from 'src/components/JsonModal';
+import { safeJsonObjectParse } from 'src/components/JsonModal/utils';
 
 export type ActionLogObject = {
   user: {
@@ -48,6 +50,15 @@ export type ActionLogObject = {
 
 const PAGE_SIZE = 25;
 
+const JsonCellTrigger = styled.div`
+  > [role='button'] {
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+    cursor: pointer;
+  }
+`;
+
 function ActionLogList() {
   const { addDangerToast, addSuccessToast } = useToasts();
   const initialSort = [{ id: 'dttm', desc: true }];
@@ -215,24 +226,42 @@ function ActionLogList() {
           row: {
             original: { json },
           },
-        }: any) => (
-          <Typography.Text
-            css={css`
-              .ant-typography-copy {
-                visibility: hidden;
-              }
-              &:hover .ant-typography-copy {
-                visibility: visible;
-              }
-            `}
-            copyable={!!json}
-            ellipsis={{
-              tooltip: { styles: { root: { maxWidth: '900px' } }, title: json },
-            }}
-          >
-            {json}
-          </Typography.Text>
-        ),
+        }: any) => {
+          const jsonObject = safeJsonObjectParse(json);
+          if (jsonObject) {
+            return (
+              <JsonCellTrigger>
+                <JsonModal
+                  modalTitle={t('JSON')}
+                  jsonObject={jsonObject}
+                  jsonValue={json}
+                  wrapContent={false}
+                />
+              </JsonCellTrigger>
+            );
+          }
+          return (
+            <Typography.Text
+              css={css`
+                .ant-typography-copy {
+                  visibility: hidden;
+                }
+                &:hover .ant-typography-copy {
+                  visibility: visible;
+                }
+              `}
+              copyable={!!json}
+              ellipsis={{
+                tooltip: {
+                  styles: { root: { maxWidth: '900px' } },
+                  title: json,
+                },
+              }}
+            >
+              {json}
+            </Typography.Text>
+          );
+        },
       },
 
       {