@budibase/frontend-core 3.3.3 → 3.3.5
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 +2 -2
- package/src/utils/{utils.js → utils.ts} +53 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"svelte-check": "^4.1.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "e7d337d75d1d36365d07aa7bfa273db522bbe822"
|
|
24
24
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { makePropSafe as safe } from "@budibase/string-templates"
|
|
2
2
|
import { Helpers } from "@budibase/bbui"
|
|
3
3
|
import { cloneDeep } from "lodash"
|
|
4
|
+
import { SearchFilterGroup, UISearchFilter } from "@budibase/types"
|
|
4
5
|
|
|
5
|
-
export const sleep = ms
|
|
6
|
+
export const sleep = (ms: number) =>
|
|
7
|
+
new Promise(resolve => setTimeout(resolve, ms))
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Utility to wrap an async function and ensure all invocations happen
|
|
@@ -10,12 +12,18 @@ export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
|
10
12
|
* @param fn the async function to run
|
|
11
13
|
* @return {Function} a sequential version of the function
|
|
12
14
|
*/
|
|
13
|
-
export const sequential =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export const sequential = <
|
|
16
|
+
TReturn,
|
|
17
|
+
TFunction extends (...args: any[]) => Promise<TReturn>
|
|
18
|
+
>(
|
|
19
|
+
fn: TFunction
|
|
20
|
+
): TFunction => {
|
|
21
|
+
let queue: (() => Promise<void>)[] = []
|
|
22
|
+
const result = (...params: Parameters<TFunction>) => {
|
|
23
|
+
return new Promise<TReturn>((resolve, reject) => {
|
|
17
24
|
queue.push(async () => {
|
|
18
|
-
let data
|
|
25
|
+
let data: TReturn | undefined
|
|
26
|
+
let error: unknown
|
|
19
27
|
try {
|
|
20
28
|
data = await fn(...params)
|
|
21
29
|
} catch (err) {
|
|
@@ -28,7 +36,7 @@ export const sequential = fn => {
|
|
|
28
36
|
if (error) {
|
|
29
37
|
reject(error)
|
|
30
38
|
} else {
|
|
31
|
-
resolve(data)
|
|
39
|
+
resolve(data!)
|
|
32
40
|
}
|
|
33
41
|
})
|
|
34
42
|
if (queue.length === 1) {
|
|
@@ -36,6 +44,7 @@ export const sequential = fn => {
|
|
|
36
44
|
}
|
|
37
45
|
})
|
|
38
46
|
}
|
|
47
|
+
return result as TFunction
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
/**
|
|
@@ -45,9 +54,9 @@ export const sequential = fn => {
|
|
|
45
54
|
* @param minDelay the minimum delay between invocations
|
|
46
55
|
* @returns a debounced version of the callback
|
|
47
56
|
*/
|
|
48
|
-
export const debounce = (callback, minDelay = 1000) => {
|
|
49
|
-
let timeout
|
|
50
|
-
return async (...params) => {
|
|
57
|
+
export const debounce = (callback: Function, minDelay = 1000) => {
|
|
58
|
+
let timeout: ReturnType<typeof setTimeout>
|
|
59
|
+
return async (...params: any[]) => {
|
|
51
60
|
return new Promise(resolve => {
|
|
52
61
|
if (timeout) {
|
|
53
62
|
clearTimeout(timeout)
|
|
@@ -70,11 +79,11 @@ export const debounce = (callback, minDelay = 1000) => {
|
|
|
70
79
|
* @param minDelay
|
|
71
80
|
* @returns {Function} a throttled version function
|
|
72
81
|
*/
|
|
73
|
-
export const throttle = (callback, minDelay = 1000) => {
|
|
74
|
-
let lastParams
|
|
82
|
+
export const throttle = (callback: Function, minDelay = 1000) => {
|
|
83
|
+
let lastParams: any[]
|
|
75
84
|
let stalled = false
|
|
76
85
|
let pending = false
|
|
77
|
-
const invoke = (...params) => {
|
|
86
|
+
const invoke = (...params: any[]) => {
|
|
78
87
|
lastParams = params
|
|
79
88
|
if (stalled) {
|
|
80
89
|
pending = true
|
|
@@ -98,10 +107,10 @@ export const throttle = (callback, minDelay = 1000) => {
|
|
|
98
107
|
* @param callback the function to run
|
|
99
108
|
* @returns {Function}
|
|
100
109
|
*/
|
|
101
|
-
export const domDebounce = callback => {
|
|
110
|
+
export const domDebounce = (callback: Function) => {
|
|
102
111
|
let active = false
|
|
103
|
-
let lastParams
|
|
104
|
-
return (...params) => {
|
|
112
|
+
let lastParams: any[]
|
|
113
|
+
return (...params: any[]) => {
|
|
105
114
|
lastParams = params
|
|
106
115
|
if (!active) {
|
|
107
116
|
active = true
|
|
@@ -119,7 +128,17 @@ export const domDebounce = callback => {
|
|
|
119
128
|
*
|
|
120
129
|
* @param {any} props
|
|
121
130
|
* */
|
|
122
|
-
export const buildFormBlockButtonConfig = props
|
|
131
|
+
export const buildFormBlockButtonConfig = (props?: {
|
|
132
|
+
_id?: string
|
|
133
|
+
actionType?: string
|
|
134
|
+
dataSource?: { resourceId: string }
|
|
135
|
+
notificationOverride?: boolean
|
|
136
|
+
actionUrl?: string
|
|
137
|
+
showDeleteButton?: boolean
|
|
138
|
+
deleteButtonLabel?: string
|
|
139
|
+
showSaveButton?: boolean
|
|
140
|
+
saveButtonLabel?: string
|
|
141
|
+
}) => {
|
|
123
142
|
const {
|
|
124
143
|
_id,
|
|
125
144
|
actionType,
|
|
@@ -227,7 +246,11 @@ export const buildFormBlockButtonConfig = props => {
|
|
|
227
246
|
|
|
228
247
|
const defaultButtons = []
|
|
229
248
|
|
|
230
|
-
if (
|
|
249
|
+
if (
|
|
250
|
+
actionType &&
|
|
251
|
+
["Update", "Create"].includes(actionType) &&
|
|
252
|
+
showSaveButton !== false
|
|
253
|
+
) {
|
|
231
254
|
defaultButtons.push({
|
|
232
255
|
text: saveText || "Save",
|
|
233
256
|
_id: Helpers.uuid(),
|
|
@@ -251,7 +274,13 @@ export const buildFormBlockButtonConfig = props => {
|
|
|
251
274
|
return defaultButtons
|
|
252
275
|
}
|
|
253
276
|
|
|
254
|
-
export const buildMultiStepFormBlockDefaultProps = props
|
|
277
|
+
export const buildMultiStepFormBlockDefaultProps = (props?: {
|
|
278
|
+
_id: string
|
|
279
|
+
stepCount: number
|
|
280
|
+
currentStep: number
|
|
281
|
+
actionType: string
|
|
282
|
+
dataSource: { resourceId: string }
|
|
283
|
+
}) => {
|
|
255
284
|
const { _id, stepCount, currentStep, actionType, dataSource } = props || {}
|
|
256
285
|
|
|
257
286
|
// Sanity check
|
|
@@ -361,7 +390,7 @@ export const buildMultiStepFormBlockDefaultProps = props => {
|
|
|
361
390
|
* @param {Object} filter UI filter
|
|
362
391
|
* @returns {Object} parsed filter
|
|
363
392
|
*/
|
|
364
|
-
export function parseFilter(filter) {
|
|
393
|
+
export function parseFilter(filter: UISearchFilter) {
|
|
365
394
|
if (!filter?.groups) {
|
|
366
395
|
return filter
|
|
367
396
|
}
|
|
@@ -369,13 +398,13 @@ export function parseFilter(filter) {
|
|
|
369
398
|
const update = cloneDeep(filter)
|
|
370
399
|
|
|
371
400
|
update.groups = update.groups
|
|
372
|
-
|
|
373
|
-
group.filters = group.filters
|
|
401
|
+
?.map(group => {
|
|
402
|
+
group.filters = group.filters?.filter((filter: any) => {
|
|
374
403
|
return filter.field && filter.operator
|
|
375
404
|
})
|
|
376
|
-
return group.filters
|
|
405
|
+
return group.filters?.length ? group : null
|
|
377
406
|
})
|
|
378
|
-
.filter(group => group)
|
|
407
|
+
.filter((group): group is SearchFilterGroup => !!group)
|
|
379
408
|
|
|
380
409
|
return update
|
|
381
410
|
}
|