Skip to content

Commit

Permalink
ADM-763: [frontend] refactor: refactor component (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangRu1 authored Jan 31, 2024
1 parent 7641b92 commit da8b7e9
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions frontend/src/components/Common/ReportForThreeColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,40 @@ export const ReportForThreeColumns = ({
: '';
};

const shouldShowLoading = !errorMessage && !data;
const shouldShowData = !errorMessage && data;
const renderLoading = () => (
<>
{!errorMessage && !data && (
<StyledLoadingWrapper>
<Loading size='1.5rem' backgroundColor='transparent' />
</StyledLoadingWrapper>
)}
</>
);

const renderData = () => (
<>
{!errorMessage && data && (
<Table data-test-id={title} data-testid={title}>
<TableHead>
<TableRow>
<StyledTableCell>{fieldName}</StyledTableCell>
<StyledTableCell>{listName}</StyledTableCell>
<StyledTableCell>{`Value${getTitleUnit(title)}`}</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>{renderRows()}</TableBody>
</Table>
)}
</>
);

return (
<>
<Container>
<ReportSelectionTitle>{title}</ReportSelectionTitle>
{errorMessage && <ErrorMessagePrompt errorMessage={errorMessage} style={{ marginBottom: '1.5rem' }} />}
{shouldShowLoading && (
<StyledLoadingWrapper>
<Loading size='1.5rem' backgroundColor='transparent' />
</StyledLoadingWrapper>
)}
{shouldShowData && (
<Table data-test-id={title} data-testid={title}>
<TableHead>
<TableRow>
<StyledTableCell>{fieldName}</StyledTableCell>
<StyledTableCell>{listName}</StyledTableCell>
<StyledTableCell>{`Value${getTitleUnit(title)}`}</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>{renderRows()}</TableBody>
</Table>
)}
{renderLoading()}
{renderData()}
</Container>
</>
);
Expand Down

0 comments on commit da8b7e9

Please sign in to comment.