Skip to content

Commit

Permalink
working refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
arodidev committed Jan 7, 2024
1 parent 8e2fd5f commit 3d7bf66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface CommonOverviewPropsBase {
overviewData: Array<OverviewPanelEntry>;
insertSeparator?: boolean;
patientUuid?: string;
seeAllResults?: boolean;
}

interface CommonOverviewPropsWithToolbar {
Expand Down Expand Up @@ -43,6 +44,7 @@ const CommonOverview: React.FC<CommonOverviewProps> = ({
insertSeparator = false,
hideToolbar = false,
patientUuid,
seeAllResults,
}) => {
const { t } = useTranslation();
const [activeCardUuid, setActiveCardUuid] = React.useState('');
Expand All @@ -68,10 +70,12 @@ const CommonOverview: React.FC<CommonOverviewProps> = ({
<EmptyState headerTitle={t('testResults_title', 'Test Results')} displayText={t('testResults', 'test results')} />
);

const filteredOverviewData = seeAllResults ? overviewData : overviewData.slice(0, 3);

return (
<>
{(() => {
const cards = overviewData.map(([title, type, data, effectiveDateTime, issuedDateTime, uuid]) => (
const cards = filteredOverviewData.map(([title, type, data, effectiveDateTime, issuedDateTime, uuid]) => (
<article
key={uuid}
className={insertSeparator ? '' : `${styles.card} ${isActiveCard(uuid) ? styles.activeCard : ''}`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Button, DataTableSkeleton } from '@carbon/react';
Expand Down Expand Up @@ -45,6 +45,8 @@ function useFilteredOverviewData(patientUuid: string, filter: (filterProps: Pane
}

const ExternalOverview: React.FC<ExternalOverviewProps> = ({ patientUuid, filter }) => {
const [seeAllResults, setSeeAllResults] = useState<boolean>(false);

const { t } = useTranslation();
const { overviewData, loaded, error } = useFilteredOverviewData(patientUuid, filter);

Expand All @@ -67,23 +69,24 @@ const ExternalOverview: React.FC<ExternalOverviewProps> = ({ patientUuid, filter
kind="ghost"
renderIcon={(props) => <ArrowRight size={16} {...props} />}
iconDescription="See all results"
onClick={handleSeeAll}
onClick={() => setSeeAllResults(true)}
>
{t('seeAllResults', 'See all results')}
</Button>
</div>
<CommonOverview
{...{
patientUuid,
overviewData: overviewData.slice(0, resultsToShow),
overviewData: overviewData,
insertSeparator: true,
deactivateToolbar: true,
isPatientSummaryDashboard: false,
hideToolbar: true,
seeAllResults: seeAllResults,
}}
/>
{overviewData.length > resultsToShow && (
<Button onClick={handleSeeAll} kind="ghost">
{overviewData.length > resultsToShow && !seeAllResults && (
<Button onClick={() => setSeeAllResults(true)} kind="ghost">
{t('moreResultsAvailable', 'More results available')}
</Button>
)}
Expand Down

0 comments on commit 3d7bf66

Please sign in to comment.