@budibase/frontend-core 2.13.31 → 2.13.32
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 +4 -4
- package/src/utils/utils.js +135 -0
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.32",
|
|
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.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@budibase/bbui": "2.13.
|
|
10
|
-
"@budibase/shared-core": "2.13.
|
|
9
|
+
"@budibase/bbui": "2.13.32",
|
|
10
|
+
"@budibase/shared-core": "2.13.32",
|
|
11
11
|
"dayjs": "^1.10.8",
|
|
12
12
|
"lodash": "^4.17.21",
|
|
13
13
|
"socket.io-client": "^4.6.1",
|
|
14
14
|
"svelte": "^3.46.2"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "e0118d45fe9dcd9fc6649380f67c6656d27f39c8"
|
|
17
17
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { makePropSafe as safe } from "@budibase/string-templates"
|
|
2
|
+
import { Helpers } from "@budibase/bbui"
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Utility to wrap an async function and ensure all invocations happen
|
|
3
6
|
* sequentially.
|
|
@@ -106,3 +109,135 @@ export const domDebounce = callback => {
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Build the default FormBlock button configs per actionType
|
|
115
|
+
* Parse any legacy button config and mirror its the outcome
|
|
116
|
+
*
|
|
117
|
+
* @param {any} props
|
|
118
|
+
* */
|
|
119
|
+
export const buildDynamicButtonConfig = props => {
|
|
120
|
+
const {
|
|
121
|
+
_id,
|
|
122
|
+
actionType,
|
|
123
|
+
dataSource,
|
|
124
|
+
notificationOverride,
|
|
125
|
+
actionUrl,
|
|
126
|
+
showDeleteButton,
|
|
127
|
+
deleteButtonLabel,
|
|
128
|
+
showSaveButton,
|
|
129
|
+
saveButtonLabel,
|
|
130
|
+
} = props || {}
|
|
131
|
+
|
|
132
|
+
if (!_id) {
|
|
133
|
+
console.log("MISSING ID")
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
const formId = `${_id}-form`
|
|
137
|
+
const repeaterId = `${_id}-repeater`
|
|
138
|
+
const resourceId = dataSource?.resourceId
|
|
139
|
+
|
|
140
|
+
// Accommodate old config to ensure delete button does not reappear
|
|
141
|
+
const deleteText = showDeleteButton === false ? "" : deleteButtonLabel?.trim()
|
|
142
|
+
const saveText = showSaveButton === false ? "" : saveButtonLabel?.trim()
|
|
143
|
+
|
|
144
|
+
const onSave = [
|
|
145
|
+
{
|
|
146
|
+
"##eventHandlerType": "Validate Form",
|
|
147
|
+
parameters: {
|
|
148
|
+
componentId: formId,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"##eventHandlerType": "Save Row",
|
|
153
|
+
parameters: {
|
|
154
|
+
providerId: formId,
|
|
155
|
+
tableId: resourceId,
|
|
156
|
+
notificationOverride,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"##eventHandlerType": "Close Screen Modal",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"##eventHandlerType": "Close Side Panel",
|
|
164
|
+
},
|
|
165
|
+
// Clear a create form once submitted
|
|
166
|
+
...(actionType !== "Create"
|
|
167
|
+
? []
|
|
168
|
+
: [
|
|
169
|
+
{
|
|
170
|
+
"##eventHandlerType": "Clear Form",
|
|
171
|
+
parameters: {
|
|
172
|
+
componentId: formId,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
]),
|
|
176
|
+
|
|
177
|
+
...(actionUrl
|
|
178
|
+
? [
|
|
179
|
+
{
|
|
180
|
+
"##eventHandlerType": "Navigate To",
|
|
181
|
+
parameters: {
|
|
182
|
+
url: actionUrl,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
]
|
|
186
|
+
: []),
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
const onDelete = [
|
|
190
|
+
{
|
|
191
|
+
"##eventHandlerType": "Delete Row",
|
|
192
|
+
parameters: {
|
|
193
|
+
confirm: true,
|
|
194
|
+
tableId: resourceId,
|
|
195
|
+
rowId: `{{ ${safe(repeaterId)}.${safe("_id")} }}`,
|
|
196
|
+
revId: `{{ ${safe(repeaterId)}.${safe("_rev")} }}`,
|
|
197
|
+
notificationOverride,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"##eventHandlerType": "Close Screen Modal",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"##eventHandlerType": "Close Side Panel",
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
...(actionUrl
|
|
208
|
+
? [
|
|
209
|
+
{
|
|
210
|
+
"##eventHandlerType": "Navigate To",
|
|
211
|
+
parameters: {
|
|
212
|
+
url: actionUrl,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
]
|
|
216
|
+
: []),
|
|
217
|
+
]
|
|
218
|
+
|
|
219
|
+
const defaultButtons = []
|
|
220
|
+
|
|
221
|
+
if (["Update", "Create"].includes(actionType) && showSaveButton !== false) {
|
|
222
|
+
defaultButtons.push({
|
|
223
|
+
text: saveText || "Save",
|
|
224
|
+
_id: Helpers.uuid(),
|
|
225
|
+
_component: "@budibase/standard-components/button",
|
|
226
|
+
onClick: onSave,
|
|
227
|
+
type: "cta",
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (actionType == "Update" && showDeleteButton !== false) {
|
|
232
|
+
defaultButtons.push({
|
|
233
|
+
text: deleteText || "Delete",
|
|
234
|
+
_id: Helpers.uuid(),
|
|
235
|
+
_component: "@budibase/standard-components/button",
|
|
236
|
+
onClick: onDelete,
|
|
237
|
+
quiet: true,
|
|
238
|
+
type: "secondary",
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return defaultButtons
|
|
243
|
+
}
|