From c82c6eaf340cb36d3a08884ed5ad707e76d2d2af Mon Sep 17 00:00:00 2001 From: J M <2364004+Blu-J@users.noreply.github.com> Date: Tue, 28 Jun 2022 13:57:51 -0600 Subject: [PATCH] fix: Properties had a null description (#1581) * fix: Properties had a null description * Update frontend/projects/ui/src/app/util/properties.util.ts --- .../ui/src/app/util/properties.util.ts | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/frontend/projects/ui/src/app/util/properties.util.ts b/frontend/projects/ui/src/app/util/properties.util.ts index 8d8b15619..7b5038fd0 100644 --- a/frontend/projects/ui/src/app/util/properties.util.ts +++ b/frontend/projects/ui/src/app/util/properties.util.ts @@ -24,9 +24,9 @@ const matchPropertiesV1 = shape( { name: string, value: string, - description: string, - copyable: boolean, - qr: boolean, + description: string.optional(), + copyable: boolean.optional(), + qr: boolean.optional(), }, ['description', 'copyable', 'qr'], { copyable: false, qr: false } as const, @@ -41,11 +41,11 @@ const [matchPackagePropertiesV2, setPPV2] = deferred() const matchPackagePropertyString = shape( { type: literal('string'), - description: string, + description: string.optional(), value: string, - copyable: boolean, - qr: boolean, - masked: boolean, + copyable: boolean.optional(), + qr: boolean.optional(), + masked: boolean.optional(), }, ['description', 'copyable', 'qr', 'masked'], { @@ -149,12 +149,12 @@ function parsePropertiesV1Permissive( } else { const error = result.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}`)) if (dataPath) { applyOperation(cur, { op: 'replace', - path: dataPath, + path: `/${dataPath}`, value: undefined, }) } @@ -179,12 +179,12 @@ function parsePropertiesV2Permissive( } else { const error = result.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}`)) if (dataPath) { applyOperation(properties, { op: 'replace', - path: dataPath, + path: `/${dataPath}`, 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[] export type PackageProperties = PackagePropertiesV2