Skip to content

Commit d63cb9f

Browse files
committed
fix: remove unused conditions from formData
reduce payload size
1 parent bef03b6 commit d63cb9f

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/lib/js/components/controls/form/button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ButtonControl extends Control {
2020
options: [
2121
{
2222
label: i18n.get('button'),
23-
type: ['button', 'submit', 'reset'].map((buttonType, index) => ({
23+
type: ['button', 'submit', 'reset'].map((buttonType) => ({
2424
label: buttonType,
2525
type: buttonType,
2626
})),

src/lib/js/components/fields/edit-panel.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import actions from '../../common/actions.js'
44
import EditPanelItem from './edit-panel-item.mjs'
55
import { capitalize } from '../../common/helpers.mjs'
66
import { slugify, toTitleCase } from '../../common/utils/string.mjs'
7-
import { cleanObj } from '../../common/utils/object.mjs'
87

98
/**
109
* Element/Field class.
@@ -176,8 +175,7 @@ export default class EditPanel {
176175
field: this.field,
177176
index: this.props.children.length,
178177
})
179-
180-
// debugger
178+
181179
this.editPanelItems.push(newOption)
182180
this.props.appendChild(newOption.dom)
183181
this.field.set(itemKey, itemData)

src/lib/js/components/fields/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ export class Fields extends ComponentData {
4040
}
4141
return found
4242
}
43+
44+
getData = () => {
45+
return Object.entries(this.data).reduce((acc, [key, val]) => {
46+
const { conditions, ...data } = val?.getData() || val
47+
48+
if (conditions?.length) {
49+
let hasConditions = true
50+
if (conditions.length === 1) {
51+
const [firstCondition] = conditions
52+
hasConditions = Boolean(firstCondition.if[0].source && firstCondition.then[0].target)
53+
}
54+
if (hasConditions) {
55+
data.conditions = conditions
56+
}
57+
}
58+
59+
acc[key] = data
60+
return acc
61+
}, {})
62+
}
4363
}
4464

4565
const fields = new Fields()

0 commit comments

Comments
 (0)