Skip to content

Commit ebd7fbd

Browse files
authored
Merge pull request #119 from HyperloopUPV-H8/ethernet-view/load-files
[ethernet-view] Load files logic
2 parents 6c6754d + fc0a8bd commit ebd7fbd

17 files changed

Lines changed: 465 additions & 23 deletions

File tree

ethernet-view/package-lock.json

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethernet-view/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lightweight-charts": "^4.1.2",
2121
"lodash": "^4.17.21",
2222
"nanoid": "^4.0.2",
23+
"papaparse": "^5.4.1",
2324
"react": "^18.2.0",
2425
"react-dom": "^18.2.0",
2526
"react-icons": "^4.6.0",
@@ -39,6 +40,7 @@
3940
"@types/events": "^3.0.0",
4041
"@types/lodash": "^4.14.191",
4142
"@types/node": "^18.11.9",
43+
"@types/papaparse": "^5.3.14",
4244
"@types/react": "^18.0.24",
4345
"@types/react-dom": "^18.0.8",
4446
"@types/react-virtualized-auto-sizer": "^1.0.1",
Lines changed: 3 additions & 0 deletions
Loading

ethernet-view/src/components/FormComponents/Button/Button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { lightenHSL } from "utils/color";
44

55
type Props = {
66
label: string;
7-
onClick: (ev: React.MouseEvent) => void;
7+
onClick?: (ev: React.MouseEvent) => void;
88
disabled?: boolean;
99
color?: string;
1010
className?: string;
@@ -13,7 +13,7 @@ type Props = {
1313
export const Button = ({
1414
label,
1515
color = "hsl(29, 88%, 57%)",
16-
onClick,
16+
onClick = () => {},
1717
disabled,
1818
className = "",
1919
}: Props) => {

ethernet-view/src/hooks/useSplit/useSplit.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,34 @@ export type SplitElement = {
1313
minLength: number;
1414
};
1515

16-
export function useSplit(minLengths: number[], direction: Orientation) {
16+
/**
17+
* The `useSplit` function in TypeScript is used to manage resizable elements with specified initial
18+
* lengths and minimum lengths in a given direction.
19+
* @param {number[] | undefined} initialLengths - The `initialLengths` parameter is an array of numbers
20+
* representing the initial lengths of the elements to be split. It can be either `undefined` or an
21+
* array of numbers. If it is `undefined`, if its length is not equal to the length of the
22+
* `minLengths` array or if its sum is not equal to 1, the `initialLengths` will be set proportionally equal.
23+
* @param {number[]} minLengths - The `minLengths` parameter in the `useSplit` function represents an
24+
* array of minimum lengths for each split element. These minimum lengths determine the smallest size
25+
* each element can be resized to. If a user tries to resize an element below its minimum length, the
26+
* element will be collapsed.
27+
* @param {Orientation} direction - The `direction` parameter in the `useSplit` function is used to
28+
* determine the orientation of the split elements. It is of type `Orientation`, which is likely an
29+
* enum or type that specifies whether the split should be horizontal or vertical. This helps in
30+
* calculating the resizing of elements based on the direction
31+
* @returns The `useSplit` function returns an array containing the `elements` state and the
32+
* `handleMouseDown` function from the `separatorEventHandler`.
33+
*/
34+
export function useSplit(minLengths: number[], direction: Orientation, initialLengths?: number[]) {
35+
36+
if(!initialLengths || initialLengths.length != minLengths.length || initialLengths.reduce((prev, curr) => prev + curr, 0) != 1) {
37+
initialLengths = minLengths.map(() => 1 / minLengths.length);
38+
}
39+
1740
const [elements, setElements] = useState<SplitElement[]>(
18-
minLengths.map((minLength) => ({
19-
length: 1 / minLengths.length,
20-
minLength: minLength,
41+
initialLengths.map((length, index) => ({
42+
length,
43+
minLength: minLengths[index],
2144
}))
2245
);
2346

ethernet-view/src/layouts/SplitLayout/SplitLayout.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ type Props = {
1111
collapsedIcon: string;
1212
}[];
1313
orientation?: Orientation;
14+
initialLengths?: number[];
1415
};
1516

16-
export const SplitLayout = ({ components, orientation = Orientation.HORIZONTAL }: Props) => {
17+
export const SplitLayout = ({ initialLengths, components, orientation = Orientation.HORIZONTAL }: Props) => {
1718

18-
const minSizes = components.map(() => 0.05);
19-
const [splitElements, onSeparatorMouseDown] = useSplit(minSizes, orientation);
19+
const minLengths = components.map(() => 0.05);
20+
const [splitElements, onSeparatorMouseDown] = useSplit(minLengths, orientation, initialLengths);
2021

2122
return (
2223
<div
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.LoggerPage {
2+
display: flex;
3+
width: 100%;
4+
gap: 1rem;
5+
}
6+
7+
.LogsColumn {
8+
flex: 1;
9+
}
10+
11+
.ChartsColumn {
12+
flex: 3;
13+
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { Orientation } from "hooks/useSplit/Orientation";
2-
import { SplitLayout } from "layouts/SplitLayout/SplitLayout";
31
import { ChartsColumn } from "pages/LoggerPage/ChartsColumn/ChartsColumn";
4-
import chart from "assets/svg/chart.svg"
2+
import { LogsColumn } from "./LogsColumn/LogsColumn";
3+
import { SplitLayout } from "layouts/SplitLayout/SplitLayout";
54

65
export const LoggerPage = () => {
76
return (
8-
<SplitLayout
7+
<SplitLayout
98
components={[
109
{
11-
component: <ChartsColumn />,
12-
collapsedIcon: chart,
10+
component: <LogsColumn />,
11+
collapsedIcon: ""
1312
},
13+
{
14+
component: <ChartsColumn />,
15+
collapsedIcon: ""
16+
}
1417
]}
15-
orientation={Orientation.HORIZONTAL}
16-
></SplitLayout>
18+
initialLengths={[0.3, 0.7]}
19+
/>
1720
);
1821
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.controlsWrapper {
2+
width: 100%;
3+
display: flex;
4+
padding: 1rem;
5+
gap: 2rem;
6+
}
7+
8+
.button {
9+
flex: 1;
10+
padding: 0.2rem;
11+
font-size: large;
12+
border-style: none;
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Button } from "components/FormComponents/Button/Button"
2+
import styles from "./Controls.module.scss"
3+
import { UploadInformation, UploadState } from "../../LogLoader";
4+
5+
type Props = {
6+
uploadInformation: UploadInformation;
7+
onLoad: () => void;
8+
onRemove: () => void;
9+
}
10+
11+
export const Controls = ({uploadInformation, onLoad, onRemove}: Props) => {
12+
return (
13+
<div className={styles.controlsWrapper}>
14+
15+
<Button
16+
label="Load"
17+
color="#317ae7"
18+
disabled={uploadInformation.state !== UploadState.SUCCESS}
19+
onClick={() => onLoad()}
20+
/>
21+
22+
<Button
23+
label="Remove"
24+
disabled={uploadInformation.state !== UploadState.SUCCESS && uploadInformation.state !== UploadState.ERROR}
25+
onClick={() => onRemove() }
26+
/>
27+
28+
</div>
29+
)
30+
}

0 commit comments

Comments
 (0)