From c9faf5b127b4a74bb6bef0e9c1714fda973d7f26 Mon Sep 17 00:00:00 2001 From: labkey-nicka Date: Wed, 24 Dec 2025 12:11:58 -0800 Subject: [PATCH 1/2] #754: display and log errors --- .../components/samples/actions.test.ts | 11 ++--- .../internal/components/samples/actions.ts | 6 +-- .../src/internal/util/measurement.ts | 48 ++++++------------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/packages/components/src/internal/components/samples/actions.test.ts b/packages/components/src/internal/components/samples/actions.test.ts index 229bc1b0e7..b962215a28 100644 --- a/packages/components/src/internal/components/samples/actions.test.ts +++ b/packages/components/src/internal/components/samples/actions.test.ts @@ -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']); }); }); diff --git a/packages/components/src/internal/components/samples/actions.ts b/packages/components/src/internal/components/samples/actions.ts index 2d12c4eb63..836a2cc7fb 100644 --- a/packages/components/src/internal/components/samples/actions.ts +++ b/packages/components/src/internal/components/samples/actions.ts @@ -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); diff --git a/packages/components/src/internal/util/measurement.ts b/packages/components/src/internal/util/measurement.ts index 994103be1a..1807189cd2 100644 --- a/packages/components/src/internal/util/measurement.ts +++ b/packages/components/src/internal/util/measurement.ts @@ -185,14 +185,14 @@ export const MEASUREMENT_UNITS: Record = { }, }; -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, @@ -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; } @@ -221,8 +217,8 @@ 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; } @@ -230,10 +226,10 @@ export function areUnitsCompatible(unitAStr: string, unitBStr: string) { } 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) @@ -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; } From 1a0ac537e7ce28e28eba6cb55e880fa3ac0f91e1 Mon Sep 17 00:00:00 2001 From: labkey-nicka Date: Wed, 24 Dec 2025 12:12:39 -0800 Subject: [PATCH 2/2] 7.5.2-fb-error-754.0 --- packages/components/package-lock.json | 4 ++-- packages/components/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/components/package-lock.json b/packages/components/package-lock.json index 26bd5b2471..7a4273f9c5 100644 --- a/packages/components/package-lock.json +++ b/packages/components/package-lock.json @@ -1,12 +1,12 @@ { "name": "@labkey/components", - "version": "7.5.1", + "version": "7.5.2-fb-error-754.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@labkey/components", - "version": "7.5.1", + "version": "7.5.2-fb-error-754.0", "license": "SEE LICENSE IN LICENSE.txt", "dependencies": { "@hello-pangea/dnd": "18.0.1", diff --git a/packages/components/package.json b/packages/components/package.json index 292f9e7eba..e0adcdadd0 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -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": [