From af6e4486a4358e343b4723a86576a7322cf69297 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Wed, 30 Jun 2021 11:50:53 -0700 Subject: [PATCH 1/2] Fixed schema definition --- .../attribute/CustomAttributeDefinition.js | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js index 0ec36e44b..a9f329794 100644 --- a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js +++ b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js @@ -61,7 +61,7 @@ export const CustomAttributeDefinition = { return data; } const { attributeType } = data; - let { defaultValueBoolean, defaultValueString, ...parsed } = data; + let { defaultValueBoolean, ...parsed } = data; if (attributeType === 'SELECTION_LIST') { parsed = { ...parsed, @@ -77,13 +77,6 @@ export const CustomAttributeDefinition = { } } - if (attributeType === 'STRING') { - parsed = { - ...parsed, - defaultValue: defaultValueString - } - } - return parsed; }, @@ -94,30 +87,28 @@ export const CustomAttributeDefinition = { let { defaultValue, ...formatted } = changes; const { attributeType } = changes; - if (attributeType === 'SELECTION_LIST') { - formatted = { - ...formatted, - customAttrListDefinitions: formatted.customAttrListDefinitions.map(d => ({ - value: d, - default: d === defaultValue - })) - } - } - - if (attributeType === 'BOOLEAN') { - formatted = { - ...formatted, - defaultValueBoolean: formatted.defaultValue === 'true' ? true : false, - invert: formatted.invert === 'true' ? true : false -// defaultValueBoolean: defaultValue === 'true' ? true : false - } - } - - if (attributeType === 'STRING') { - formatted = { - ...formatted, - defaultValueString: defaultValue - } + switch (attributeType) { + case 'SELECTION_LIST': + formatted = { + ...formatted, + customAttrListDefinitions: formatted.customAttrListDefinitions.map(d => ({ + value: d, + default: d === defaultValue + })) + } + break; + case 'BOOLEAN': + formatted = { + ...formatted, + defaultValueBoolean: formatted.defaultValue === 'true' ? true : false, + invert: formatted.invert === 'true' ? true : false + } + break; + default: + formatted = { + ...formatted, + defaultValue + } } return formatted; From 01c8b225845ba693d2058dfca820ea7fef2f955c Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Wed, 30 Jun 2021 12:57:15 -0700 Subject: [PATCH 2/2] Fixed unit test --- .../domain/attribute/CustomAttributeDefinition.js | 2 +- .../domain/attribute/CustomAttributeDefinition.test.js | 10 ++++++---- ui/src/app/metadata/domain/transform.test.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js index a9f329794..cf671e547 100644 --- a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js +++ b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.js @@ -100,7 +100,7 @@ export const CustomAttributeDefinition = { case 'BOOLEAN': formatted = { ...formatted, - defaultValueBoolean: formatted.defaultValue === 'true' ? true : false, + defaultValueBoolean: defaultValue === 'true' ? true : false, invert: formatted.invert === 'true' ? true : false } break; diff --git a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.test.js b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.test.js index 9fbbe6e6c..3b6c865ca 100644 --- a/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.test.js +++ b/ui/src/app/metadata/domain/attribute/CustomAttributeDefinition.test.js @@ -25,10 +25,12 @@ describe('formatter', () => { expect(CustomAttributeDefinition.formatter({ attributeType: 'BOOLEAN', - defaultValue: 'true' + defaultValue: 'true', + invert: 'true' })).toEqual({ attributeType: 'BOOLEAN', - defaultValueBoolean: true + defaultValueBoolean: true, + invert: true }); expect(CustomAttributeDefinition.formatter({ @@ -36,7 +38,7 @@ describe('formatter', () => { defaultValue: 'true' })).toEqual({ attributeType: 'STRING', - defaultValueString: 'true' + defaultValue: 'true' }); }); }); @@ -72,7 +74,7 @@ describe('parser', () => { expect(CustomAttributeDefinition.parser({ attributeType: 'STRING', - defaultValueString: 'true' + defaultValue: 'true' })).toEqual({ attributeType: 'STRING', defaultValue: 'true' diff --git a/ui/src/app/metadata/domain/transform.test.js b/ui/src/app/metadata/domain/transform.test.js index 1ae2c8fa7..1b3109906 100644 --- a/ui/src/app/metadata/domain/transform.test.js +++ b/ui/src/app/metadata/domain/transform.test.js @@ -12,7 +12,7 @@ const errors = [ it('should transform error messages', () => { expect(transformErrors(errors)).toEqual([ { name: 'pattern', property: '/email', message: 'message.valid-email' }, - { name: 'pattern', property: 'foo', message: 'message.valid-duration' }, + { name: 'pattern', property: 'foo', message: 'message.duration' }, { name: 'type', message: 'bar' }, { name: 'type', message: 'message.required' } ]);