Skip to content

Commit 4a8daa9

Browse files
committed
removed ssh slice, load/save everything from/to DB.
list all/user specific repos from db
1 parent d2ba914 commit 4a8daa9

21 files changed

+237
-155
lines changed

src/ipc-handlers/persistent-db-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ipcMain } from "electron";
22
import { JsonDB, Config } from "node-json-db";
33

4-
var db = new JsonDB(new Config("mgam_git_repo_mapping.bin"));
4+
var db = new JsonDB(new Config("mgam_git_repo_mapping.bin", true, true, "/"));
55

66
ipcMain.handle("db:reloadAsync", () => {
77
return db.reload();

src/ipc-handlers/ssh-work/generate-add-remove.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function _addIdentityKeysToConfig(git_username: string, fileName: string, consta
3838
lines.push(` User git`);
3939
lines.push(` IdentityFile ~/${appWorkingDir}/${fileName}`);
4040
lines.push(` # AddedBy ${addedByName}`);
41-
lines.push(` # AddedAt ${dt.toISOString()}`);
4241
lines.push(end);
4342
appendFileSync(sshConfigFilePath, lines.join("\n"));
4443
}

src/ipc-handlers/ssh-work/get-account.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class ConfigDetail {
88
User: string;
99
IdentityFile: string;
1010
AddedBy: string;
11-
AddedAt: string;
1211
}
1312

1413
function getSshAccounts() {
@@ -44,9 +43,6 @@ function getSshAccounts() {
4443
if (c.startsWith("# AddedBy ")) {
4544
cur.AddedBy = c.replace("# AddedBy ", "").trim();
4645
}
47-
if (c.startsWith("# AddedAt ")) {
48-
cur.AddedAt = c.replace("# AddedAt ", "").trim();
49-
}
5046
});
5147
checkAndAdd();
5248

src/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let db = {
1515
}
1616

1717
let obj = {
18-
readConfigFile: () => ipcRenderer.invoke("get-ssh-config-file", "config - copy"),
18+
readConfigFile: () => ipcRenderer.invoke("get-ssh-config-file"),
1919
generateSshKeys: (git_username: string) => ipcRenderer.invoke("generate-ssh-key", git_username),
2020
remove_sshkey: (git_username: string) => ipcRenderer.invoke("remove-ssh-key", git_username),
2121
readPublicKey: (git_username: string) => ipcRenderer.invoke("read-pub-ssh-key", git_username),

web-app/screens/accountDetails/accountDetails.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const AccountDetails = ({ gitUserName, addedAt }) => {
5151
</div>
5252
<Button icon='pi pi-trash' severity="danger" label='Delete' title='Delete' onClick={() => confirmRef.current.showConfirmDialog()} />
5353
</div>
54-
<RepoTable />
54+
<RepoTable gitUserName={gitUserName} />
5555
</Panel>
5656
</div>
5757
</SidePanelPage>

web-app/screens/accountDetails/deleteConfirmationDialog.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ import { ConfirmDialog, confirmDialog } from "primereact/confirmdialog"
33
import { useDispatch } from "react-redux";
44
import { globalStuffActions } from "../../store/slices/globalStuffSlice";
55
import { ScreensMapping } from "../screenConfig";
6-
import { sshKeysActions } from "../../store/slices/sshKeySlice";
7-
import { removeSshKeys } from "../../src/non-component-sharing";
6+
import { deleteProfile } from "../../src/db_operations";
87

98

109
export const DeleteConfirmationDialog = forwardRef(({ gitUserName }, ref) => {
1110
const dispatch = useDispatch();
12-
const deleteAcc = () => {
13-
removeSshKeys(gitUserName).then(() => {
14-
dispatch(sshKeysActions.loadSavedKeys())
15-
dispatch(globalStuffActions.setScreen({
16-
screen: ScreensMapping.addedKeys,
17-
extra: {}
18-
}))
19-
});
11+
const deleteProfileAndRefresh = async () => {
12+
await deleteProfile(dispatch, gitUserName);
13+
dispatch(globalStuffActions.setScreen({
14+
screen: ScreensMapping.addedKeys,
15+
extra: {}
16+
}))
2017
};
2118

2219
const showConfirmDialog = () => {
@@ -30,7 +27,7 @@ export const DeleteConfirmationDialog = forwardRef(({ gitUserName }, ref) => {
3027
className: `max-w-30rem`,
3128
icon: 'pi pi-info-circle',
3229
acceptClassName: 'p-button-danger',
33-
accept: deleteAcc,
30+
accept: deleteProfileAndRefresh,
3431
});
3532
}
3633

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
import { Column } from "primereact/column";
22
import { DataTable } from "primereact/datatable";
3-
import React from "react";
3+
import React, { useMemo } from "react";
4+
import { useSelector } from "react-redux";
45

5-
export const RepoTable = () => {
6-
const items = [{
7-
field1: '1- Field 1',
8-
field2: '1- Field 2',
9-
field3: '1- Field 3',
10-
field4: '1- Field 4',
11-
}, {
12-
field1: '2- Field 1',
13-
field2: '2- Field 2',
14-
field3: '2- Field 3',
15-
field4: '2- Field 4',
16-
}, {
17-
field1: '3- Field 1',
18-
field2: '3- Field 2',
19-
field3: '3- Field 3',
20-
field4: '3- Field 4',
21-
}, {
22-
field1: '4- Field 1',
23-
field2: '4- Field 2',
24-
field3: '4- Field 3',
25-
field4: '4- Field 4',
26-
}]
27-
return <DataTable value={items} className="text-primary">
28-
<Column header="Git Name" field="field1" ></Column>
29-
<Column header="Github Profile" field="field2" ></Column>
30-
<Column header="Added At" field="field3"></Column>
31-
<Column header='' field="field4"></Column>
6+
export const RepoTable = ({ gitUserName }) => {
7+
let { repoList } = useSelector(st => st.gitRepoMapping);
8+
let ownRepos = useMemo(() => {
9+
return repoList.filter(c => c.owner === gitUserName)
10+
}, [gitUserName])
11+
return <DataTable value={ownRepos} className="text-primary">
12+
<Column header="Repo Name" field="repoName" ></Column>
13+
<Column header="Account" field="owner" ></Column>
14+
<Column header="Path" field="localPath"></Column>
3215
</DataTable>
3316
}

web-app/screens/addNewAccount/sections/section_configGit.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { Tag } from "primereact/tag";
77
import { copyToClip, getPublicKey, openExternalLink, showToast } from "../../../src/non-component-sharing";
88
import { addGitAccountActions } from "../../../store/slices/addGitAccountSlice";
99
import { ShowPublicKeyDialog, ShowSshConfigureVideoDialog } from "../../../components/commonDialogComp";
10+
import { profilePublickeyAddedToGit } from "../../../src/db_operations";
1011

1112

1213
export const Section_ConfigGit = () => {
1314
const dispatch = useDispatch();
14-
const { name, confirmedPubKeyConfigured } = useSelector(st => st.addGitAccount);
15+
const { name: gitUserName, confirmedPubKeyConfigured } = useSelector(st => st.addGitAccount);
1516

1617
const [dialogShow, setDialogShow] = useState({
1718
video: false,
@@ -33,8 +34,13 @@ export const Section_ConfigGit = () => {
3334
});
3435
}
3536

37+
const confirmPublicKeyAdded = async () => {
38+
await profilePublickeyAddedToGit(gitUserName, !confirmedPubKeyConfigured);
39+
dispatch(addGitAccountActions.toggleConfPubKeyConfig())
40+
}
41+
3642
useEffect(() => {
37-
getPublicKey(name).then(key => {
43+
getPublicKey(gitUserName).then(key => {
3844
setPubKey(key);
3945
})
4046
}, []);
@@ -52,7 +58,7 @@ export const Section_ConfigGit = () => {
5258
<i className="text-primary"><span className="font-semibold">Remember:</span> Your private key is still in your local system, and doesn't need to be give to anyone.</i><br /><br />
5359
We can configure SSH by following steps -
5460
<ol style={{ lineHeight: `30px` }}>
55-
<li>goto your github account <code className="text-primary">"https://github.com/{name}"</code></li>
61+
<li>goto your github account <code className="text-primary">"https://github.com/{gitUserName}"</code></li>
5662
<li>navigate to <code className="text-primary">"Settings"</code></li>
5763
<li>navigate to <code className="text-primary">"SSH and GPG keys"</code></li>
5864
<li>click on button <code className="text-primary">"New SSH Key" </code><Tag value="Open" icon="pi pi-external-link" className="cursor-pointer" onClick={() => openExternalLink(`https://github.com/settings/ssh/new`)} /></li>
@@ -76,7 +82,7 @@ export const Section_ConfigGit = () => {
7682
icon="pi pi-check"
7783
iconPos="right"
7884
size="sm"
79-
onClick={() => dispatch(addGitAccountActions.toggleConfPubKeyConfig())}
85+
onClick={confirmPublicKeyAdded}
8086
outlined={!confirmedPubKeyConfigured}
8187
></Button>
8288
</div>

web-app/screens/addNewAccount/sections/section_gen_key.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Message } from "primereact/message"
66
import { Button } from "primereact/button"
77
import { useDispatch, useSelector } from "react-redux"
88
import { addGitAccountActions } from "../../../store/slices/addGitAccountSlice"
9-
import { generateSshKeys, isGitUserExist, showToast } from "../../../src/non-component-sharing"
10-
import { sshKeysActions } from "../../../store/slices/sshKeySlice"
9+
import { isGitUserExist, showToast } from "../../../src/non-component-sharing"
10+
import { addProfile } from "../../../src/db_operations"
1111

1212

1313
export const Section_GenKey = () => {
@@ -40,9 +40,8 @@ export const Section_GenKey = () => {
4040
: 'this is not a valid github user. Check name again!'
4141

4242
const addKeys = () => {
43-
generateSshKeys(gitData.name).then(() => {
43+
addProfile(dispatch, gitData.name).then(() => {
4444
dispatch(addGitAccountActions.markKeyAdded())
45-
dispatch(sshKeysActions.loadSavedKeys())
4645
showToast({ severity: 'success', summary: 'Key Generated', detail: `Key as been generated, move next to Configure Git account.`, life: 5000 })
4746
}).catch(ex => {
4847
let { message } = ex;

web-app/screens/addNewAccount/sections/section_testComplete.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import { useDispatch, useSelector } from "react-redux"
44
import { showToast, verifySSHAccess } from "../../../src/non-component-sharing";
55
import { Panel } from "primereact/panel";
66
import { addGitAccountActions } from "../../../store/slices/addGitAccountSlice";
7+
import { gitConnectedTested } from "../../../src/db_operations";
78

89
export const Section_TestAndComplete = () => {
910
const dispatch = useDispatch();
10-
let { name } = useSelector(st => st.addGitAccount);
11+
let { name: gitUserName } = useSelector(st => st.addGitAccount);
1112
let [gitCon, setGitCon] = useState({
1213
canConnect: undefined,
1314
processing: false
1415
});
1516
const verifyAccess = () => {
1617
setGitCon(st => ({ ...st, processing: true }));
17-
verifySSHAccess(name).then(canConnect => {
18+
verifySSHAccess(gitUserName).then(canConnect => {
1819
setGitCon(st => ({ ...st, processing: false, canConnect }));
1920
showToast({
2021
summary: 'Git Access',
2122
severity: canConnect ? 'success' : 'error',
2223
detail: `SSH Keys are ${canConnect ? '' : 'not '}configured correctly, and ${canConnect ? 'can' : 'can\'t'} access git.`,
2324
life: 5000,
2425
})
26+
gitConnectedTested(gitUserName, canConnect);
2527
dispatch(addGitAccountActions.markGitConnectionTested(canConnect));
2628
}).catch(() => {
2729
setGitCon(st => ({ ...st, processing: false, canConnect: false }));

web-app/screens/addedKeys.jsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useCallback, useEffect } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
3-
import { sshKeysActions } from '../store/slices/sshKeySlice';
43
import { DataTable } from 'primereact/datatable';
54
import { Column } from 'primereact/column';
65
import { SidePanelPage } from '../components/sidePanelPage';
@@ -9,37 +8,48 @@ import { ScreensMapping } from './screenConfig';
98
import { Button } from 'primereact/button';
109
import { isoStringToReadable, openExternalLink } from '../src/non-component-sharing';
1110
import { Panel } from 'primereact/panel';
11+
import { gitProfileActions } from '../store/slices/gitProfileSlice';
1212

1313
export const AddedKeysList = () => {
14-
let { userList } = useSelector(st => st.sshKeys);
14+
let { profiles } = useSelector(st => st.gitProfile);
1515
const dispatch = useDispatch();
1616

1717
const detailsButton = (user) => {
18-
let { gitUserName, AddedAt: addedAt } = user;
18+
let { gitUserName, addedAt } = user;
1919
return <Button icon='pi pi-chevron-right' outlined rounded size='small'
2020
title='Detail page'
2121
onClick={() => dispatch(globalStuffActions.setScreen({ screen: ScreensMapping.accountDetails, extra: { gitUserName, addedAt } }))}
2222
/>
2323
}
2424

2525
const getReadbleDate = useCallback(user => {
26-
const { AddedAt } = user; // this is ISO string;
27-
return isoStringToReadable(AddedAt);
26+
const { addedAt } = user; // this is ISO string;
27+
return isoStringToReadable(addedAt);
2828
}, []);
2929

3030
const githubLink = useCallback(user => {
31-
let { gitUserName } = user;
32-
return <a title='open profile in browser' href='#' onClick={() => openExternalLink(`https://github.com/${gitUserName}`)}>Github.com/{gitUserName}</a>
31+
let { gitUserName, profileLink } = user;
32+
return <a title='open profile in browser' href='#' onClick={() => openExternalLink(profileLink)}>{gitUserName}</a>
3333
}, [])
3434

35+
const connectionTested = useCallback(user => {
36+
let { connectionTested } = user;
37+
return connectionTested ? 'Yes' : 'No'
38+
}, [])
39+
40+
41+
useEffect(() => {
42+
dispatch(gitProfileActions.loadProfileAndSSHConfig());
43+
}, []);
44+
3545
return <>
3646
<SidePanelPage screenTitle="Following Keys are added">
3747
<div className="side-panel-center">
3848
<Panel header='Added Git Account'>
39-
<DataTable value={userList}>
40-
<Column header="Git Name" field="gitUserName" ></Column>
41-
<Column header="Github Profile" body={githubLink} ></Column>
49+
<DataTable value={profiles}>
50+
<Column header="Git Profile" body={githubLink} ></Column>
4251
<Column header="Added At" body={getReadbleDate}></Column>
52+
<Column header="Connection Tested" body={connectionTested}></Column>
4353
<Column header='' body={detailsButton}></Column>
4454
</DataTable>
4555
</Panel>

web-app/screens/dashboard.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { useSelector } from 'react-redux';
44
import { SidePanelPage } from '../components/sidePanelPage';
55

66
export const Dashboard = () => {
7-
let { userList } = useSelector(st => st.sshKeys);
7+
let { sshConfig } = useSelector(st => st.gitProfile);
88
return <>
99
<SidePanelPage screenTitle="Dashboard">
1010
<div className="side-panel-center">
1111
<Panel header="Panel Heading">
12-
<p>
13-
We have {userList.length} keys configured.
14-
</p>
12+
<pre>
13+
{JSON.stringify(sshConfig, null, " ")}
14+
</pre>
1515
</Panel>
1616
</div>
1717
</SidePanelPage>

0 commit comments

Comments
 (0)