From 841e6b2518c22f2396b6bd0e96b70057e295467b Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 25 Oct 2021 09:58:05 +0100 Subject: [PATCH] Feedback: Rename set/not set to not empty/empty, remove cell rendering --- packages/bbui/src/Table/CellRenderer.svelte | 20 +------------------ packages/bbui/src/Table/StringRenderer.svelte | 9 +-------- .../DataTable/modals/FilterModal.svelte | 10 +++++----- .../src/api/controllers/view/viewBuilder.js | 17 +++++----------- 4 files changed, 12 insertions(+), 44 deletions(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 844501947f..9a53fd0169 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -28,27 +28,9 @@ $: type = schema?.type ?? "string" $: customRenderer = customRenderers?.find(x => x.column === schema?.name) $: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer - - /** - * Don't use falsy here as we want to: - * - include empty arrays - * - exclude 0 and booleans - * - * If updated, the corresponding view expression should be updated in 'server/viewBuilder.js' - */ - const isNotSet = value => { - return ( - value === undefined || - value === null || - value === "" || - (Array.isArray(value) && value.length === 0) - ) - } -{#if !customRenderer && isNotSet(value)} - -{:else if renderer} +{#if renderer && (customRenderer || (value != null && value !== ""))} diff --git a/packages/bbui/src/Table/StringRenderer.svelte b/packages/bbui/src/Table/StringRenderer.svelte index 7219a1a8f1..2756839616 100644 --- a/packages/bbui/src/Table/StringRenderer.svelte +++ b/packages/bbui/src/Table/StringRenderer.svelte @@ -1,11 +1,8 @@ -
- {typeof value === "object" ? JSON.stringify(value) : value} -
+
{value}
diff --git a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte index 2b76fd2209..6359c781cc 100644 --- a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte @@ -43,12 +43,12 @@ key: "CONTAINS", }, { - name: "Is Set", - key: "SET", + name: "Is Not Empty", + key: "NOT_EMPTY", }, { - name: "Is Not Set", - key: "NOT_SET", + name: "Is Empty", + key: "EMPTY", }, ] @@ -122,7 +122,7 @@ const getOptionValue = x => x.key const showValue = filter => { - return !(filter.condition === "SET" || filter.condition === "NOT_SET") + return !(filter.condition === "EMPTY" || filter.condition === "NOT_EMPTY") } diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 9cbd7b83d4..b0f39b2f1f 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -10,14 +10,7 @@ const TOKEN_MAP = { OR: "||", } -/** - * Don't use falsy here as we want to: - * - include empty arrays - * - exclude 0 and booleans - * - * If updated, the corresponding rendering condition should be updated in 'bbui/CellRenderer.svelte' - */ -const isNotSetExpression = key => { +const isEmptyExpression = key => { return `( doc["${key}"] === undefined || doc["${key}"] === null || @@ -88,10 +81,10 @@ function parseFilterExpression(filters) { expression.push( `doc["${filter.key}"].${TOKEN_MAP[filter.condition]}("${filter.value}")` ) - } else if (filter.condition === "NOT_SET") { - expression.push(isNotSetExpression(filter.key)) - } else if (filter.condition === "SET") { - expression.push(`!${isNotSetExpression(filter.key)}`) + } else if (filter.condition === "EMPTY") { + expression.push(isEmptyExpression(filter.key)) + } else if (filter.condition === "NOT_EMPTY") { + expression.push(`!${isEmptyExpression(filter.key)}`) } else { const value = typeof filter.value == "string" ? `"${filter.value}"` : filter.value