From ffbb4863f387c1dd9d7b0c414e1d5754bdffe195 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 27 Feb 2024 20:56:42 +0100 Subject: [PATCH 1/2] Fix GoToEvent link generation when value is None --- src/npm-fastui/src/components/display.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/npm-fastui/src/components/display.tsx b/src/npm-fastui/src/components/display.tsx index 6fbe4d3d..4ce4fb86 100644 --- a/src/npm-fastui/src/components/display.tsx +++ b/src/npm-fastui/src/components/display.tsx @@ -218,9 +218,7 @@ const subKeys = (template: string, row: DataModel): string | null => { let returnNull = false const r = template.replace(/{(.+?)}/g, (_, key: string): string => { const v: JsonData | undefined = row[key] - if (v === undefined) { - throw new Error(`field "${key}" not found in ${JSON.stringify(row)}`) - } else if (v === null) { + if (v === null || v === undefined) { returnNull = true return 'null' } else { From 50484312b20b281a85e3319e4101c2f36a9b3bed Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Fri, 19 Apr 2024 19:27:17 +0200 Subject: [PATCH 2/2] change implementation --- src/npm-fastui/src/components/display.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/npm-fastui/src/components/display.tsx b/src/npm-fastui/src/components/display.tsx index 4ce4fb86..30bb2c14 100644 --- a/src/npm-fastui/src/components/display.tsx +++ b/src/npm-fastui/src/components/display.tsx @@ -203,7 +203,12 @@ export function renderEvent(event: AnyEvent | undefined, data: DataModel): AnyEv if (newEvent) { if (newEvent.type === 'go-to' && newEvent.url) { // for go-to events with a URL, substitute the row values into the url - const url = subKeys(newEvent.url, data) + let url: string | null = null + try { + url = subKeys(newEvent.url, data) + } catch (e) { + url = null + } if (url === null) { newEvent = undefined } else { @@ -218,7 +223,9 @@ const subKeys = (template: string, row: DataModel): string | null => { let returnNull = false const r = template.replace(/{(.+?)}/g, (_, key: string): string => { const v: JsonData | undefined = row[key] - if (v === null || v === undefined) { + if (v === undefined) { + throw new Error(`field "${key}" not found in ${JSON.stringify(row)}`) + } else if (v === null) { returnNull = true return 'null' } else {