Skip to content

Commit 54f0c74

Browse files
authored
Merge pull request #2 from oslabs-beta/Tim-Roberto/aws-data
Tim roberto/aws data
2 parents e946fc4 + 5e5b324 commit 54f0c74

22 files changed

+869
-68
lines changed

app/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import React, { useState } from 'react';
22
import Splash from './components/Splash';
33
import DashboardContainer from './containers/DashboardContainer';
44
import './stylesheets/scrollBar.scss';
5+
import { QueryClient, QueryClientProvider } from 'react-query';
6+
import { ReactQueryDevtools } from 'react-query/devtools'
7+
8+
const queryClient = new QueryClient();
59

610
const App: React.FC = React.memo(() => {
711
return (
8-
<>
12+
<QueryClientProvider client={queryClient}>
13+
<ReactQueryDevtools initialIsOpen={false} />
914
<Splash />
1015
<DashboardContainer />
11-
</>
16+
</QueryClientProvider>
1217

1318
)
1419
});

app/components/Occupied.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import '../stylesheets/Occupied.scss';
4444
import { DashboardContext } from '../context/DashboardContext';
4545
import { ApplicationContext } from '../context/ApplicationContext';
4646
import { CommsContext } from '../context/CommsContext';
47+
import { AwsContext } from '../context/AwsContext';
4748

4849
// TYPESCRIPT
4950
interface StyleProps {
@@ -52,6 +53,7 @@ interface StyleProps {
5253
type ClickEvent = React.MouseEvent<HTMLElement>;
5354

5455
const Occupied = React.memo(() => {
56+
const { awsData, fetchAwsData } = useContext(AwsContext);
5557
const { setServicesData, app, setApp } = useContext(ApplicationContext);
5658
const { user, applications, getApplications, deleteApp, mode } = useContext(DashboardContext);
5759
const { commsData } = useContext(CommsContext);
@@ -82,10 +84,12 @@ const Occupied = React.memo(() => {
8284
const handleClick = (event: ClickEvent, selectedApp: string, i: number) => {
8385
console.log(selectedApp, i);
8486
if (delRef.current[i] && !delRef.current[i].contains(event.target)) {
87+
console.log('the application that you clicked is: ', selectedApp)
8588
setIndex(i);
8689
setApp(selectedApp);
8790
setServicesData([]);
8891
setServiceModalOpen(true);
92+
fetchAwsData();
8993
}
9094
};
9195

app/components/SignUp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SignUp = React.memo(() => {
1414
return (
1515
<div className="home">
1616
<div className="welcome" data-testid="SignUp">
17-
<h1 className="welcomeMessage">Welcome Chronos!</h1>
17+
<h1 className="welcomeMessage">Welcome to Chronos!</h1>
1818
<h2>Your all-in-one application monitoring tool.</h2>
1919

2020
<form className="form" onSubmit={handleSubmit}>

app/components/TransferColumns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const TransferColumns = React.memo(() => {
148148
temp.push(newCategory);
149149
}
150150
}
151-
console.log('SelectedMetrics is: ', temp);
151+
console.log('temp array with requested graphs is: ', temp);
152152
setSelectedMetrics(temp);
153153
};
154154

app/containers/AWSGraphsContainer.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,34 @@ import { useNavigate, useParams } from 'react-router-dom';
44
import { ApplicationContext } from '../context/ApplicationContext';
55
import * as DashboardContext from '../context/DashboardContext';
66
import lightAndDark from '../components/Styling';
7+
import { useQuery } from 'react-query';
8+
import { AwsContext } from '../context/AwsContext';
9+
10+
const AwsGraphsContainer: React.FC = React.memo(props => {
11+
const { awsData, fetchAwsData, setAwsData } = useContext(AwsContext);
12+
13+
useEffect(() => {
14+
fetchAwsData();
15+
})
16+
17+
// const { data, status, isLoading } = useQuery('awsData', fetchAwsData);
18+
19+
// if(status === 'loading') {
20+
// return <p>Loading...</p>
21+
// }
22+
23+
// if(status === 'error') {
24+
// return <p>Error!</p>
25+
// }
26+
27+
// else {
28+
return (
29+
<div className='test-container'>
30+
<p>AWS TEST DATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p>
31+
<p>Here is our data: {awsData}</p>
32+
</div>
33+
)
34+
// }
35+
});
36+
37+
export default AwsGraphsContainer;

app/containers/DashboardContainer.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import DashboardContextProvider from '../context/DashboardContext';
99
import DockerContextProvider from '../context/DockerContext';
1010
import EventContextProvider from '../context/EventContext';
1111
import QueryContextProvider from '../context/QueryContext';
12+
import AwsContextProvider from '../context/AwsContext';
1213
import '../stylesheets/Dashboard.scss';
1314

1415
const DashboardContainer = React.memo(() => {
15-
const [visible, setVisible] = useState(false);
16-
useEffect(() => {
17-
setTimeout(() => setVisible(true), 4000);
18-
}, []);
16+
const [visible, setVisible] = useState(true);
17+
18+
// useEffect(() => {
19+
// setTimeout(() => setVisible(true), 4000);
20+
// }, []);
1921

2022
return (
2123
<>
@@ -29,8 +31,10 @@ const DashboardContainer = React.memo(() => {
2931
<HealthContextProvider>
3032
<EventContextProvider>
3133
<QueryContextProvider>
32-
<SidebarContainer />
33-
<MainContainer />
34+
<AwsContextProvider>
35+
<SidebarContainer />
36+
<MainContainer />
37+
</AwsContextProvider>
3438
</QueryContextProvider>
3539
</EventContextProvider>
3640
</HealthContextProvider>

app/containers/GraphsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const GraphsContainer: React.FC = React.memo(props => {
7272
if (service.includes('kubernetesmetrics')) {
7373
fetchEventData('kubernetesmetrics');
7474
}
75-
}, 3000)
75+
}, 10000)
7676
);
7777
} else {
7878
if (intervalID) clearInterval(intervalID);

app/context/ApplicationContext.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4444
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
4545
let result: any;
4646
if (tryParseJSON(data)) result = JSON.parse(data);
47+
console.log('result from ipcrenderer services response is: ', result);
4748
setServicesData(result);
4849
ipcRenderer.removeAllListeners('servicesResponse');
4950
});
@@ -64,7 +65,8 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
6465
const store: object = {};
6566
data.forEach(el => {
6667
store[el.metric] = el;
67-
});
68+
})
69+
console.log('result from getSavedMetrics is: ', store)
6870
setSavedMetrics(store);
6971
});
7072
}, []);

app/context/AwsContext.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { useCallback, useState, useEffect } from 'react';
2+
import Electron from 'electron';
3+
import { transformData } from './helpers';
4+
const { ipcRenderer } = window.require('electron');
5+
import { useQuery } from 'react-query';
6+
7+
export const AwsContext = React.createContext<any>(null);
8+
9+
interface Props {
10+
children: any;
11+
}
12+
13+
const AwsContextProvider: React.FC<Props> = React.memo(({ children }) => {
14+
const [awsData, setAwsData] = useState<any>(null)
15+
16+
const fetchAwsData = () => {
17+
ipcRenderer.send('awsMetricsRequest');
18+
ipcRenderer.on('awsMetricsResponse', (event: Electron.Event, res: any) => {
19+
// console.log('data fetched from awsContext', res);
20+
setAwsData(res);
21+
// return res;
22+
})
23+
};
24+
25+
useEffect(() => {
26+
console.log('awsdata after fetch is: ', awsData)
27+
});
28+
29+
return (
30+
<AwsContext.Provider
31+
value={{ fetchAwsData, awsData, setAwsData }}
32+
>
33+
{children}
34+
</AwsContext.Provider>
35+
);
36+
});
37+
38+
export default AwsContextProvider;

app/context/CommsContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const CommsContextProvider: React.FC<Props> = React.memo((props) => {
4646
ipcRenderer.on('commsResponse', (event: Electron.Event, data: any) => {
4747
let result: any;
4848
if (tryParseJSON(data)) result = JSON.parse(data);
49+
console.log('communication data from fetch request is: ', result);
4950
setCommsData(result);
5051
});
5152
}

0 commit comments

Comments
 (0)