Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Schwartz committed Oct 12, 2023
1 parent 2dfe70b commit 87c8e47
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions engine/frontend/src/component/PackageCatalogForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const renderArgs = (args, handleChange, formData, errorData, packageName) => {
return
}

let dataType = "STRING";
let dataType = "JSON";
try {
switch (getType(arg)) {
case "INTEGER":
Expand Down Expand Up @@ -183,24 +183,38 @@ const renderSingleArg = (fieldName, type, errorData, formData, index, handleChan

const checkValidUndefinedType = (data) => {
try {
const val = yaml.load(data)
yaml.load(data)
} catch (ex) {
return false;
}
return true;
}

const checkValidJsonType = (data) => {
if (data === undefined || data === "undefined" || data.length === 0) {
return false
}

try {
JSON.parse(JSON.stringify(data))
return true;
} catch (ex) {
return false
const checkValidJsonType = (rawData, required) => {
// data is normally going to be a string serialized json object as it comes from the CodeEditor, so we try and process it as such
if (typeof rawData === "string") {
try {
const parsed = JSON.parse(rawData)
if (required && Object.keys(parsed).length < 1) {
return false
}
return true;
} catch (ex) {
console.error("Data is not serialized json", rawData)
return false
}
} else if (typeof rawData === "object") {
// if it's already an object then we only check that it's non-empty (if it's required)
try {
if (required && Object.keys(rawData).length < 1) {
return false
}
return true;
} catch (ex) {
return false
}
}
console.error(`Data is unknown type ${typeof rawData}`, rawData)
}

const checkValidStringType = (data) => {
Expand Down Expand Up @@ -448,14 +462,15 @@ const PackageCatalogForm = ({createEnclave, mode}) => {
let subType = getFirstSubType(arg)
valid = checkValidListType(formData[key], subType)
} else if (type === "DICT") {
valid = checkValidJsonType(formData[key])
valid = checkValidJsonType(formData[key], required)
} else if (type === "JSON") {
valid = checkValidJsonType(formData[key])
// required = false, always because we have a later check that ensures the object is not null
valid = checkValidJsonType(formData[key], false)
} else {
valid = checkValidUndefinedType(formData[key])
}

let typeToPrint = type
let typeToPrint
if (type === undefined) {
typeToPrint = "JSON"
} else if (type === "BOOL") {
Expand Down Expand Up @@ -533,14 +548,17 @@ const PackageCatalogForm = ({createEnclave, mode}) => {
console.error(`Data field '${argName}' was not a valid object but was type ${typeof value}. Contained value: '${value}'`)
}
} else {
val = JSON.parse(value)
args[argName] = val
try {
val = JSON.parse(value)
args[argName] = val
} catch (ex) {
console.error(`Data field '${argName}' was not a valid object but was type ${typeof value}. Contained value: '${value}'`)
}
}
}
})

console.log("args", args)

console.log("raw args", args)
const stringifiedArgs = JSON.stringify(args)
const runKurtosisPackageArgs = {
packageId: thisKurtosisPackage.name,
Expand Down

0 comments on commit 87c8e47

Please sign in to comment.