Skip to content

Commit 67d94e1

Browse files
committed
add local storage and load faster
1 parent 53bf90a commit 67d94e1

File tree

9 files changed

+152
-14
lines changed

9 files changed

+152
-14
lines changed

src/app/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function Home() {
1111
const [loading, setLoading] = useState<boolean>(true);
1212
const [workLoadOne, setWorkLoadOne] = useState<string>('');
1313
const [workLoadTwo, setWorkLoadTwo] = useState<string>('');
14-
const [activeTab, setActiveTab] = useState(tabs[0]);
14+
const [activeTab, setActiveTab] = useState(tabs[1]);
1515

1616
const setWorkLoadValueOne = (e: any) => {
1717
setWorkLoadOne(e.target.value);
@@ -88,7 +88,7 @@ export default function Home() {
8888

8989
<div className="mt-4 tab body">
9090
{activeTab === "Deployments" && <DeploymentTab workLoadOne={workLoadOne} workLoadTwo={workLoadTwo} loading={loading} closeLoading={closeLoading} />}
91-
{activeTab === "Config Map" && <ConfigMapTab />}
91+
{activeTab === "Config Map" && <ConfigMapTab loading={loading} closeLoading={closeLoading} workLoadOne={workLoadOne} workLoadTwo={workLoadTwo}/>}
9292
{activeTab === "Key Vault" && <p>📜 Key vaults</p>}
9393
</div>
9494
</div>

src/components/configmap/index.tsx

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1-
const ConfigMapTab = () => {
1+
import { useEffect, useState } from "react";
2+
import { getDeploymentsData } from "@/functions/localstorage";
3+
import { findName } from "@/functions";
4+
import CountTable from "./tables/countInfo";
5+
import ConfigMapDeployments from "./tables/deployments";
6+
7+
const ConfigMapTab = (props: any) => {
8+
const { workLoadOne, workLoadTwo, loading } = props;
9+
const [configMapData, setConfigMapData] = useState<any>([]);
10+
const [deploymentsDiff, setDeploymentsDiff] = useState<any>(null);
11+
useEffect(() => {
12+
setConfigMapData(getDeploymentsData());
13+
props.closeLoading(false);
14+
}, []);
15+
16+
217
return (
3-
<div>
4-
<h1>ConfigMap</h1>
18+
<div className="flex flex-row p-2 gap-8">
19+
{
20+
configMapData?.map((deployment: any, index: number) => (
21+
22+
<div key={index} className="flex flex-col gap-2">
23+
<h3 className="font-bold flex-row text-l p-2">
24+
{`${index + 1}.`} <span className="text-blue-500"> {index == 0 ? findName(workLoadOne || workLoadTwo) : findName(workLoadTwo)} </span> <small className="text-sm">({index == 0 ? workLoadOne || workLoadTwo : workLoadTwo})</small>
25+
&nbsp; <small className="text-xs font-light text-green-500">{loading ? "Loading..." : ""}</small>
26+
</h3>
27+
<div className="flex flex-col gap-2">
28+
<CountTable deployments={deployment} />
29+
<ConfigMapDeployments deployments={deployment} title="Services" />
30+
</div>
31+
</div>
32+
))
33+
}
534
</div>
635
);
736
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import { getDeploymentStatus } from "@/functions";
3+
4+
const ConfigMapDeploymentListItems = ({ deployment, index }: { deployment: any,index: number }) => {
5+
return (
6+
<tr><td className="border border-gray-300 px-4 py-2">{index+1}</td> </tr>
7+
)
8+
}
9+
10+
export default ConfigMapDeploymentListItems;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { deploymentHavingIssue, filterDeployments } from '@/functions';
2+
import React from 'react';
3+
4+
const CountTable = (props: any) => {
5+
const allServices = filterDeployments(props.deployments);
6+
const deploymentHavingIssues = deploymentHavingIssue(allServices);
7+
8+
return (
9+
<div className="overflow-x-auto">
10+
<table className="w-full text-center table-auto border-collapse border border-gray-300">
11+
<thead>
12+
<tr className="bg-gray-200">
13+
<th className="border border-gray-300 px-4 py-2">Services</th>
14+
<th className="border border-gray-300 px-4 py-2">Config Item</th>
15+
<th className="border border-gray-300 px-4 py-2">Diff</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<td className="border border-gray-300 px-4 py-2">{allServices.length}</td>
21+
<td className="border border-gray-300 px-4 py-2">2</td>
22+
<td className={`border border-gray-300 px-4 py-2 ${deploymentHavingIssues.length ? "text-red-500": "text-green-500"}`}>{deploymentHavingIssues.length}</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
</div>
27+
);
28+
};
29+
30+
export default CountTable;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { getDeploymentStatus } from "@/functions";
2+
3+
const ConfigMapDeploymentList = ({ deployment, index }: { deployment: any, index: number }) => {
4+
5+
console.log("deploymentcmap", deployment)
6+
return (
7+
<>
8+
<tr>
9+
<td className="border border-gray-300 px-4 py-2">{index + 1}</td>
10+
<td className="border border-gray-300 px-4 py-2">{deployment.name}</td>
11+
<td className="border border-gray-300 px-4 py-2 block-inline cursor-pointer"> <p title='Replicas'>{deployment.replicas}</p></td>
12+
<td className="border border-gray-300 px-4 py-2 block-inline cursor-pointer"> <p title='Available'>{deployment.available}</p></td>
13+
<td className="border border-gray-300 px-4 py-2 block-inline"> <a href="#" className="text-blue-500">Open / Close </a></td>
14+
</tr>
15+
<tr>
16+
<td className="border border-gray-300 px-4 py-2 text-sm gap-2 bg-green-100 " colSpan={5}>
17+
<div className="gap-3 p-2">
18+
<ol type="1">
19+
<li>Swagger API</li>
20+
<li>Swagger API2</li>
21+
</ol>
22+
</div>
23+
<div className="gap-3">
24+
<hr className=" border-gray-300 mt-3 mb-3"></hr>
25+
<a className="text-blue-500 underline" href="">Set current</a>
26+
</div>
27+
28+
</td>
29+
</tr>
30+
31+
</>
32+
33+
)
34+
}
35+
36+
export default ConfigMapDeploymentList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
import React from 'react';
3+
import { filterDeployments } from '@/functions';
4+
import ConfigMapDeploymentList from './deploymentItem';
5+
6+
const ConfigMapDeployments = (props: any) => {
7+
const { deployments, type } = props;
8+
const deploymentList: any[] = filterDeployments(deployments);
9+
10+
return (
11+
<div className="overflow-x-auto">
12+
{ deploymentList.length ? <h4 className={type == 'diff' ? 'text-yellow-600 gap-2': ''}>{props.title}</h4> : <></>}
13+
<table className="w-full table-auto border-collapse border border-gray-300 mt-2">
14+
<tbody>
15+
{deploymentList.map((deployment: any, index: number) => (
16+
<ConfigMapDeploymentList key={index} index={index} deployment={deployment} />
17+
))}
18+
</tbody>
19+
</table>
20+
</div>
21+
);
22+
};
23+
24+
export default ConfigMapDeployments;

src/components/deployment/main.tsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,32 @@ const DeploymentTab = (props: any) => {
1818
props.workLoadOne ? `workload1=${props.workLoadOne}` : '',
1919
props.workLoadTwo ? `workload2=${props.workLoadTwo}` : ''
2020
].filter(Boolean).join('&');
21+
try {
22+
const response = await httpRequest.get(`/api/deploy?${queryString}`);
23+
saveDeploymentsData(response.data);
24+
setData(response.data);
25+
setDataDiff(findDifferentNamesInList(response.data as unknown as any));
2126

22-
const response = await httpRequest.get(`/api/deploy?${queryString}`);
23-
saveDeploymentsData(response.data);
24-
setData(response.data);
25-
setDataDiff(findDifferentNamesInList(response.data as unknown as any));
26-
27-
if (response && response.data && response.data.length > 0) {
27+
if (response && response.data && response.data.length > 0) {
28+
props.closeLoading(false);
29+
}
30+
} catch (error) {
31+
console.error('Error fetching deployments:', error);
2832
props.closeLoading(false);
2933
}
34+
3035
};
3136

32-
useEffect(() => {
37+
useEffect(() => {
3338
setData(getDeploymentsData());
3439
props.closeLoading(false);
3540
}, []);
3641

37-
useEffect(() => {
42+
useEffect(() => {
3843
if (workLoadOne || workLoadTwo) {
3944
getDeployments(props);
4045
}
41-
46+
4247
}, [loading]);
4348

4449

src/pages/api/deploy.ts

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ async function getDeployments(context: string, loadConfig: boolean): Promise<Dep
9696
replicas,
9797
available,
9898
configMaps,
99+
isConfigMapOpen: false,
100+
setCurrentView: false
99101
});
100102
}
101103

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ export interface Deployment {
44
replicas: number;
55
available: number;
66
configMaps: any;
7+
isConfigMapOpen: boolean;
8+
setCurrentView: boolean;
79
}

0 commit comments

Comments
 (0)