Repository navigation
feat(new-webui): Add panel to ingest page with mocked compression statistics. #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a1171e4
saving
bbda9e4
ingest
90230c2
fix lint
e1bee56
latest
0aca620
simplify
4d04da3
fix
0ff2bc8
fix lint
760d8b2
add back page
2cfcbb2
review
1fac0a6
latest
72bb4be
latest
3ca51e4
junhao review
0d9a840
small change
00574a0
latest
6a1273a
small
735c949
small
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
components/log-viewer-webui/client/src/pages/IngestPage/Size/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
81 changes: 81 additions & 0 deletions
81
components/log-viewer-webui/client/src/pages/IngestPage/Size/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| // 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; | ||
10 changes: 10 additions & 0 deletions
10
components/log-viewer-webui/client/src/pages/IngestPage/Size/typings.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }; |
6 changes: 6 additions & 0 deletions
6
components/log-viewer-webui/client/src/pages/IngestPage/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
9 changes: 6 additions & 3 deletions
9
...wer-webui/client/src/pages/IngestPage.tsx → ...bui/client/src/pages/IngestPage/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
📝 Committable suggestion
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 === 0is 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.