@budibase/frontend-core 3.26.2 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.27.0",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
7
7
|
"svelte": "./src/index.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"check:types": "yarn svelte-check"
|
|
9
|
+
"check:types": "yarn svelte-check",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
10
12
|
},
|
|
11
13
|
"dependencies": {
|
|
12
14
|
"@ai-sdk/svelte": "^4.0.48",
|
|
@@ -19,5 +21,8 @@
|
|
|
19
21
|
"shortid": "2.2.15",
|
|
20
22
|
"socket.io-client": "^4.7.5"
|
|
21
23
|
},
|
|
22
|
-
"
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"vitest": "^3.2.4"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "7fc04647584c83a2d70f302fa88f2569580f7539"
|
|
23
28
|
}
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// Reset state if this search is invalid
|
|
100
|
-
if (!schema?.tableId || !isOpen) {
|
|
100
|
+
if (!schema?.tableId || !isOpen || !primaryDisplay) {
|
|
101
101
|
lastSearchString = null
|
|
102
102
|
candidateIndex = null
|
|
103
103
|
searchResults = []
|
|
@@ -159,6 +159,7 @@
|
|
|
159
159
|
primaryDisplay = await cache.actions.getPrimaryDisplayForTableId(
|
|
160
160
|
schema.tableId
|
|
161
161
|
)
|
|
162
|
+
searching = false
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
// Show initial list of results
|
|
@@ -38,7 +38,8 @@ export const createActions = (context: StoreContext): CacheActionStore => {
|
|
|
38
38
|
|
|
39
39
|
const getPrimaryDisplayForTableId = async (tableId: string) => {
|
|
40
40
|
const table = await fetchTable(tableId)
|
|
41
|
-
const
|
|
41
|
+
const firstSchemaKey = Object.keys(table?.schema || {})[0]
|
|
42
|
+
const display = table?.primaryDisplay || firstSchemaKey
|
|
42
43
|
return display
|
|
43
44
|
}
|
|
44
45
|
|
package/src/constants.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { BpmCorrelationKey } from "@budibase/shared-core"
|
|
|
11
11
|
import { BBReferenceFieldSubType, FieldType } from "@budibase/types"
|
|
12
12
|
|
|
13
13
|
export const BannedSearchTypes = [
|
|
14
|
-
FieldType.LINK,
|
|
15
14
|
FieldType.ATTACHMENT_SINGLE,
|
|
16
15
|
FieldType.ATTACHMENTS,
|
|
17
16
|
FieldType.FORMULA,
|
|
@@ -8,10 +8,12 @@ export function getTableFields(tables, linkField) {
|
|
|
8
8
|
const linkFields = getFields(tables, Object.values(table.schema), {
|
|
9
9
|
allowLinks: false,
|
|
10
10
|
})
|
|
11
|
-
return linkFields
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return linkFields
|
|
12
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
13
|
+
.map(field => ({
|
|
14
|
+
...field,
|
|
15
|
+
name: `${linkField.name}.${field.name}`,
|
|
16
|
+
}))
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export function getFields(
|
|
@@ -19,18 +21,22 @@ export function getFields(
|
|
|
19
21
|
fields,
|
|
20
22
|
{ allowLinks } = { allowLinks: true }
|
|
21
23
|
) {
|
|
24
|
+
const result = []
|
|
22
25
|
let filteredFields = fields.filter(
|
|
23
|
-
field =>
|
|
26
|
+
field =>
|
|
27
|
+
!BannedSearchTypes.includes(field.type) &&
|
|
28
|
+
(allowLinks || field.type !== "link")
|
|
24
29
|
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
for (const field of filteredFields) {
|
|
31
|
+
result.push(field)
|
|
32
|
+
|
|
33
|
+
if (allowLinks && field.type === "link") {
|
|
28
34
|
// only allow one depth of SQL relationship filtering
|
|
29
|
-
|
|
35
|
+
result.push(...getTableFields(tables, field))
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
const staticFormulaFields = fields.filter(
|
|
33
39
|
field => field.type === "formula" && field.formulaType === "static"
|
|
34
40
|
)
|
|
35
|
-
return
|
|
41
|
+
return result.concat(staticFormulaFields)
|
|
36
42
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { getFields, getTableFields } from "./searchFields.js"
|
|
3
|
+
|
|
4
|
+
const field = (name, type, extra = {}) => ({
|
|
5
|
+
name,
|
|
6
|
+
type,
|
|
7
|
+
...extra,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const table = (id, schema) => ({
|
|
11
|
+
_id: id,
|
|
12
|
+
name: id,
|
|
13
|
+
sql: true,
|
|
14
|
+
schema,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe("search fields", () => {
|
|
18
|
+
const relatedTable = table("t2", {
|
|
19
|
+
title: field("title", "string"),
|
|
20
|
+
otherLink: field("otherLink", "link", { tableId: "t3" }),
|
|
21
|
+
})
|
|
22
|
+
const baseTable = table("t1", {
|
|
23
|
+
name: field("name", "string"),
|
|
24
|
+
rel: field("rel", "link", { tableId: "t2" }),
|
|
25
|
+
})
|
|
26
|
+
const tables = [baseTable, relatedTable]
|
|
27
|
+
|
|
28
|
+
describe("getTableFields", () => {
|
|
29
|
+
it("excludes nested link fields when allowLinks is false", () => {
|
|
30
|
+
const fields = getTableFields(tables, baseTable.schema.rel)
|
|
31
|
+
expect(fields.map(field => field.name)).toEqual(["rel.title"])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("returns empty for non-sql related tables", () => {
|
|
35
|
+
const nonSqlTable = {
|
|
36
|
+
...relatedTable,
|
|
37
|
+
sql: false,
|
|
38
|
+
}
|
|
39
|
+
const fields = getTableFields([baseTable, nonSqlTable], {
|
|
40
|
+
...baseTable.schema.rel,
|
|
41
|
+
tableId: nonSqlTable._id,
|
|
42
|
+
})
|
|
43
|
+
expect(fields).toEqual([])
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe("getFields", () => {
|
|
48
|
+
it("excludes link fields when allowLinks is false", () => {
|
|
49
|
+
const fields = getFields(tables, Object.values(baseTable.schema), {
|
|
50
|
+
allowLinks: false,
|
|
51
|
+
})
|
|
52
|
+
expect(fields.map(field => field.name)).toEqual(["name"])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it("includes one relationship depth when allowLinks is true", () => {
|
|
56
|
+
const fields = getFields(tables, Object.values(baseTable.schema), {
|
|
57
|
+
allowLinks: true,
|
|
58
|
+
})
|
|
59
|
+
const names = fields.map(field => field.name)
|
|
60
|
+
expect(names).toEqual(
|
|
61
|
+
expect.arrayContaining(["name", "rel", "rel.title"])
|
|
62
|
+
)
|
|
63
|
+
expect(names).not.toEqual(expect.arrayContaining(["rel.otherLink"]))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it("appends static formula fields even when allowLinks is false", () => {
|
|
67
|
+
const withFormula = table("t4", {
|
|
68
|
+
name: field("name", "string"),
|
|
69
|
+
calc: field("calc", "formula", { formulaType: "static" }),
|
|
70
|
+
rel: field("rel", "link", { tableId: "t2" }),
|
|
71
|
+
})
|
|
72
|
+
const fields = getFields(tables, Object.values(withFormula.schema), {
|
|
73
|
+
allowLinks: false,
|
|
74
|
+
})
|
|
75
|
+
expect(fields.map(field => field.name)).toEqual(
|
|
76
|
+
expect.arrayContaining(["name", "calc"])
|
|
77
|
+
)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it("filters out banned field types", () => {
|
|
81
|
+
const withBanned = table("t5", {
|
|
82
|
+
name: field("name", "string"),
|
|
83
|
+
meta: field("meta", "json"),
|
|
84
|
+
files: field("files", "attachment"),
|
|
85
|
+
file: field("file", "attachment_single"),
|
|
86
|
+
})
|
|
87
|
+
const fields = getFields(tables, Object.values(withBanned.schema), {
|
|
88
|
+
allowLinks: false,
|
|
89
|
+
})
|
|
90
|
+
expect(fields.map(field => field.name)).toEqual(["name"])
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
package/vite.config.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineConfig } from "vite"
|
|
2
|
+
import path from "path"
|
|
3
|
+
|
|
4
|
+
export default defineConfig(() => {
|
|
5
|
+
return {
|
|
6
|
+
test: {
|
|
7
|
+
globals: true,
|
|
8
|
+
include: ["src/**/*.test.*", "src/**/*.spec.*"],
|
|
9
|
+
},
|
|
10
|
+
resolve: {
|
|
11
|
+
alias: [
|
|
12
|
+
{
|
|
13
|
+
find: "@budibase/types",
|
|
14
|
+
replacement: path.resolve("../types/src"),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
find: "@budibase/shared-core",
|
|
18
|
+
replacement: path.resolve("../shared-core/src"),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
})
|