1
0
Fork 0
mirror of synced 2024-09-11 06:56:23 +12:00

Try/catch automation Create Row relationship (#9924)

* Try/catch

* Increase height of automation test output

* Unit tests

* lint
This commit is contained in:
melohagan 2023-03-08 13:39:18 +00:00 committed by GitHub
parent 33a9c8d215
commit a8f873fff3
3 changed files with 78 additions and 5 deletions

View file

@ -73,14 +73,14 @@
<Tabs noHorizPadding selected="Input"> <Tabs noHorizPadding selected="Input">
<Tab title="Input"> <Tab title="Input">
<TextArea <TextArea
minHeight="80px" minHeight="160px"
disabled disabled
value={textArea(filteredResults?.[idx]?.inputs, "No input")} value={textArea(filteredResults?.[idx]?.inputs, "No input")}
/> />
</Tab> </Tab>
<Tab title="Output"> <Tab title="Output">
<TextArea <TextArea
minHeight="100px" minHeight="160px"
disabled disabled
value={textArea(filteredResults?.[idx]?.outputs, "No output")} value={textArea(filteredResults?.[idx]?.outputs, "No output")}
/> />
@ -98,8 +98,9 @@
<style> <style>
.container { .container {
padding: 0 30px 0 30px; padding: 0 30px 30px 30px;
height: 100%; height: 100%;
overflow: auto;
} }
.tabs { .tabs {

View file

@ -52,14 +52,18 @@ export function cleanInputValues(inputs: Record<string, any>, schema: any) {
} }
} }
} }
//Check if input field should be a relationship and cast to array //Check if input field for Update Row should be a relationship and cast to array
for (let key in inputs.row) { for (let key in inputs.row) {
if ( if (
inputs.schema?.[key]?.type === "link" && inputs.schema?.[key]?.type === "link" &&
inputs.row[key] && inputs.row[key] &&
typeof inputs.row[key] === "string" typeof inputs.row[key] === "string"
) { ) {
inputs.row[key] = JSON.parse(inputs.row[key]) try {
inputs.row[key] = JSON.parse(inputs.row[key])
} catch (e) {
//Link is not an array or object, so continue
}
} }
} }
return inputs return inputs

View file

@ -62,4 +62,72 @@ describe("automationUtils", () => {
).toThrow() ).toThrow()
}) })
}) })
describe("cleanInputValues", () => {
it("should handle array relationship fields from read binding", () => {
const schema = {
relationship: {
type: "link",
constraints: {
type: "array",
presence: false,
},
fieldName: "Users",
name: "relationship",
relationshipType: "many-to-many",
tableId: "ta_users",
sortable: false,
},
}
expect(
automationUtils.cleanInputValues(
{
row: {
relationship: `[{"_id": "ro_ta_users_us_3"}]`,
},
schema,
},
schema
)
).toEqual({
row: {
relationship: [{ _id: "ro_ta_users_us_3" }],
},
schema,
})
})
it("should handle single string relationship field", () => {
const schema = {
relationship: {
type: "link",
constraints: {
type: "array",
presence: false,
},
fieldName: "Users",
name: "relationship",
relationshipType: "many-to-many",
tableId: "ta_users",
sortable: false,
},
}
expect(
automationUtils.cleanInputValues(
{
row: {
relationship: `ro_ta_users_us_3`,
},
schema,
},
schema
)
).toEqual({
row: {
relationship: "ro_ta_users_us_3",
},
schema,
})
})
})
}) })