fix: view filter handle bool, number & date

This commit is contained in:
Michael Shanks 2020-10-01 16:55:17 +01:00
parent 69a1361d11
commit 0c373a9fb4
2 changed files with 16 additions and 6 deletions

View File

@ -81,11 +81,18 @@
function isMultipleChoice(field) { function isMultipleChoice(field) {
return ( return (
viewModel.schema[field].constraints && (viewModel.schema[field].constraints &&
viewModel.schema[field].constraints.inclusion && viewModel.schema[field].constraints.inclusion &&
viewModel.schema[field].constraints.inclusion.length viewModel.schema[field].constraints.inclusion.length) ||
viewModel.schema[field].type === "boolean"
) )
} }
function fieldOptions(field) {
return viewModel.schema[field].type === "string"
? viewModel.schema[field].constraints.inclusion
: [true, false]
}
</script> </script>
<div bind:this={anchor}> <div bind:this={anchor}>
@ -126,8 +133,8 @@
</Select> </Select>
{#if filter.key && isMultipleChoice(filter.key)} {#if filter.key && isMultipleChoice(filter.key)}
<Select secondary thin bind:value={filter.value}> <Select secondary thin bind:value={filter.value}>
{#each viewModel.schema[filter.key].constraints.inclusion as option} {#each fieldOptions(filter.key) as option}
<option value={option}>{option}</option> <option value={option}>{option.toString()}</option>
{/each} {/each}
</Select> </Select>
{:else} {:else}

View File

@ -61,8 +61,11 @@ function parseFilterExpression(filters) {
`doc["${filter.key}"].${TOKEN_MAP[filter.condition]}("${filter.value}")` `doc["${filter.key}"].${TOKEN_MAP[filter.condition]}("${filter.value}")`
) )
} else { } else {
const value =
typeof filter.value == "string" ? `"${filter.value}"` : filter.value
expression.push( expression.push(
`doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} "${filter.value}"` `doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} ${value}`
) )
} }
} }