Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.card :global(.ant-card-head) {
border: 0px;
}

.cardContent {
display: flex;
flex-direction: column;
}

.title {
font-size: 1.5rem;
font-weight: 600;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason we want to extract this component from the StatCard component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have cards with a graph instead of a statistic. I thought having an empty card component was better, and then anything we want for content added as children

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, right

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Card,
Typography,
} from "antd";

import styles from "./index.module.css";


const {Text} = Typography;

interface DashboardCardProps {
title: string;
titleColor?: string;
backgroundColor?: string;
children?: React.ReactNode;
}

/**
* Renders a card for dashboard.
*
* @param props
* @param props.title
* @param props.titleColor
* @param props.backgroundColor
* @param props.children
* @return
*/
const DashboardCard = ({title, titleColor, backgroundColor, children}: DashboardCardProps) => {
return (
<Card
className={styles["card"] || ""}
hoverable={true}
Comment on lines +31 to +32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve fallback pattern for CSS class names

The current fallback pattern using logical OR (||) may not work as expected with CSS modules. When styles["card"] is an empty string (but defined), it will still be used instead of falling back to the empty string.

- className={styles["card"] || ""}
+ className={styles.card ?? ""}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
className={styles["card"] || ""}
hoverable={true}
className={styles.card ?? ""}
hoverable={true}

style={{backgroundColor}}
>
<div className={styles["cardContent"]}>
<Text
className={styles["title"] || ""}
style={{color: titleColor}}
Comment on lines +37 to +38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve fallback pattern for CSS class names

Same issue as with the card class - the logical OR fallback may not work as expected with CSS modules.

- className={styles["title"] || ""}
+ className={styles.title ?? ""}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
className={styles["title"] || ""}
style={{color: titleColor}}
className={styles.title ?? ""}
style={{ color: titleColor }}

>
{title}
</Text>
{children}
</div>
</Card>
);
};

export {DashboardCard};

export type {DashboardCardProps};
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
.card :global(.ant-card-head) {
border: 0px;
}

.cardContent {
display: flex;
flex-direction: column;
}

.title {
font-size: 1.5rem;
font-weight: 600;
}

.statistic {
font-size: 5rem;
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
import {
Card,
Typography,
} from "antd";
import {Typography} from "antd";

import styles from "./index.module.css";
import {
DashboardCard,
DashboardCardProps,
} from "../DashboardCard/index";


const {Text} = Typography;

interface StatCardProps {
title: string;
stat: string;
textColor?: string;
titleColor?: string;
backgroundColor?: string;
statSize?: string;
statColor?: string;
}

/**
* Renders a card that dislays a statistic.
* Renders a card with a statistic.
*
* @param props
* @param props.title
* @param props.stat
* @param props.textColor
* @param props.titleColor
* @param props.backgroundColor
* @param props.statSize
* @param props.statColor
* @return
*/
const StatCard = ({title, stat, textColor, backgroundColor}: StatCardProps) => {
const StatCard = ({
title,
stat,
titleColor,
backgroundColor,
statSize,
statColor,
}: StatCardProps) => {
const props: DashboardCardProps = {
title,
...(titleColor ?
{titleColor} :
{}),
...(backgroundColor ?
{backgroundColor} :
{}),
};

return (
<Card
className={styles["card"] || ""}
hoverable={true}
style={{backgroundColor}}
>
<div className={styles["cardContent"]}>
<Text
className={styles["title"] || ""}
style={{color: textColor}}
>
{title}
</Text>
<Text
className={styles["statistic"] || ""}
style={{color: textColor}}
>
{stat}
</Text>
</div>
</Card>
<DashboardCard {...props}>
<Text style={{color: statColor, fontSize: statSize}}>
{stat}
</Text>
</DashboardCard>
);
};

export default StatCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {theme} from "antd";

import StatCard from "../../../components/StatCard";


interface DetailsCardProps {
title: string;
stat: string;
}

/**
* A stat card in the details grid.
*
* @param props
* @param props.title
* @param props.stat
* @return
*/
const DetailsCard = ({title, stat}: DetailsCardProps) => {
const {token} = theme.useToken();
return (
<StatCard
stat={stat}
statColor={token.colorTextSecondary}
statSize={"1.3rem"}
title={title}/>
);
};

export default DetailsCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import DetailsCard from "./DetailsCard";


// eslint-disable-next-line no-warning-comments
// TODO: Replace with values from database once api implemented.
const DUMMY_FILES = 124;

/**
* Renders the files statistic.
*
* @return
*/
const Files = () => {
return (
<DetailsCard
stat={DUMMY_FILES.toString()}
title={"Files"}/>
);
};

export default Files;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import DetailsCard from "./DetailsCard";


// eslint-disable-next-line no-warning-comments
// TODO: Replace with values from database once api implemented.
const DUMMY_MESSAGES = 1235844;

/**
* Renders the messages statistic.
*
* @return
*/
const Messages = () => {
return (
<DetailsCard
stat={DUMMY_MESSAGES.toString()}
title={"Messages"}/>
);
};

export default Messages;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import dayjs from "dayjs";

import DetailsCard from "./DetailsCard";


// eslint-disable-next-line no-warning-comments
// TODO: Replace with values from database once api implemented.
const DUMMY_START_DATE = "2021-12-14";
const DUMMY_END_DATE = "2025-04-16";

const DATE_FORMAT = "MMMM D, YYYY";

/**
* Renders the time range statistic.
*
* @return
*/
const TimeRange = () => {
const formattedStat = `${dayjs(DUMMY_START_DATE).format(DATE_FORMAT)} -
${dayjs(DUMMY_END_DATE).format(DATE_FORMAT)}`;

return (
<DetailsCard
stat={formattedStat}
title={"Time Range"}/>
);
};

export default TimeRange;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.detailsGrid {
display: grid;
grid-template-columns: repeat(2, 200px);
gap: 8px;
}

.timeRange {
grid-column: span 2;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Files from "./Files";
import styles from "./index.module.css";
import Messages from "./Messages";
import TimeRange from "./TimeRange";


/**
* Renders grid with compression details.
*
* @return
*/
const Details = () => {
return (
<div className={styles["detailsGrid"]}>
<div className={styles["timeRange"]}>
<TimeRange/>
</div>
<Messages/>
<Files/>
</div>
);
};

export default Details;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DUMMY_COMPRESSED_SIZE = 1004023;
const DUMMY_UNCOMPRESSED_SIZE = 110300010;

/**
* Presents space savings or compression ratio from the given statistics.
* Renders space savings card.
*
* @return
*/
Expand All @@ -18,7 +18,7 @@ const SpaceSavings = () => {
const compressedSize = DUMMY_COMPRESSED_SIZE as number;
const uncompressedSize = DUMMY_UNCOMPRESSED_SIZE as number;

const spaceSavingsPercent = (0 === uncompressedSize) ?
const spaceSavingsPercent = (0 !== uncompressedSize) ?
100 * (1 - (compressedSize / uncompressedSize)) :
0;

Expand All @@ -28,10 +28,11 @@ const SpaceSavings = () => {
<StatCard
backgroundColor={token.colorPrimary}
stat={spaceSavingsPercentText}
textColor={token.colorWhite}
title={"Space Savings"}/>
statColor={token.colorWhite}
statSize={"6rem"}
title={"Space Savings"}
titleColor={token.colorWhite}/>
);
};


export default SpaceSavings;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Details from "./Details";
import styles from "./index.module.css";
import SpaceSavings from "./SpaceSavings";

Expand All @@ -11,6 +12,7 @@ const IngestPage = () => {
return (
<div className={styles["ingestPageGrid"]}>
<SpaceSavings/>
<Details/>
</div>
);
};
Expand Down