Skip to content

Commit

Permalink
Refactor - moving frontend search fields around so accessible from fi…
Browse files Browse the repository at this point in the history
…lter builder.
  • Loading branch information
mike12345567 committed May 24, 2024
1 parent cf89c6f commit 7a7f718
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,6 +59,7 @@
<FilterBuilder
bind:filters={rawFilters}
behaviourFilters={true}
tables={$tables.list}
{schemaFields}
{datasource}
{allowBindings}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand All @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions packages/frontend-core/src/components/FilterBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend-core/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/frontend-core/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 => ({
Expand All @@ -17,15 +15,19 @@ 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)
)
if (allowLinks) {
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(
Expand Down

0 comments on commit 7a7f718

Please sign in to comment.