diff --git a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte index 12e5f23814..6359c781cc 100644 --- a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte @@ -42,6 +42,14 @@ name: "Contains", key: "CONTAINS", }, + { + name: "Is Not Empty", + key: "NOT_EMPTY", + }, + { + name: "Is Empty", + key: "EMPTY", + }, ] const CONJUNCTIONS = [ @@ -112,6 +120,10 @@ const getOptionLabel = x => x.name const getOptionValue = x => x.key + + const showValue = filter => { + return !(filter.condition === "EMPTY" || filter.condition === "NOT_EMPTY") + } @@ -140,30 +152,36 @@ {getOptionLabel} {getOptionValue} /> - {#if filter.key && isMultipleChoice(filter.key)} - + {#if showValue(filter)} + {#if filter.key && isMultipleChoice(filter.key)} + + {:else} + + {/if} + removeFilter(idx)} /> {:else} - + removeFilter(idx)} /> + +
{/if} - removeFilter(idx)} /> {/each}
{:else} diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 068c6ab7b1..b0f39b2f1f 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -10,6 +10,15 @@ const TOKEN_MAP = { OR: "||", } +const isEmptyExpression = key => { + return `( + doc["${key}"] === undefined || + doc["${key}"] === null || + doc["${key}"] === "" || + (Array.isArray(doc["${key}"]) && doc["${key}"].length === 0) + )` +} + const GROUP_PROPERTY = { group: { type: "string", @@ -72,6 +81,10 @@ function parseFilterExpression(filters) { expression.push( `doc["${filter.key}"].${TOKEN_MAP[filter.condition]}("${filter.value}")` ) + } 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