feat(MED-168): clean up types

This commit is contained in:
2025-09-19 15:14:03 +03:00
parent 47bbeeb155
commit afdaebc804
4 changed files with 127 additions and 144 deletions

View File

@@ -4,12 +4,7 @@ import { ArrowDown } from 'lucide-react';
import { cn } from '@kit/ui/utils';
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
export enum AnalysisResultLevel {
NORMAL = 0,
WARNING = 1,
CRITICAL = 2,
}
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
type AnalysisResultLevelBarResults = Pick<AnalysisResultDetailsElementResults, 'normLower' | 'normUpper' | 'responseValue'>;
@@ -148,34 +143,10 @@ const AnalysisLevelBar = ({
const isValueInNormalRange = !isValueBelowLower && !isValueAboveUpper;
const [first, second, third] = useMemo(() => {
if (!hasLowerBound) {
return [
{
isActive: isNormal,
color: "success",
isFirst: true,
normRangeText,
...(isNormal ? { arrowLocation } : {}),
},
{
isActive: isWarning,
color: "warning",
...(isWarning ? { arrowLocation } : {}),
},
{
isActive: isCritical,
color: "destructive",
isLast: true,
...(isCritical ? { arrowLocation } : {}),
},
] as const;
}
return [
const [warning, normal, critical] = [
{
isActive: isWarning,
color: "warning",
isFirst: true,
...(isWarning ? { arrowLocation } : {}),
},
{
@@ -191,6 +162,20 @@ const AnalysisLevelBar = ({
...(isCritical ? { arrowLocation } : {}),
},
] as const;
if (!hasLowerBound) {
return [
{ ...normal, isFirst: true },
warning,
critical,
] as const;
}
return [
{ ...warning, isFirst: true },
normal,
{ ...critical, isLast: true },
] as const;
}, [isValueBelowLower, isValueAboveUpper, isValueInNormalRange, arrowLocation, normRangeText, isNormal, isWarning, isCritical]);
return (

View File

@@ -2,27 +2,18 @@
import React, { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type {
AnalysisResultDetailsElementResults,
AnalysisResultDetailsElement,
AnalysisResultsDetailsElementNested,
} from '@/packages/features/user-analyses/src/types/analysis-results';
import { format } from 'date-fns';
import { Info } from 'lucide-react';
import type {
AnalysisResultDetailsElement,
AnalysisResultsDetailsElementNested,
} from '@/packages/features/user-analyses/src/types/analysis-results';
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
import AnalysisLevelBar, {
AnalysisResultLevel,
} from './analysis-level-bar';
export enum AnalysisStatus {
NORMAL = 0,
MEDIUM = 1,
HIGH = 2,
}
import AnalysisLevelBar from './analysis-level-bar';
const Analysis = ({
element: elementOriginal,
@@ -41,7 +32,7 @@ const Analysis = ({
}
return elementOriginal!;
})();
const results: AnalysisResultDetailsElementResults = useMemo(() => {
const results: AnalysisResultDetailsElement['results'] = useMemo(() => {
if (isNestedElement) {
const nestedElement = element as AnalysisResultsDetailsElementNested;
return {
@@ -115,7 +106,8 @@ const Analysis = ({
}, [normStatus]);
const isCancelled = Number(results?.status) === 5;
const hasNestedElements = results?.nestedElements.length > 0;
const nestedElements = results?.nestedElements ?? null;
const hasNestedElements = Array.isArray(nestedElements) && nestedElements.length > 0;
const normRangeText = (() => {
if (normLower === null && normUpper === null) {