Skip to content

Commit

Permalink
(refactor) O3-3655 Change the behaviour of the results view switchers
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Sep 10, 2024
1 parent 05dc488 commit 4e8e6c3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/esm-patient-labs-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"slot": "patient-chart-dashboard-slot",
"meta": {
"slot": "patient-chart-test-results-dashboard-slot",
"path": "Results Viewer",
"path": "Results",
"hideDashboardTitle": true
},
"order": 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const dashboardMeta = {
slot: 'patient-chart-test-results-dashboard-slot',
columns: 1,
path: 'Results Viewer',
title: 'Results Viewer',
path: 'Results',
title: 'Results',
hideDashboardTitle: true,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext, useState } from 'react';
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
import classNames from 'classnames';
import { type TFunction, useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
Expand Down Expand Up @@ -65,6 +65,54 @@ const ResultsViewer: React.FC<ResultsViewerProps> = ({ patientUuid, basePath, lo
const isExpanded = view === 'full';
const trendlineView = testUuid && type === 'trendline';
const responsiveSize = isTablet ? 'lg' : 'md';
const headerRef = useRef(null);

useEffect(() => {
const headerElement = headerRef.current;

if (!headerElement) {
const fallbackElement = document.querySelector(`.${styles.resultsHeader}`);
if (fallbackElement) {
const observer = new IntersectionObserver(
([entry]) => {
if (!entry.isIntersecting) {
(fallbackElement as HTMLElement).style.borderBottom = '0px';
} else {
(fallbackElement as HTMLElement).style.borderBottom = '1px solid #e0e0e0';
}
},
{
rootMargin: '0px 0px -80% 0px',
threshold: [1],
},
);
observer.observe(fallbackElement);
}
return;
}

const observer = new IntersectionObserver(
([entry]) => {
if (!entry.isIntersecting) {
headerElement.style.borderBottom = '1px solid #e0e0e0';
} else {
headerElement.style.borderBottom = '0px';
}
},
{
rootMargin: '0px 0px -80% 0px',
threshold: [1],
},
);

observer.observe(headerElement);

return () => {
if (headerElement) {
observer.unobserve(headerElement);
}
};
}, []);

const navigateBackFromTrendlineView = useCallback(() => {
navigate({
Expand All @@ -75,7 +123,7 @@ const ResultsViewer: React.FC<ResultsViewerProps> = ({ patientUuid, basePath, lo
if (isTablet) {
return (
<div className={styles.resultsContainer}>
<div className={styles.resultsHeader}>
<div ref={headerRef} className={styles.resultsHeader}>
<h4 style={{ flexGrow: 1 }}>{`${t('results', 'Results')} ${
totalResultsCount ? `(${totalResultsCount})` : ''
}`}</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
grid-template-columns: 1fr 1fr;
width: max-content;
justify-content: flex-start;
height: 32px;
}

.trendlineOverlayHeader {
Expand Down

0 comments on commit 4e8e6c3

Please sign in to comment.