Skip to content

Commit 9b388d5

Browse files
committed
add a fix for multi-cardinality stacked notes
1 parent 988e8dd commit 9b388d5

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

ui/src/app/modules/builder/services/node-database.service.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { Injectable } from '@angular/core';
22
import { cloneDeep, isEqual } from 'lodash-es';
33
import { filter, map, Observable, ReplaySubject } from 'rxjs';
4-
import {
5-
JsonAttributeNode,
6-
JsonNode,
7-
JsonRootNode,
8-
RosettaBasicType,
9-
} from '../models/builder.model';
4+
import { JsonAttributeNode, JsonNode, JsonRootNode, RosettaBasicType, } from '../models/builder.model';
105
import { isAttributeExhausted, isListBasedBasicType } from '../utils/node.util';
11-
import { isJsonRootNode, isStringArray } from '../utils/type-guards.util';
6+
import { isEnumType, isJsonRootNode, isNumberArray, isStringArray, } from '../utils/type-guards.util';
127
import { IdentityService } from './identity.service';
138

149
export interface NodeDataChangeEvent {
@@ -224,20 +219,36 @@ export class NodeDatabaseService {
224219
throw new Error('Attempt to add undefined value to sibling');
225220
}
226221

227-
switch (newJsonAttribute.definition.type) {
228-
case RosettaBasicType.STRING:
229-
const newValue = (newJsonAttribute.value || '') as string;
230-
if (isStringArray(matchingSiblingAttributeNode.value)) {
231-
matchingSiblingAttributeNode.value.push(newValue);
232-
} else if (typeof matchingSiblingAttributeNode.value === 'string') {
233-
const newValues = [newValue, matchingSiblingAttributeNode.value];
234-
matchingSiblingAttributeNode.value = newValues;
235-
}
236-
break;
237-
default:
238-
throw new Error(
239-
`Adding value ${newJsonAttribute.value} to matchingSiblingAttributeNode.value ${matchingSiblingAttributeNode.value} is not supported`
240-
);
222+
if (isEnumType(newJsonAttribute.definition.type)) {
223+
const newValue = (newJsonAttribute.value || '') as string;
224+
if (isStringArray(matchingSiblingAttributeNode.value)) {
225+
matchingSiblingAttributeNode.value.push(newValue)
226+
} else {
227+
matchingSiblingAttributeNode.value = [newValue, matchingSiblingAttributeNode.value as string];
228+
}
229+
} else {
230+
switch (newJsonAttribute.definition.type) {
231+
case RosettaBasicType.STRING:
232+
const newStringValue = (newJsonAttribute.value || '') as string;
233+
if (isStringArray(matchingSiblingAttributeNode.value)) {
234+
matchingSiblingAttributeNode.value.push(newStringValue);
235+
} else {
236+
matchingSiblingAttributeNode.value = [newStringValue, matchingSiblingAttributeNode.value as string];
237+
}
238+
break;
239+
case RosettaBasicType.NUMBER:
240+
const newNumberValue = (newJsonAttribute.value || 0) as number;
241+
if (isNumberArray(matchingSiblingAttributeNode.value)) {
242+
matchingSiblingAttributeNode.value.push(newNumberValue);
243+
} else {
244+
matchingSiblingAttributeNode.value = [newNumberValue, matchingSiblingAttributeNode.value as number];
245+
}
246+
break;
247+
default:
248+
throw new Error(
249+
`Adding value ${newJsonAttribute.value} to matchingSiblingAttributeNode.value ${matchingSiblingAttributeNode.value} is not supported`
250+
);
251+
}
241252
}
242253
}
243254

ui/src/app/modules/builder/utils/type-guards.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function isStringArray(value: JsonValue | undefined): value is string[] {
5252
throw new Error('Can not determine type of empty array');
5353
}
5454

55-
return typeof value[0] === 'string';
55+
return typeof value[0] === 'string' || value[0] === undefined;
5656
}
5757

5858
export function isNumberArray(value: JsonValue | undefined): value is number[] {

0 commit comments

Comments
 (0)