Skip to content

Commit 0b9e0c7

Browse files
committed
this will typescript conversion on front end
1 parent 3757168 commit 0b9e0c7

File tree

5 files changed

+79
-70
lines changed

5 files changed

+79
-70
lines changed

src/components/tabs/ImagesUser.js renamed to src/components/tabs/ImagesUser.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/* eslint-disable react/prop-types */
2-
import React, { useState } from 'react';
2+
import React, { useState, MouseEvent } from 'react';
33
import * as helper from '../helper/commands';
4+
import { ImagesProps } from '../../../types';
45

56
/**
67
* Render Images of the user has
78
*
89
* @param {*} props
910
*/
10-
const Images = (props) => {
11+
const Images = (props: ImagesProps) => {
1112
const [repo, setRepo] = useState('');
1213

13-
const handleClick = (e) => {
14+
const handleClick = (e: MouseEvent) => {
1415
e.preventDefault();
1516
helper.pullImage(repo);
1617
};

src/components/tabs/Metrics.js renamed to src/components/tabs/Metrics.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
/* eslint-disable no-tabs */
22
/* eslint-disable react/prop-types */
33
import React from 'react';
4-
import { convertToMetricsArr } from '../helper/parseContainerFormat';
54
import { Chart } from 'react-chartjs-2';
65
import LineChartDisplay from '../display/LineChartDisplay';
76
import { useSelector } from 'react-redux';
7+
import { ContainerProps, hostStats, containersList } from '../../../types';
8+
import { RootState, AppDispatch } from '../../renderer/store';
89

910
/**
1011
* Display general metrics
1112
*
1213
* @param {*} props
1314
*/
14-
const Metrics = (props) => {
15-
const hostStats = useSelector((state) => state.containersList.hostStats);
15+
const Metrics = (props : any) => {
1616
const fullRunningList = props.runningList;
17-
// const result = convertToMetricsArr(props.runningList)
18-
const result = hostStats;
19-
const cpuData = 100 - result.cpuPerc; // .toFixed(2) // 60%
20-
const memoryData = 100 - result.memPerc; // .toFixed(2)
17+
const hostStats = useSelector((state: any) => state.containersList.hostStats);
18+
const cpuData = 100 - hostStats.cpuPerc;
19+
const memoryData = 100 - hostStats.memPerc;
2120
const cpuThreshold = props.threshold[0];
2221
const memThreshold = props.threshold[1];
2322

@@ -33,23 +32,23 @@ const Metrics = (props) => {
3332
}
3433

3534
const cpu = {
36-
labels: [`Available: ${cpuData}%`, `Usage: ${result.cpuPerc}%`],
35+
labels: [`Available: ${cpuData}%`, `Usage: ${hostStats.cpuPerc}%`],
3736
datasets: [
3837
{
3938
label: 'CPU',
4039
backgroundColor: ['rgba(44, 130, 201, 1)', 'rgba(19, 221, 29, 1)'],
41-
data: [cpuData, result.cpuPerc],
40+
data: [cpuData, hostStats.cpuPerc],
4241
},
4342
],
4443
};
4544

4645
const memory = {
47-
labels: [`Available: ${memoryData}%`, `Usage: ${result.memPerc}%`],
46+
labels: [`Available: ${memoryData}%`, `Usage: ${hostStats.memPerc}%`],
4847
datasets: [
4948
{
5049
label: 'Memory',
5150
backgroundColor: ['rgba(44, 130, 201, 1)', 'rgba(19, 221, 29, 1)'],
52-
data: [memoryData, result.memPerc],
51+
data: [memoryData, hostStats.memPerc],
5352
},
5453
],
5554
};
@@ -62,10 +61,10 @@ const Metrics = (props) => {
6261
tooltips: { enabled: true, mode: 'index' },
6362
legend: { display: false },
6463
datalabels: {
65-
formatter: (value, ctx) => {
64+
formatter: (value: number, ctx: any) => {
6665
let sum = 0;
6766
const dataArr = ctx.chart.data.datasets[0].data;
68-
dataArr.map((data) => {
67+
dataArr.map((data: any) => {
6968
sum += data;
7069
});
7170
const percentage = (value * 100) / sum + '%';
@@ -84,10 +83,10 @@ const Metrics = (props) => {
8483
tooltips: { enabled: false },
8584
legend: { display: false },
8685
datalabels: {
87-
formatter: (value, ctx) => {
86+
formatter: (value: number, ctx: any) => {
8887
let sum = 0;
8988
const dataArr = ctx.chart.data.datasets[0].data;
90-
dataArr.map((data) => {
89+
dataArr.map((data: any) => {
9190
sum += data;
9291
});
9392
const percentage = (value * 100) / sum + '%';
@@ -123,7 +122,7 @@ const Metrics = (props) => {
123122
</div>
124123
<div className="legend-section">
125124
<div className="usage-box"></div>
126-
<p className="legend-text"> Usage {Math.round(result.cpuPerc)}%</p>
125+
<p className="legend-text"> Usage {Math.round(hostStats.cpuPerc)}%</p>
127126
</div>
128127
</div>
129128
</div>
@@ -144,7 +143,7 @@ const Metrics = (props) => {
144143
</div>
145144
<div className="legend-section">
146145
<div className="usage-box"></div>
147-
<p className="legend-text"> Usage {Math.round(result.memPerc)}%</p>
146+
<p className="legend-text"> Usage {Math.round(hostStats.memPerc)}%</p>
148147
</div>
149148
</div>
150149
</div>

src/components/tabs/ProcessLogs.js renamed to src/components/tabs/ProcessLogs.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/* eslint-disable react/prop-types */
2+
import { AnyAsyncThunk } from '@reduxjs/toolkit/dist/matchers';
23
import React from 'react';
34
import ProcessLogsCard from '../display/ProcessLogsCard';
5+
import { ContainerType } from '../../../types';
46

57
/**
68
* Display all running and stopped containers. Each box can be selected to view process log tables.
79
*
810
* @param {*} props
911
*/
1012

11-
const ProcessLogs = (props) => {
12-
const renderRunningList = [];
13-
props.runningList.map((container, index) => {
13+
const ProcessLogs = (props: any) => {
14+
const renderRunningList: any[] = [];
15+
props.runningList.map((container: ContainerType, index: number) => {
1416
renderRunningList.push(
1517
<ProcessLogsCard
1618
key={index}
@@ -21,8 +23,8 @@ const ProcessLogs = (props) => {
2123
);
2224
});
2325

24-
const renderStoppedList = [];
25-
props.stoppedList.map((container, index) => {
26+
const renderStoppedList: any[] = [];
27+
props.stoppedList.map((container: ContainerType, index: number) => {
2628
renderStoppedList.push(
2729
<ProcessLogsCard key={index} index={index} container={container} status='Stopped' />
2830
);

src/components/tabs/Stopped.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
/* eslint-disable react/prop-types */
2-
import React from "react";
2+
import React from 'react';
33

44
/**
55
* Display all stopped containers with functionality
66
*
77
* @param {*} props
88
*/
9-
const Stopped = (props) => {
10-
const renderStoppedList = props.stoppedList.map((container, i) => {
11-
return (
12-
<div className="box" key={`stoppedBox${i}`}>
13-
<div className="box-label">
14-
<h3>{container.Names}</h3>
15-
<p>{container.ID}</p>
16-
</div>
9+
// const Stopped = (props) => {
10+
// const renderStoppedList = props.stoppedList.map((container, i) => {
11+
// return (
12+
// <div className="box" key={`stoppedBox${i}`}>
13+
// <div className="box-label">
14+
// <h3>{container.Names}</h3>
15+
// <p>{container.ID}</p>
16+
// </div>
1717

18-
<div className="stopped-info">
19-
<li>Img: {container.Image}</li>
20-
<li>Created: {container.RunningFor}</li>
21-
<li>name: {container.Names}</li>
22-
</div>
23-
<div className="stopped-button">
24-
<button
25-
className="run-btn"
26-
onClick={() =>
27-
props.runStopped(container["ID"], props.runStoppedContainer)
28-
}
29-
>
30-
RUN
31-
</button>
32-
<button
33-
className="stop-btn"
34-
onClick={() => props.remove(container["ID"], props.removeContainer)}
35-
>
36-
REMOVE
37-
</button>
38-
</div>
39-
</div>
40-
);
41-
});
18+
// <div className="stopped-info">
19+
// <li>Img: {container.Image}</li>
20+
// <li>Created: {container.RunningFor}</li>
21+
// <li>name: {container.Names}</li>
22+
// </div>
23+
// <div className="stopped-button">
24+
// <button
25+
// className="run-btn"
26+
// onClick={() =>
27+
// props.runStopped(container["ID"], props.runStoppedContainer)
28+
// }
29+
// >
30+
// RUN
31+
// </button>
32+
// <button
33+
// className="stop-btn"
34+
// onClick={() => props.remove(container["ID"], props.removeContainer)}
35+
// >
36+
// REMOVE
37+
// </button>
38+
// </div>
39+
// </div>
40+
// );
41+
// });
4242

43-
return (
44-
<div className="renderContainers">
45-
<div className="header">
46-
<h1 className="tabTitle">Exited Containers</h1>
47-
</div>
48-
<div className="containers">{renderStoppedList}</div>
49-
</div>
50-
);
51-
};
43+
// return (
44+
// <div className="renderContainers">
45+
// <div className="header">
46+
// <h1 className="tabTitle">Exited Containers</h1>
47+
// </div>
48+
// <div className="containers">{renderStoppedList}</div>
49+
// </div>
50+
// );
51+
// };
5252

53-
export default Stopped;
53+
// export default Stopped;

types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface RunningListType {
2525
RunningFor: string,
2626
}
2727

28+
export interface hostStats {
29+
cpuPerc: string,
30+
memPerc: string,
31+
}
32+
2833
// for more info review actions.ts file and Settings.ts
2934
export type ContainerProps = {
3035
stoppedList: StoppedListType[];
@@ -36,6 +41,7 @@ export type ContainerProps = {
3641
stop: (id: string, refreshStoppedContainers: (data: StoppedContainerObj[]) => void) => void;
3742
runningList: RunningListType[];
3843
runIm: (id: ContainerType, runningList: RunningListType, callback_1: () => void, callback_2: () => void) => void;
44+
hostStats?: hostStats[];
3945
}
4046

4147
// Stopped containers have a Names key and running containers have a Name key
@@ -242,9 +248,10 @@ interface session {
242248
}
243249

244250
// "any" has been used below since strict typing was used to define these props in the tabs types
245-
interface containersList {
251+
export interface containersList {
246252
runningList: any[],
247-
stoppedList: any[]
253+
stoppedList: any[],
254+
hostStats: any,
248255
}
249256

250257
interface imagesList {

0 commit comments

Comments
 (0)