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