Refactor - moving frontend search fields around so accessible from filter builder.
This commit is contained in:
parent
cf89c6fbde
commit
7a7f7185c9
|
@ -4,7 +4,8 @@
|
||||||
import FilterBuilder from "components/design/settings/controls/FilterEditor/FilterBuilder.svelte"
|
import FilterBuilder from "components/design/settings/controls/FilterEditor/FilterBuilder.svelte"
|
||||||
import { getUserBindings } from "dataBinding"
|
import { getUserBindings } from "dataBinding"
|
||||||
import { makePropSafe } from "@budibase/string-templates"
|
import { makePropSafe } from "@budibase/string-templates"
|
||||||
import { getFields } from "helpers/searchFields"
|
import { search } from "@budibase/frontend-core"
|
||||||
|
import { tables } from "stores/builder"
|
||||||
|
|
||||||
export let schema
|
export let schema
|
||||||
export let filters
|
export let filters
|
||||||
|
@ -16,7 +17,11 @@
|
||||||
let drawer
|
let drawer
|
||||||
|
|
||||||
$: tempValue = filters || []
|
$: tempValue = filters || []
|
||||||
$: schemaFields = getFields(Object.values(schema || {}), { allowLinks: true })
|
$: schemaFields = search.getFields(
|
||||||
|
$tables.list,
|
||||||
|
Object.values(schema || {}),
|
||||||
|
{ allowLinks: true }
|
||||||
|
)
|
||||||
|
|
||||||
$: text = getText(filters)
|
$: text = getText(filters)
|
||||||
$: selected = tempValue.filter(x => !x.onEmptyFilter)?.length > 0
|
$: selected = tempValue.filter(x => !x.onEmptyFilter)?.length > 0
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
import { Button, ActionButton, Drawer } from "@budibase/bbui"
|
import { Button, ActionButton, Drawer } from "@budibase/bbui"
|
||||||
|
import { search } from "@budibase/frontend-core"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import ColumnDrawer from "./ColumnDrawer.svelte"
|
import ColumnDrawer from "./ColumnDrawer.svelte"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
||||||
import { selectedScreen } from "stores/builder"
|
import { selectedScreen, tables } from "stores/builder"
|
||||||
import { getFields } from "helpers/searchFields"
|
|
||||||
|
|
||||||
export let componentInstance
|
export let componentInstance
|
||||||
export let value = []
|
export let value = []
|
||||||
|
@ -25,9 +25,13 @@
|
||||||
: enrichedSchemaFields?.map(field => field.name)
|
: enrichedSchemaFields?.map(field => field.name)
|
||||||
$: sanitisedValue = getValidColumns(value, options)
|
$: sanitisedValue = getValidColumns(value, options)
|
||||||
$: updateBoundValue(sanitisedValue)
|
$: updateBoundValue(sanitisedValue)
|
||||||
$: enrichedSchemaFields = getFields(Object.values(schema || {}), {
|
$: enrichedSchemaFields = search.getFields(
|
||||||
allowLinks: true,
|
$tables.list,
|
||||||
})
|
Object.values(schema || {}),
|
||||||
|
{
|
||||||
|
allowLinks: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
value = (value || []).filter(
|
value = (value || []).filter(
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import { dataFilters } from "@budibase/shared-core"
|
import { dataFilters } from "@budibase/shared-core"
|
||||||
import { FilterBuilder } from "@budibase/frontend-core"
|
import { FilterBuilder } from "@budibase/frontend-core"
|
||||||
|
import { tables } from "stores/builder"
|
||||||
|
|
||||||
import { createEventDispatcher, onMount } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@
|
||||||
<FilterBuilder
|
<FilterBuilder
|
||||||
bind:filters={rawFilters}
|
bind:filters={rawFilters}
|
||||||
behaviourFilters={true}
|
behaviourFilters={true}
|
||||||
|
tables={$tables.list}
|
||||||
{schemaFields}
|
{schemaFields}
|
||||||
{datasource}
|
{datasource}
|
||||||
{allowBindings}
|
{allowBindings}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script>
|
<script>
|
||||||
import { Multiselect } from "@budibase/bbui"
|
import { Multiselect } from "@budibase/bbui"
|
||||||
|
import { search } from "@budibase/frontend-core"
|
||||||
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
||||||
import { selectedScreen } from "stores/builder"
|
import { selectedScreen, tables } from "stores/builder"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { getFields } from "helpers/searchFields"
|
|
||||||
|
|
||||||
export let componentInstance = {}
|
export let componentInstance = {}
|
||||||
export let value = ""
|
export let value = ""
|
||||||
|
@ -20,7 +20,9 @@
|
||||||
if (!ds?.tableId) {
|
if (!ds?.tableId) {
|
||||||
return base.map(field => field.name)
|
return base.map(field => field.name)
|
||||||
}
|
}
|
||||||
return getFields(base, { allowLinks: true }).map(field => field.name)
|
return search
|
||||||
|
.getFields($tables.list, base, { allowLinks: true })
|
||||||
|
.map(field => field.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedOption(selectedOptions, allOptions) {
|
function getSelectedOption(selectedOptions, allOptions) {
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
import { LuceneUtils, Constants } from "@budibase/frontend-core"
|
import { LuceneUtils, Constants } from "@budibase/frontend-core"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import FilterUsers from "./FilterUsers.svelte"
|
import FilterUsers from "./FilterUsers.svelte"
|
||||||
import { getFields } from "@budibase/builder/src/helpers/searchFields"
|
import { getFields } from "../utils/searchFields"
|
||||||
|
|
||||||
const { OperatorOptions } = Constants
|
const { OperatorOptions } = Constants
|
||||||
|
|
||||||
export let schemaFields
|
export let schemaFields
|
||||||
export let filters = []
|
export let filters = []
|
||||||
|
export let tables = []
|
||||||
export let datasource
|
export let datasource
|
||||||
export let behaviourFilters = false
|
export let behaviourFilters = false
|
||||||
export let allowBindings = false
|
export let allowBindings = false
|
||||||
|
@ -46,12 +47,12 @@
|
||||||
|
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
|
||||||
$: fieldOptions = getFields(schemaFields || [], { allowLinks: true }).map(
|
$: fieldOptions = getFields(tables, schemaFields || [], {
|
||||||
field => ({
|
allowLinks: true,
|
||||||
label: field.displayName || field.name,
|
}).map(field => ({
|
||||||
value: field.name,
|
label: field.displayName || field.name,
|
||||||
})
|
value: field.name,
|
||||||
)
|
}))
|
||||||
|
|
||||||
const addFilter = () => {
|
const addFilter = () => {
|
||||||
filters = [
|
filters = [
|
||||||
|
|
|
@ -6,6 +6,15 @@ export { Feature as Features } from "@budibase/types"
|
||||||
import { BpmCorrelationKey } from "@budibase/shared-core"
|
import { BpmCorrelationKey } from "@budibase/shared-core"
|
||||||
import { FieldType, BBReferenceFieldSubType } from "@budibase/types"
|
import { FieldType, BBReferenceFieldSubType } from "@budibase/types"
|
||||||
|
|
||||||
|
export const BannedSearchTypes = [
|
||||||
|
FieldType.LINK,
|
||||||
|
FieldType.ATTACHMENTS,
|
||||||
|
FieldType.FORMULA,
|
||||||
|
FieldType.JSON,
|
||||||
|
"jsonarray",
|
||||||
|
"queryarray",
|
||||||
|
]
|
||||||
|
|
||||||
// Cookie names
|
// Cookie names
|
||||||
export const Cookies = {
|
export const Cookies = {
|
||||||
Auth: "budibase:auth",
|
Auth: "budibase:auth",
|
||||||
|
|
|
@ -4,6 +4,7 @@ export * as CookieUtils from "./cookies"
|
||||||
export * as RoleUtils from "./roles"
|
export * as RoleUtils from "./roles"
|
||||||
export * as Utils from "./utils"
|
export * as Utils from "./utils"
|
||||||
export * as RowUtils from "./rows"
|
export * as RowUtils from "./rows"
|
||||||
|
export * as search from "./searchFields"
|
||||||
export { memo, derivedMemo } from "./memo"
|
export { memo, derivedMemo } from "./memo"
|
||||||
export { createWebsocket } from "./websocket"
|
export { createWebsocket } from "./websocket"
|
||||||
export * from "./download"
|
export * from "./download"
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import { tables } from "stores/builder"
|
import { BannedSearchTypes } from "../constants"
|
||||||
import { BannedSearchTypes } from "../constants/backend"
|
|
||||||
import { get } from "svelte/store"
|
|
||||||
|
|
||||||
export function getTableFields(linkField) {
|
export function getTableFields(tables, linkField) {
|
||||||
const table = get(tables).list.find(table => table._id === linkField.tableId)
|
const table = tables.find(table => table._id === linkField.tableId)
|
||||||
// TODO: mdrury - add support for this with SQS at some point
|
// TODO: mdrury - add support for this with SQS at some point
|
||||||
if (!table || !table.sql) {
|
if (!table || !table.sql) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const linkFields = getFields(Object.values(table.schema), {
|
const linkFields = getFields(tables, Object.values(table.schema), {
|
||||||
allowLinks: false,
|
allowLinks: false,
|
||||||
})
|
})
|
||||||
return linkFields.map(field => ({
|
return linkFields.map(field => ({
|
||||||
|
@ -17,7 +15,11 @@ export function getTableFields(linkField) {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFields(fields, { allowLinks } = { allowLinks: true }) {
|
export function getFields(
|
||||||
|
tables,
|
||||||
|
fields,
|
||||||
|
{ allowLinks } = { allowLinks: true }
|
||||||
|
) {
|
||||||
let filteredFields = fields.filter(
|
let filteredFields = fields.filter(
|
||||||
field => !BannedSearchTypes.includes(field.type)
|
field => !BannedSearchTypes.includes(field.type)
|
||||||
)
|
)
|
||||||
|
@ -25,7 +27,7 @@ export function getFields(fields, { allowLinks } = { allowLinks: true }) {
|
||||||
const linkFields = fields.filter(field => field.type === "link")
|
const linkFields = fields.filter(field => field.type === "link")
|
||||||
for (let linkField of linkFields) {
|
for (let linkField of linkFields) {
|
||||||
// only allow one depth of SQL relationship filtering
|
// only allow one depth of SQL relationship filtering
|
||||||
filteredFields = filteredFields.concat(getTableFields(linkField))
|
filteredFields = filteredFields.concat(getTableFields(tables, linkField))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const staticFormulaFields = fields.filter(
|
const staticFormulaFields = fields.filter(
|
Loading…
Reference in New Issue