fix: Properties had a null description (#1581)

* fix: Properties had a null description

* Update frontend/projects/ui/src/app/util/properties.util.ts
This commit is contained in:
J M
2022-06-28 13:57:51 -06:00
committed by GitHub
parent b8f3759739
commit c82c6eaf34

View File

@@ -24,9 +24,9 @@ const matchPropertiesV1 = shape(
{ {
name: string, name: string,
value: string, value: string,
description: string, description: string.optional(),
copyable: boolean, copyable: boolean.optional(),
qr: boolean, qr: boolean.optional(),
}, },
['description', 'copyable', 'qr'], ['description', 'copyable', 'qr'],
{ copyable: false, qr: false } as const, { copyable: false, qr: false } as const,
@@ -41,11 +41,11 @@ const [matchPackagePropertiesV2, setPPV2] = deferred<PackagePropertiesV2>()
const matchPackagePropertyString = shape( const matchPackagePropertyString = shape(
{ {
type: literal('string'), type: literal('string'),
description: string, description: string.optional(),
value: string, value: string,
copyable: boolean, copyable: boolean.optional(),
qr: boolean, qr: boolean.optional(),
masked: boolean, masked: boolean.optional(),
}, },
['description', 'copyable', 'qr', 'masked'], ['description', 'copyable', 'qr', 'masked'],
{ {
@@ -149,12 +149,12 @@ function parsePropertiesV1Permissive(
} else { } else {
const error = result.error const error = result.error
const message = Parser.validatorErrorAsString(error) const message = Parser.validatorErrorAsString(error)
let dataPath = error.keys.map(x => JSON.parse(x)).join('/') const dataPath = error.keys.map(removeQuotes).join('/')
errorCallback(new Error(`/data/${idx}: ${message}`)) errorCallback(new Error(`/data/${idx}: ${message}`))
if (dataPath) { if (dataPath) {
applyOperation(cur, { applyOperation(cur, {
op: 'replace', op: 'replace',
path: dataPath, path: `/${dataPath}`,
value: undefined, value: undefined,
}) })
} }
@@ -179,12 +179,12 @@ function parsePropertiesV2Permissive(
} else { } else {
const error = result.error const error = result.error
const message = Parser.validatorErrorAsString(error) const message = Parser.validatorErrorAsString(error)
let dataPath = error.keys.map(x => JSON.parse(x)).join('/') const dataPath = error.keys.map(removeQuotes).join('/')
errorCallback(new Error(`/data/${idx}: ${message}`)) errorCallback(new Error(`/data/${idx}: ${message}`))
if (dataPath) { if (dataPath) {
applyOperation(properties, { applyOperation(properties, {
op: 'replace', op: 'replace',
path: dataPath, path: `/${dataPath}`,
value: undefined, value: undefined,
}) })
} }
@@ -196,6 +196,14 @@ function parsePropertiesV2Permissive(
) )
} }
const removeRegex = /('|")/
function removeQuotes(x: string) {
while (removeRegex.test(x)) {
x = x.replace(removeRegex, '')
}
return x
}
type PackagePropertiesV1 = PropertiesV1[] type PackagePropertiesV1 = PropertiesV1[]
export type PackageProperties = PackagePropertiesV2 export type PackageProperties = PackagePropertiesV2