Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,39 @@
.card {
background-color: #1888fa;
}

.card :global(.ant-card-head) {
border: 0px;
}

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

.header {
display: inline-flex;
align-items: center;
justify-content: space-between;
}

.title {
font-size: 24px;
color: white;
font-weight: 600;
}

.segmented {
background-color: transparent;
color:white;

}

.segmented :global(.ant-segmented-item-selected) {
color:rgba(0, 0, 0, 0.65)
}

.statistic {
font-size: 80px;
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {useState} from "react";

import {
CloseOutlined,
PercentageOutlined,
} from "@ant-design/icons";
import {
Card,
Segmented,
Typography,
} from "antd";

import styles from "./index.module.css";
import {
DEFAULT_SIZE_OPTION,
SIZE_OPTION,
} from "./typings.js";


const {Text} = Typography;

// eslint-disable-next-line no-warning-comments
// TODO: Replace with values from database once api implemented.
const DUMMY_COMPRESSED_SIZE = 1004023;
const DUMMY_UNCOMPRESSED_SIZE = 110300010;

/**
* Presents space savings or compression ratio from the given statistics.
*
* @return
*/
const Size = () => {
const [segmentedOption, setSegmentedOption] = useState<SIZE_OPTION>(DEFAULT_SIZE_OPTION);
const compressedSize = DUMMY_COMPRESSED_SIZE;
const uncompressedSize = DUMMY_UNCOMPRESSED_SIZE;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const spaceSavingsPercent = 0 < compressedSize ?
100 * (1 - (compressedSize / uncompressedSize)) :
0;

@coderabbitai coderabbitai Bot Apr 16, 2025 •

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

Consider adding validation for uncompressedSize being zero.

The calculation handles the case where compressedSize is less than or equal to zero, but doesn't check if uncompressedSize is zero, which could lead to division by zero or NaN results.

 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
-const spaceSavingsPercent = 0 < compressedSize ?
-    100 * (1 - (compressedSize / uncompressedSize)) :
-    0;
+const spaceSavingsPercent = (0 < compressedSize && 0 < uncompressedSize) ?
+    100 * (1 - (compressedSize / uncompressedSize)) :
+    0;
📝 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
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const spaceSavingsPercent = 0 < compressedSize ?
100 * (1 - (compressedSize / uncompressedSize)) :
0;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const spaceSavingsPercent = (0 < compressedSize && 0 < uncompressedSize) ?
100 * (1 - (compressedSize / uncompressedSize)) :
0;

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.

I modfied to check only if uncompressedSize === 0. It should not be possible for compressed size or uncompressed size to be less than 0.

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.

@davemarco Thanks for implementing that check! Your approach of checking specifically for uncompressedSize === 0 is perfectly valid for preventing division by zero. And your explanation makes sense - if the data inherently cannot be negative, then checking for zero is indeed the only validation needed here. That's a more precise check than what I suggested.


// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const compressionRatio = 0 < compressedSize ?
uncompressedSize / compressedSize :
0;

const handleChange = (option: SIZE_OPTION) => {
setSegmentedOption(option);
};

return (
<Card
className={styles["card"] || ""}
hoverable={true}
>
<div className={styles["cardContent"]}>
<div className={styles["header"]}>
<Text className={styles["title"] || ""}>
{segmentedOption}
</Text>
<Segmented
className={styles["segmented"] || ""}
defaultValue={DEFAULT_SIZE_OPTION}
options={[
{value: SIZE_OPTION.SPACE_SAVINGS, icon: <PercentageOutlined/>},
{value: SIZE_OPTION.COMPRESSION_RATIO, icon: <CloseOutlined/>},
]}
onChange={handleChange}/>
</div>
<Text className={styles["statistic"] || ""}>
{segmentedOption === SIZE_OPTION.SPACE_SAVINGS ?
`${spaceSavingsPercent.toFixed(2)}%` :
`${compressionRatio.toFixed(2)}x`}
</Text>
</div>
</Card>
);
};


export default Size;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum SIZE_OPTION {
SPACE_SAVINGS = "Space Savings",
COMPRESSION_RATIO = "Compression Ratio",
}

const DEFAULT_SIZE_OPTION = SIZE_OPTION.SPACE_SAVINGS;

export {
DEFAULT_SIZE_OPTION, SIZE_OPTION,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.ingestPageGrid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto;
padding: 20px;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import styles from "./index.module.css";
import Size from "./Size";


/**
* Presents compression statistics.
*
* @return
*/
const IngestPage = () => {
return (
<div>
<h1>Ingest Page</h1>
<p>This is the Ingest Page.</p>
<div className={styles["ingestPageGrid"]}>
<Size/>
</div>
);
};
Expand Down