@@ -17,13 +17,14 @@ export const EditComponent = defineComponent({
1717 setup ( props , { emit } ) {
1818 const internalValue = ref ( { } as ListItemBag ) ;
1919
20+ // The selected Entity Type.
2021 const entityTypeGuid = computed ( ( ) : string | null | undefined => {
21- const entityType = JSON . parse ( props . configurationValues [ ConfigurationValueKey . EntityTypeName ] ?? "{}" ) as ListItemBag ;
22+ const entityType = JSON . parse ( props . configurationValues [ ConfigurationValueKey . EntityType ] ?? "{}" ) as ListItemBag ;
2223 return entityType ?. value ;
2324 } ) ;
2425
2526 watch ( ( ) => props . modelValue , ( ) => {
26- internalValue . value = JSON . parse ( props . modelValue || "{} " ) ;
27+ internalValue . value = JSON . parse ( props . modelValue || "null " ) ;
2728 } , { immediate : true } ) ;
2829
2930 watch ( ( ) => internalValue . value , ( ) => {
@@ -56,7 +57,31 @@ export const ConfigurationComponent = defineComponent({
5657 ] ,
5758
5859 setup ( props , { emit } ) {
59- const entityType = ref ( { } as ListItemBag ) ;
60+ const entityType = ref < ListItemBag > ( ) ;
61+
62+ // Compute a consistent entity type string value to compare against.
63+ const entityTypeStringFromProps = computed ( ( ) : string => {
64+ const propsString = props . modelValue [ ConfigurationValueKey . EntityType ] ;
65+ if ( ! propsString ) {
66+ return "{}" ;
67+ }
68+
69+ try {
70+ // It's possible for propsString to be "null", in which case we
71+ // want to default to an empty object for consistent comparison.
72+ return JSON . stringify (
73+ JSON . parse ( propsString ) ?? { }
74+ ) ;
75+ }
76+ catch {
77+ return "{}" ;
78+ }
79+ } ) ;
80+
81+ // Compute a consistent entity type object value to compare against.
82+ const entityTypeFromProps = computed ( ( ) : ListItemBag => {
83+ return JSON . parse ( entityTypeStringFromProps . value ) ;
84+ } ) ;
6085
6186 /**
6287 * Update the modelValue property if any value of the dictionary has
@@ -71,10 +96,10 @@ export const ConfigurationComponent = defineComponent({
7196
7297 // Construct the new value that will be emitted if it is different
7398 // than the current value.
74- newValue [ ConfigurationValueKey . EntityTypeName ] = JSON . stringify ( entityType . value ?? "" ) ;
99+ newValue [ ConfigurationValueKey . EntityType ] = JSON . stringify ( entityType . value ?? { } ) ;
75100
76101 // Compare the new value and the old value.
77- const anyValueChanged = newValue [ ConfigurationValueKey . EntityTypeName ] !== ( props . modelValue [ ConfigurationValueKey . EntityTypeName ] ?? "" ) ;
102+ const anyValueChanged = newValue [ ConfigurationValueKey . EntityType ] !== entityTypeStringFromProps . value ;
78103
79104 // If any value changed then emit the new model value.
80105 if ( anyValueChanged ) {
@@ -102,12 +127,12 @@ export const ConfigurationComponent = defineComponent({
102127 // Watch for changes coming in from the parent component and update our
103128 // data to match the new information.
104129 watch ( ( ) => [ props . modelValue , props . configurationProperties ] , ( ) => {
105- entityType . value = JSON . parse ( props . modelValue [ ConfigurationValueKey . EntityTypeName ] || "{}" ) ;
130+ entityType . value = entityTypeFromProps . value ;
106131 } , {
107132 immediate : true
108133 } ) ;
109134
110- watch ( entityType , val => maybeUpdateConfiguration ( ConfigurationValueKey . EntityTypeName , JSON . stringify ( val ?? "" ) ) ) ;
135+ watch ( entityType , ( ) => maybeUpdateConfiguration ( ConfigurationValueKey . EntityType , JSON . stringify ( entityType . value ?? { } ) ) ) ;
111136
112137 return {
113138 entityType
@@ -119,4 +144,4 @@ export const ConfigurationComponent = defineComponent({
119144 <EntityTypePicker label="Entity Type" v-model="entityType" help="The type of entity to display data views for." />
120145</div>
121146 `
122- } ) ;
147+ } ) ;
0 commit comments