Skip to content

Commit

Permalink
Handle empty object in web actions (cashapp#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahexiao authored May 17, 2023
1 parent 6782b81 commit f85afaa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
5 changes: 4 additions & 1 deletion misk-admin/web/tabs/web-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"@misk/prettier": "0.4.0",
"@misk/tslint": "0.4.0",
"tslib": "2.3.0",
"@misk/cli": "0.4.0"
"@misk/cli": "0.4.0",
"webpack": "4.43.0",
"webpack-cli": "3.3.11",
"webpack-dev-server": "3.11.0"
},
"jest": {
"testEnvironment": "jsdom",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from "react"
import {
Button,
Checkbox,
Collapse,
HTMLSelect,
Icon,
Expand Down Expand Up @@ -220,27 +221,38 @@ function FormObjectComponent({
protoType={field.type}
>
<div style={{ marginLeft: "12px" }}>
{complexType.fields.map(subField => {
return (
<FormComponent
webActionMetadata={webActionMetadata}
field={subField}
onChange={newChildVal => {
const newValue = _(_.clone(value) || {})
.set(subField.name, newChildVal)
.omitBy(_.isNull)
.value()
{complexType.fields.length > 0 ? (
complexType.fields.map(subField => {
return (
<FormComponent
webActionMetadata={webActionMetadata}
field={subField}
onChange={newChildVal => {
const newValue = _(_.clone(value) || {})
.set(subField.name, newChildVal)
.omitBy(_.isNull)
.value()

if (_.isEmpty(newValue)) {
onChange(null)
} else {
onChange(newValue)
}
}}
value={_.get(value, subField.name, null)}
/>
)
})}
if (_.isEmpty(newValue)) {
onChange(null)
} else {
onChange(newValue)
}
}}
value={_.get(value, subField.name, null)}
/>
)
})
) : (
<Checkbox
onChange={e => {
const value = e.currentTarget.checked
onChange(value ? {} : undefined)
}}
>
Add as an empty object
</Checkbox>
)}
</div>
</FormComponentWrapper>
)
Expand Down

0 comments on commit f85afaa

Please sign in to comment.