diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor.svelte new file mode 100644 index 0000000000..8c4f555159 --- /dev/null +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor.svelte @@ -0,0 +1,75 @@ + + + + + + + +
+
+ {#if !Object.keys(tempValue || {}).length} +

Add your first filter column.

+ + {/if} +
+ +
+
+
+
+ + diff --git a/packages/builder/src/components/design/PropertiesPanel/SettingsView.svelte b/packages/builder/src/components/design/PropertiesPanel/SettingsView.svelte index 430e622c4f..70729bfe76 100644 --- a/packages/builder/src/components/design/PropertiesPanel/SettingsView.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/SettingsView.svelte @@ -18,6 +18,7 @@ import MultiFieldSelect from "./PropertyControls/MultiFieldSelect.svelte" import SchemaSelect from "./PropertyControls/SchemaSelect.svelte" import EventsEditor from "./PropertyControls/EventsEditor" + import FilterEditor from "./PropertyControls/FilterEditor.svelte" import ScreenSelect from "./PropertyControls/ScreenSelect.svelte" import DetailScreenSelect from "./PropertyControls/DetailScreenSelect.svelte" import { IconSelect } from "./PropertyControls/IconSelect" @@ -73,6 +74,7 @@ field: FieldSelect, multifield: MultiFieldSelect, schema: SchemaSelect, + filter: FilterEditor, "field/string": StringFieldSelect, "field/number": NumberFieldSelect, "field/options": OptionsFieldSelect, diff --git a/packages/standard-components/manifest.json b/packages/standard-components/manifest.json index a7f237a790..571d7b42ab 100644 --- a/packages/standard-components/manifest.json +++ b/packages/standard-components/manifest.json @@ -118,6 +118,11 @@ "label": "Empty Text", "key": "noRowsMessage", "defaultValue": "No rows found." + }, + { + "type": "filter", + "label": "Filtering", + "key": "filter" } ] }, diff --git a/packages/standard-components/src/List.svelte b/packages/standard-components/src/List.svelte index 9923851abb..db9ef152bb 100644 --- a/packages/standard-components/src/List.svelte +++ b/packages/standard-components/src/List.svelte @@ -4,6 +4,7 @@ export let datasource export let noRowsMessage + export let filter const { API, styleable, Provider, builderStore, ActionTypes } = getContext( "sdk" @@ -13,6 +14,7 @@ let loaded = false $: fetchData(datasource) + $: filteredRows = filterRows(rows, filter) $: actions = [ { type: ActionTypes.RefreshDatasource, @@ -21,21 +23,34 @@ }, ] - async function fetchData(datasource) { + const fetchData = async datasource => { if (!isEmpty(datasource)) { rows = await API.fetchDatasource(datasource) } loaded = true } + + const filterRows = (rows, filter) => { + if (!Object.keys(filter || {}).length) { + return rows + } + let filteredData = [...rows] + Object.keys(filter).forEach(field => { + filteredData = filteredData.filter(row => { + return row[field] === filter[field].value + }) + }) + return filteredData + }
- {#if rows.length > 0} + {#if filteredRows.length > 0} {#if $component.children === 0 && $builderStore.inBuilder}

Add some components to display.

{:else} - {#each rows as row} + {#each filteredRows as row}