Skip to content

Commit 84d0be4

Browse files
committed
bug fixes
1 parent acf9931 commit 84d0be4

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

packages/components/src/internal/components/domainproperties/actions.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
FILE_TYPE,
6262
FLAG_TYPE,
6363
INTEGER_TYPE,
64+
MULTI_CHOICE_TYPE,
6465
ONTOLOGY_LOOKUP_TYPE,
6566
PARTICIPANT_TYPE,
6667
SAMPLE_TYPE,
@@ -371,6 +372,7 @@ describe('domain properties actions', () => {
371372
allowTextChoiceProperties: true,
372373
allowSampleSubjectProperties: true,
373374
allowCalculatedFields: true,
375+
allowMultiChoiceProperties: true
374376
});
375377
const available = getAvailableTypes(domain);
376378
expect(available.contains(FLAG_TYPE)).toBeTruthy();
@@ -386,6 +388,7 @@ describe('domain properties actions', () => {
386388
expect(available.contains(SAMPLE_TYPE)).toBeTruthy();
387389
expect(available.contains(PARTICIPANT_TYPE)).toBeTruthy();
388390
expect(available.contains(CALCULATED_TYPE)).toBeFalsy();
391+
expect(available.contains(MULTI_CHOICE_TYPE)).toBeTruthy();
389392
});
390393

391394
test('getAvailableTypes, no optional allowed', () => {
@@ -399,6 +402,7 @@ describe('domain properties actions', () => {
399402
allowTextChoiceProperties: false,
400403
allowSampleSubjectProperties: false,
401404
allowCalculatedFields: false,
405+
allowMultiChoiceProperties: false,
402406
});
403407
const available = getAvailableTypes(domain);
404408
expect(available.contains(FLAG_TYPE)).toBeFalsy();
@@ -414,6 +418,7 @@ describe('domain properties actions', () => {
414418
expect(available.contains(SAMPLE_TYPE)).toBeFalsy();
415419
expect(available.contains(PARTICIPANT_TYPE)).toBeFalsy();
416420
expect(available.contains(CALCULATED_TYPE)).toBeFalsy();
421+
expect(available.contains(MULTI_CHOICE_TYPE)).toBeFalsy();
417422
});
418423

419424
test('getAvailableTypes calculated fields, LKSM Starter', () => {

packages/components/src/internal/components/domainproperties/actions.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,8 @@ export function updateDataType(field: DomainField, value: any): DomainField {
859859

860860
if (propType) {
861861
const dataType = propType.isLookup() ? field.lookupType : propType;
862-
862+
const wasTextChoice = field.isTextChoiceField() || field.isMultiChoiceField();
863+
const isTextChoice = propType.isTextChoice() || propType.isMultiChoice();
863864
field = field.merge({
864865
dataType,
865866
conceptURI: dataType.conceptURI,
@@ -872,8 +873,8 @@ export function updateDataType(field: DomainField, value: any): DomainField {
872873
conceptLabelColumn: undefined,
873874
conceptImportColumn: undefined,
874875
scannable: undefined,
875-
textChoiceValidator: undefined,
876-
valueExpression: undefined,
876+
textChoiceValidator: isTextChoice ? field.textChoiceValidator: undefined,
877+
valueExpression: isTextChoice ? field.valueExpression: undefined,
877878
}) as DomainField;
878879

879880
if (field.isNew()) {
@@ -886,13 +887,16 @@ export function updateDataType(field: DomainField, value: any): DomainField {
886887
if (field.isTextChoiceField() || field.isMultiChoiceField()) {
887888
// when changing a field to a Text Choice, add the default textChoiceValidator and
888889
// remove/reset all other propertyValidators and other text option settings
889-
field = field.merge({
890-
textChoiceValidator: DEFAULT_TEXT_CHOICE_VALIDATOR,
891-
lookupValidator: undefined,
892-
rangeValidators: [],
893-
regexValidators: [],
894-
scale: MAX_TEXT_LENGTH,
895-
}) as DomainField;
890+
if (!wasTextChoice) {
891+
field = field.merge({
892+
textChoiceValidator: DEFAULT_TEXT_CHOICE_VALIDATOR,
893+
lookupValidator: undefined,
894+
rangeValidators: [],
895+
regexValidators: [],
896+
scale: MAX_TEXT_LENGTH,
897+
valueExpression: undefined,
898+
}) as DomainField;
899+
}
896900
} else if (field.isCalculatedField()) {
897901
field = field.merge({
898902
importAliases: undefined,

0 commit comments

Comments
 (0)