Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labkey/components",
"version": "7.5.1",
"version": "7.5.2-fb-error-754.0",
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
"sideEffects": false,
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,8 @@ describe('getGroupedSampleDomainFields', () => {

test('field split by derivationDataScope', () => {
const result = _getGroupedSampleDomainFields(sampleTypeDomain, queryInfo);
expect(result.aliquotFields.length).toBe(1);
expect(result.aliquotFields[0]).toBe('aliq$c$d$s');
expect(result.independentFields.length).toBe(1);
expect(result.independentFields[0]).toBe('all$c$d$s');
expect(result.metaFields.length).toBe(3);
expect(result.metaFields[0]).toBe('name');
expect(result.metaFields[1]).toBe('spec char$c$d$s');
expect(result.metaFields[2]).toBe('parent$c$d$s');
expect(result.aliquotFields).toEqual(['aliq$c$d$s']);
expect(result.independentFields).toEqual(['all$c$d$s']);
expect(result.metaFields).toEqual(['name', 'spec char$c$d$s', 'parent$c$d$s']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export function _getGroupedSampleDomainFields(
sampleTypeDomain: DomainDetails,
queryInfo: QueryInfo
): GroupedSampleFields {
const metaFields = [];
const independentFields = [];
const aliquotFields = [];
const aliquotFields: string[] = [];
const independentFields: string[] = [];
const metaFields: string[] = [];

sampleTypeDomain.domainDesign.fields.forEach(field => {
const col = queryInfo.getColumnFromName(field.name);
Expand Down
48 changes: 14 additions & 34 deletions packages/components/src/internal/util/measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ export const MEASUREMENT_UNITS: Record<string, MeasurementUnit> = {
},
};

export function getMeasurementUnit(unitStr: string): MeasurementUnit {
export function getMeasurementUnit(unitStr: string): MeasurementUnit | null {
if (!unitStr) return null;
const unitStrLc = unitStr.toLowerCase();

const unit = MEASUREMENT_UNITS[unitStr?.toLowerCase()];
const unit = MEASUREMENT_UNITS[unitStrLc];
if (unit) return unit;

const unitStrLc = unitStr.toLowerCase();
if (MEASUREMENT_UNITS.unit.altLabels.indexOf(unitStrLc) > -1) {
if (MEASUREMENT_UNITS.unit.altLabels?.indexOf(unitStrLc) > -1) {
return {
...MEASUREMENT_UNITS.unit,
label: unitStrLc,
Expand All @@ -204,11 +204,7 @@ export function getMeasurementUnit(unitStr: string): MeasurementUnit {
return null;
}

/**
* @param unitAStr
* @param unitBStr
*/
export function areUnitsCompatible(unitAStr: string, unitBStr: string) {
export function areUnitsCompatible(unitAStr: string, unitBStr: string): boolean {
if (unitAStr == unitBStr) {
return true;
}
Expand All @@ -221,19 +217,19 @@ export function areUnitsCompatible(unitAStr: string, unitBStr: string) {
if (!unitAStr && unitBStr) {
return false;
}
const unitA: MeasurementUnit = getMeasurementUnit(unitAStr);
const unitB: MeasurementUnit = getMeasurementUnit(unitBStr);
const unitA = getMeasurementUnit(unitAStr);
const unitB = getMeasurementUnit(unitBStr);
if (!unitA || !unitB) {
return false;
}
return unitA.kind === unitB.kind;
}

export function getMetricUnitOptions(metricUnit?: string, showLongLabel?: boolean): { label: string; value: string }[] {
const unit: MeasurementUnit = getMeasurementUnit(metricUnit);
const unit = getMeasurementUnit(metricUnit);

const options = [];
for (const [key, value] of Object.entries(MEASUREMENT_UNITS)) {
for (const value of Object.values(MEASUREMENT_UNITS)) {
if (!unit || value.kind === unit.kind) {
if (value.kind === UNITS_KIND.COUNT) {
if (showLongLabel)
Expand Down Expand Up @@ -274,36 +270,20 @@ export function getMetricUnitOptionsFromKind(
return getMetricUnitOptions(metricUnit, showLongLabel);
}

export function getAltUnitKeys(unitTypeStr): string[] {
const unit: MeasurementUnit = getMeasurementUnit(unitTypeStr);
export function getAltUnitKeys(unitTypeStr: string): string[] {
const unit = getMeasurementUnit(unitTypeStr);
const options = [];
Object.values(MEASUREMENT_UNITS).forEach(value => {
for (const value of Object.values(MEASUREMENT_UNITS)) {
if (!unit || value.kind === unit.kind) {
if (value.altLabels) {
options.push(...value.altLabels);
} else options.push(value.label);
}
});

return options;
}

export function getVolumeMinStep(sampleTypeUnit?: MeasurementUnit | string) {
const step = 0.01;
if (!sampleTypeUnit) {
return step;
}

const unit = typeof sampleTypeUnit === 'string' ? getMeasurementUnit(sampleTypeUnit) : sampleTypeUnit;

// If we don't know the units, or it is 'unit' then use the default
if (!unit || unit.baseUnit === MEASUREMENT_UNITS.unit.baseUnit) {
return step;
}

return Math.pow(10, -unit.displayPrecision); // Track uL and mg to a single unit
return options;
}

export function isMeasurementUnitIgnoreCase(expected: MeasurementUnit, val: string) {
export function isMeasurementUnitIgnoreCase(expected: MeasurementUnit, val: string): boolean {
return expected.label.localeCompare(val, 'en-US', { sensitivity: 'base' }) === 0;
}