From c3db3211fb9784ae6405a95f51c87976542b21e0 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 3 May 2022 15:52:03 +0100 Subject: [PATCH] Query preview sort by number for number types --- .../src/components/integration/QueryViewer.svelte | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index 8f6f9eeb53..81ffa29733 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -44,6 +44,21 @@ $: readQuery = query.queryVerb === "read" || query.readable $: queryInvalid = !query.name || (readQuery && data.length === 0) + //Cast field in query preview response to number if specified by schema + $: { + for (let i = 0; i < data.length; i++) { + let row = data[i] + for (let fieldNameIndex in Object.keys(fields)) { + let fieldName = Object.keys(fields)[fieldNameIndex] + if (fields[fieldName] === "number" && !isNaN(Number(row[fieldName]))) { + row[fieldName] = Number(row[fieldName]) + } else { + row[fieldName] = row[fieldName]?.toString() + } + } + } + } + // seed the transformer if (query && !query.transformer) { query.transformer = "return data"