Skip to content

Commit a4f2db5

Browse files
committed
GitHub Issue 787: DomainField JSON file import should respect required boolean for SampleId field
1 parent 617e313 commit a4f2db5

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

packages/components/releaseNotes/components.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# @labkey/components
22
Components, models, actions, and utility functions for LabKey applications and pages
33

4+
### version TBD
5+
*Released*: TBD
6+
- GitHub Issue 787: DomainField JSON file import should respect required boolean for SampleId field
7+
48
### version 6.52.0
59
*Released*: 24 June 2025
610
- Improve ExecuteSql endpoint wrapper. See #1813.

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,38 @@ import {
5555
DomainDesign,
5656
DomainField,
5757
DomainIndex,
58-
IDomainIndex,
5958
FieldErrors,
6059
getValidValuesDetailStr,
6160
getValidValuesFromArray,
6261
IDomainField,
62+
IDomainIndex,
6363
isPropertyTypeAllowed,
6464
isValidTextChoiceValue,
6565
PropertyValidator,
6666
PropertyValidatorProperties,
6767
} from './models';
6868
import {
6969
BOOLEAN_RANGE_URI,
70+
CALCULATED_CONCEPT_URI,
7071
CONCEPT_CODE_CONCEPT_URI,
72+
DATE_RANGE_URI,
73+
DATETIME_RANGE_URI,
74+
DERIVATION_DATA_SCOPES,
7175
DOMAIN_FIELD_FULLY_LOCKED,
7276
DOMAIN_FIELD_NOT_LOCKED,
7377
DOMAIN_FIELD_PARTIALLY_LOCKED,
78+
DOMAIN_FIELD_PRIMARY_KEY_LOCKED,
7479
INT_RANGE_URI,
7580
MULTILINE_RANGE_URI,
76-
PHILEVEL_NOT_PHI,
7781
PHILEVEL_FULL_PHI,
7882
PHILEVEL_LIMITED_PHI,
83+
PHILEVEL_NOT_PHI,
7984
PHILEVEL_RESTRICTED_PHI,
8085
SAMPLE_TYPE_CONCEPT_URI,
8186
STORAGE_UNIQUE_ID_CONCEPT_URI,
8287
STRING_RANGE_URI,
8388
TEXT_CHOICE_CONCEPT_URI,
84-
DERIVATION_DATA_SCOPES,
85-
DOMAIN_FIELD_PRIMARY_KEY_LOCKED,
86-
DATETIME_RANGE_URI,
87-
DATE_RANGE_URI,
8889
TIME_RANGE_URI,
89-
CALCULATED_CONCEPT_URI,
9090
} from './constants';
9191

9292
beforeAll(() => {
@@ -1419,3 +1419,54 @@ describe('isValidTextChoiceValue', () => {
14191419
expect(isValidTextChoiceValue(' a ')).toBeTruthy();
14201420
});
14211421
});
1422+
1423+
describe('resolveBaseProperties', () => {
1424+
test('infer SampleId', () => {
1425+
let field = DomainField.resolveBaseProperties({ name: 'OtherId' });
1426+
expect(field.dataType).toBe(TEXT_TYPE);
1427+
expect(field.conceptURI).toBe(undefined);
1428+
expect(field.rangeURI).toBe(undefined);
1429+
expect(field.required).toBe(undefined);
1430+
1431+
field = DomainField.resolveBaseProperties({
1432+
propertyId: 1,
1433+
name: 'SampleId',
1434+
});
1435+
expect(field.dataType).toBe(LOOKUP_TYPE);
1436+
expect(field.conceptURI).toBe(undefined);
1437+
expect(field.rangeURI).toBe(undefined);
1438+
expect(field.required).toBe(undefined);
1439+
1440+
field = DomainField.resolveBaseProperties({ name: 'SampleId' });
1441+
expect(field.dataType).toBe(SAMPLE_TYPE);
1442+
expect(field.conceptURI).toBe(SAMPLE_TYPE.conceptURI);
1443+
expect(field.rangeURI).toBe(SAMPLE_TYPE.rangeURI);
1444+
expect(field.required).toBe(true);
1445+
1446+
// GitHub Issue 787
1447+
field = DomainField.resolveBaseProperties({ name: 'SampleId', required: false });
1448+
expect(field.dataType).toBe(SAMPLE_TYPE);
1449+
expect(field.conceptURI).toBe(SAMPLE_TYPE.conceptURI);
1450+
expect(field.rangeURI).toBe(SAMPLE_TYPE.rangeURI);
1451+
expect(field.required).toBe(undefined);
1452+
});
1453+
1454+
test('lockType', () => {
1455+
expect(DomainField.resolveBaseProperties({}).lockType).toBe(DOMAIN_FIELD_NOT_LOCKED);
1456+
expect(DomainField.resolveBaseProperties({ lockType: DOMAIN_FIELD_PARTIALLY_LOCKED }).lockType).toBe(
1457+
DOMAIN_FIELD_PARTIALLY_LOCKED
1458+
);
1459+
expect(DomainField.resolveBaseProperties({ lockType: DOMAIN_FIELD_FULLY_LOCKED }).lockType).toBe(
1460+
DOMAIN_FIELD_FULLY_LOCKED
1461+
);
1462+
expect(DomainField.resolveBaseProperties({ name: 'test1' }, List(['test2'])).lockType).toBe(
1463+
DOMAIN_FIELD_NOT_LOCKED
1464+
);
1465+
expect(DomainField.resolveBaseProperties({ name: 'test1' }, List(['test1'])).lockType).toBe(
1466+
DOMAIN_FIELD_PARTIALLY_LOCKED
1467+
);
1468+
expect(DomainField.resolveBaseProperties({ name: 'TEST1' }, List(['test1'])).lockType).toBe(
1469+
DOMAIN_FIELD_PARTIALLY_LOCKED
1470+
);
1471+
});
1472+
});

packages/components/src/internal/components/domainproperties/models.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,10 @@ export class DomainField
11791179
field.dataType = SAMPLE_TYPE;
11801180
field.conceptURI = SAMPLE_TYPE.conceptURI;
11811181
field.rangeURI = SAMPLE_TYPE.rangeURI;
1182-
field.required = true;
1182+
// GitHub Issue 787
1183+
if (raw.required === undefined) {
1184+
field.required = true;
1185+
}
11831186
}
11841187
}
11851188

0 commit comments

Comments
 (0)