From 03f88349c8730bfbb4613105c35482b4f3fadd64 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Thu, 20 Feb 2025 14:19:27 +0100 Subject: [PATCH] fix(frontend): add warning when integer number if too big for frontend (#5340) --- .../src/lib/components/DisplayResult.svelte | 99 ++++++++++++------- .../propertyPicker/ObjectViewer.svelte | 14 ++- 2 files changed, 77 insertions(+), 36 deletions(-) diff --git a/frontend/src/lib/components/DisplayResult.svelte b/frontend/src/lib/components/DisplayResult.svelte index 80f7ce999f..b365bbdd96 100644 --- a/frontend/src/lib/components/DisplayResult.svelte +++ b/frontend/src/lib/components/DisplayResult.svelte @@ -76,6 +76,7 @@ | 'pdf' | undefined + let hasBigInt = false $: resultKind = inferResultKind(result) export let forceJson = false @@ -168,6 +169,13 @@ largeObject = size > DISPLAY_MAX_SIZE } + if (!largeObject) { + hasBigInt = checkIfHasBigInt(result) + if (hasBigInt) { + return 'json' + } + } + if (Array.isArray(result)) { if (result.length === 0) { return 'json' @@ -263,6 +271,21 @@ } } + function checkIfHasBigInt(result: any) { + if (typeof result === 'number' && Number.isInteger(result) && !Number.isSafeInteger(result)) { + return true + } + + if (Array.isArray(result)) { + return result.some(checkIfHasBigInt) + } + + if (result && typeof result === 'object') { + return Object.values(result).some(checkIfHasBigInt) + } + return false + } + function contentOrRootString(obj: string | { filename: string; content: string } | undefined) { if (obj == undefined || obj == null) { return '' @@ -401,14 +424,17 @@ /> {/each} -{:else if resultKind === 'nondisplayable'}
Non displayable object
{:else}
Non displayable object
+{:else} +
{#if result != undefined && length != undefined && largeObject != undefined}
+ > + {#if result != undefined && length != undefined && largeObject != undefined} +
+
{#if !hideAsJson && !['json', 's3object'].includes(resultKind ?? '') && typeof result === 'object'} {/if}
-
{#if !forceJson && resultKind === 'table-col'} +
+
+ {#if !forceJson && resultKind === 'table-col'} {@const data = 'table-col' in result ? result['table-col'] : result} {:else if !forceJson && resultKind === 'table-row'} @@ -779,7 +806,7 @@
- {:else if largeObject} + {:else if largeObject || hasBigInt} {#if result && typeof result === 'object' && 'file' in result} {:else} -
- Download {filename ? '' : 'as JSON'} - - {#if download_as_csv} - convertJsonToCsv(result)} - customText="Download as CSV" - /> - {/if} -
+ {#if largeObject} +
+ Download {filename ? '' : 'as JSON'} + + {#if download_as_csv} + convertJsonToCsv(result)} + customText="Download as CSV" + /> + {/if} +
-
- -
+
+ +
+ {/if} {#if result && result != 'WINDMILL_TOO_BIG'} {/if} diff --git a/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte b/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte index 31cb5d554a..66ebd350e8 100644 --- a/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte +++ b/frontend/src/lib/components/propertyPicker/ObjectViewer.svelte @@ -6,10 +6,11 @@ import { NEVER_TESTED_THIS_FAR } from '../flows/models' import Portal from '$lib/components/Portal.svelte' import { Button } from '$lib/components/common' - import { Download, PanelRightOpen } from 'lucide-svelte' + import { Download, PanelRightOpen, TriangleAlertIcon } from 'lucide-svelte' import S3FilePicker from '../S3FilePicker.svelte' import { workspaceStore } from '$lib/stores' import AnimatedButton from '$lib/components/common/button/AnimatedButton.svelte' + import Popover from '../Popover.svelte' export let json: any export let level = 0 @@ -166,6 +167,17 @@ null {:else if typeof json[key] == 'string'} "{truncate(json[key], 200)}" + {:else if typeof json[key] == 'number' && Number.isInteger(json[key]) && !Number.isSafeInteger(json[key])} + + {truncate(JSON.stringify(json[key]), 200)} + + + + This number is too large for the frontend to handle correctly and may be + rounded. + + + {:else} {truncate(JSON.stringify(json[key]), 200)}