From 0c5019b16229c92b67b056c05329a2f5aec3d28f Mon Sep 17 00:00:00 2001 From: Etienne Burdet Date: Fri, 6 Dec 2024 11:03:04 +0100 Subject: [PATCH] fix: reverse warning type check --- .../src/components/Format/BooleanFormat.svelte | 12 +++++------- .../src/components/Format/LongTextFormat.svelte | 10 ++++------ .../src/components/Format/NumberFormat.svelte | 14 +++++++------- .../src/components/Format/ShortTextFormat.svelte | 10 ++++------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/visualizations/src/components/Format/BooleanFormat.svelte b/packages/visualizations/src/components/Format/BooleanFormat.svelte index 8d849374..acbc2a3a 100644 --- a/packages/visualizations/src/components/Format/BooleanFormat.svelte +++ b/packages/visualizations/src/components/Format/BooleanFormat.svelte @@ -9,16 +9,14 @@ export let debugWarnings = false; $: format = (v: unknown) => { - if (typeof v !== 'boolean') { - if (debugWarnings) { - warn(v, 'boolean'); - } - } - // Currently we return the raw value until we have alternative renders - if (display) { + if (typeof v === 'boolean' && display) { return display(v as boolean); } + if (debugWarnings) { + warn(v, 'boolean'); + } return v; + // Currently we return the raw value until we have alternative renders }; diff --git a/packages/visualizations/src/components/Format/LongTextFormat.svelte b/packages/visualizations/src/components/Format/LongTextFormat.svelte index 58b97fa6..793a48d6 100644 --- a/packages/visualizations/src/components/Format/LongTextFormat.svelte +++ b/packages/visualizations/src/components/Format/LongTextFormat.svelte @@ -9,14 +9,12 @@ export let debugWarnings = false; $: format = (v: unknown) => { - if (typeof v !== 'string') { - if (debugWarnings) { - warn(v, 'text'); - } - } - if (display) { + if (typeof v === 'string' && display) { return display(v as string); } + if (debugWarnings) { + warn(v, 'text'); + } return v; }; diff --git a/packages/visualizations/src/components/Format/NumberFormat.svelte b/packages/visualizations/src/components/Format/NumberFormat.svelte index b34580c1..437b2bd6 100644 --- a/packages/visualizations/src/components/Format/NumberFormat.svelte +++ b/packages/visualizations/src/components/Format/NumberFormat.svelte @@ -11,17 +11,17 @@ export let debugWarnings = false; $: format = (v: number) => { - if (!Number.isFinite(v)) { + if (Number.isFinite(v)) { if (debugWarnings) { warn(v, 'number'); } - return v; - } - const intlValue = new Intl.NumberFormat(locale, intl).format(v); - if (display) { - return display(intlValue); + const intlValue = new Intl.NumberFormat(locale, intl).format(v); + if (display) { + return display(intlValue); + } + return intlValue; } - return intlValue; + return v; }; diff --git a/packages/visualizations/src/components/Format/ShortTextFormat.svelte b/packages/visualizations/src/components/Format/ShortTextFormat.svelte index 26e18314..adf9aa84 100644 --- a/packages/visualizations/src/components/Format/ShortTextFormat.svelte +++ b/packages/visualizations/src/components/Format/ShortTextFormat.svelte @@ -9,14 +9,12 @@ export let debugWarnings = false; $: format = (v: unknown) => { - if (typeof v !== 'string') { - if (debugWarnings) { - warn(v, 'text'); - } - } - if (display) { + if (typeof v === 'string' && display) { return display(v as string); } + if (debugWarnings) { + warn(v, 'text'); + } return v; };