Skip to content

Commit

Permalink
fix: remove unused conditions from formData
Browse files Browse the repository at this point in the history
reduce payload size
  • Loading branch information
kevinchappell committed Nov 19, 2024
1 parent bef03b6 commit d63cb9f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/js/components/controls/form/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ButtonControl extends Control {
options: [
{
label: i18n.get('button'),
type: ['button', 'submit', 'reset'].map((buttonType, index) => ({
type: ['button', 'submit', 'reset'].map((buttonType) => ({
label: buttonType,
type: buttonType,
})),
Expand Down
4 changes: 1 addition & 3 deletions src/lib/js/components/fields/edit-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import actions from '../../common/actions.js'
import EditPanelItem from './edit-panel-item.mjs'
import { capitalize } from '../../common/helpers.mjs'
import { slugify, toTitleCase } from '../../common/utils/string.mjs'
import { cleanObj } from '../../common/utils/object.mjs'

/**
* Element/Field class.
Expand Down Expand Up @@ -176,8 +175,7 @@ export default class EditPanel {
field: this.field,
index: this.props.children.length,
})

// debugger

this.editPanelItems.push(newOption)
this.props.appendChild(newOption.dom)
this.field.set(itemKey, itemData)
Expand Down
20 changes: 20 additions & 0 deletions src/lib/js/components/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ export class Fields extends ComponentData {
}
return found
}

getData = () => {
return Object.entries(this.data).reduce((acc, [key, val]) => {
const { conditions, ...data } = val?.getData() || val

if (conditions?.length) {
let hasConditions = true
if (conditions.length === 1) {
const [firstCondition] = conditions
hasConditions = Boolean(firstCondition.if[0].source && firstCondition.then[0].target)
}
if (hasConditions) {
data.conditions = conditions
}
}

acc[key] = data
return acc
}, {})
}
}

const fields = new Fields()
Expand Down

0 comments on commit d63cb9f

Please sign in to comment.