Skip to content

Commit 0630224

Browse files
committed
export functionality complete
1 parent 1c827e0 commit 0630224

File tree

9 files changed

+77
-30
lines changed

9 files changed

+77
-30
lines changed

src/client/components-v2/main/http2-composer/Http2Composer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function Http2Composer(props) {
6262
warningMessage,
6363
} = props;
6464

65-
console.log(newRequestBody)
65+
// console.log(newRequestBody)
6666

6767
const {
6868
gRPC,

src/client/components-v2/navbar/LoginStatus.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ export default function LoginContainer(props) {
7272
flexDirection: 'row',
7373
alignItems: 'center',
7474
}}>
75-
<MoreVertRoundedIcon fontSize='small' onClick={handleSignOut}/>
75+
<Button
76+
sx={{ maxWidth: '24px', maxHeight: '24px', minWidth: '24px', minHeight: '24px' }}
77+
onClick={handleSignOut}
78+
>
79+
<LogoutRoundedIcon fontSize='small' />
80+
</Button>
7681
<StyledBadge
7782
sx={{
7883
m: 1,
@@ -82,7 +87,7 @@ export default function LoginContainer(props) {
8287
variant="dot">
8388
<Avatar alt={session.username} src={session.avatar}/>
8489
</StyledBadge>
85-
<Button variant="outlined">Invite +</Button>
90+
{/* <Button variant="outlined">Invite +</Button> */}
8691
</Box>
8792
:
8893
<Box sx={{

src/client/components-v2/workspace/WorkspaceSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function WorkspaceSelect({ currentWorkspaceId, handleWorkspaceCha
5151
</Select>
5252
<FormHelperText>Current Workspace</FormHelperText>
5353
</FormControl>
54-
<ImportWorkspaceModal open={open} handleClose={handleClose}/>
54+
{/* <ImportWorkspaceModal open={open} handleClose={handleClose}/> */}
5555
</Box>
5656
)
5757
}

src/client/components-v2/workspace/modals/import-export-workspace/ExportToGitHubDialog.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import React from 'react';
2+
// Import controllers
3+
import collectionsController from '../../../../controllers/collectionsController'
24
// Import MUI components
35
import DialogTitle from '@mui/material/DialogTitle';
46
import Dialog from '@mui/material/Dialog';
57
import List from '@mui/material/List';
68
import ListItem from '@mui/material/ListItem';
79
import ListItemText from '@mui/material/ListItemText';
10+
import ListItemButton from '@mui/material/ListItemButton';
11+
812

913
// export interface SimpleDialogProps {
1014
// open: boolean;
1115
// selectedValue: string;
1216
// onClose: (value: string) => void;
1317
// }
1418

15-
export default function ExportToGithubDialog({ allUserRepos, selectedRepo, open, onClose}) {
19+
export default function ExportToGithubDialog({ allUserRepos, workspace, selectedRepo, open, onClose}) {
1620
// const { onClose, selectedValue, open } = props;
1721

1822
const handleClose = () => {
@@ -23,12 +27,29 @@ export default function ExportToGithubDialog({ allUserRepos, selectedRepo, open,
2327
onClose(value);
2428
};
2529

30+
const handleExportToRepo = (repo) => {
31+
console.log('need to export this specific file to this clicked-on repo.')
32+
console.log('workspace to export:', workspace)
33+
console.log('repo metadata:', repo.repository)
34+
collectionsController.exportToGithub(workspace.id, repo.repository.name, repo.sha)
35+
//
36+
}
37+
38+
console.log(
39+
'all user repos:', allUserRepos
40+
)
2641
const repoListItems = []
2742
for (let repo of allUserRepos) {
43+
// console.log('sha', repo.sha);
2844
repoListItems.push(
29-
<ListItem>
30-
<ListItemText primary={repo.repository.full_name} />
31-
</ListItem>
45+
<ListItemButton
46+
key={repo.repository.id}
47+
onClick={() => handleExportToRepo(repo)}
48+
>
49+
<ListItem>
50+
<ListItemText primary={repo.repository.full_name} />
51+
</ListItem>
52+
</ListItemButton>
3253
)
3354
}
3455

src/client/components-v2/workspace/modals/import-export-workspace/ImportExportWorkspaceModal.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
3-
import Backdrop from '@mui/material/Backdrop';
4-
import Box from '@mui/material/Box';
5-
import { Button } from '@mui/material';
3+
import { Box, Button, Backdrop } from '@mui/material';
64
import Modal from '@mui/material/Modal';
75
import Fade from '@mui/material/Fade';
86
import collectionsController from '../../../../controllers/collectionsController';
@@ -30,16 +28,22 @@ import ExportToGithubDialog from './ExportToGitHubDialog';
3028
import DialogTitle from '@mui/material/DialogTitle';
3129
import Dialog from '@mui/material/Dialog';
3230

33-
export default function ImportWorkspaceModal({ open, handleClose }) {
31+
export default function ImportExportWorkspaceModal({ open, handleClose }) {
3432
const [importFromGithubList, setImportFromGithubList] = React.useState(false);
3533
const [exportToLocalFilesList, setExportToLocalFilesList] = React.useState(false);
3634
const [exportToGithubList, setExportToGithubList] = React.useState(false);
3735
const [dialogOpen, setDialogOpen] = React.useState(false);
3836

3937
let files = useLiveQuery(() => db.files.toArray());
40-
console.log(files[0].repository.full_name)
41-
const [selectedRepo, setSelectedRepo] = React.useState("files[0].repository.full_name");
38+
// console.log(files[0].repository.full_name)
39+
let repoToExportTo;
40+
if(files !== undefined) {
41+
files[0].repository.full_name;
42+
} else {
43+
repoToExportTo = '';
44+
}
4245

46+
const [selectedRepo, setSelectedRepo] = React.useState(repoToExportTo);
4347

4448
const handleImportFromGithubClick = () => {
4549
setImportFromGithubList(!importFromGithubList)
@@ -61,10 +65,9 @@ export default function ImportWorkspaceModal({ open, handleClose }) {
6165

6266

6367
const importFileClick = () => {
64-
collectionsController.importCollection(localWorkspaces);
68+
collectionsController.importCollection(localWorkspaces);
6569
}
6670

67-
6871
const importFromGithub = async (owner, repo) => {
6972
const token = await db.auth.toArray();
7073
const octokit = new Octokit({
@@ -96,7 +99,11 @@ export default function ImportWorkspaceModal({ open, handleClose }) {
9699
const owner = file.repository.owner.login;
97100
const repo = file.repository.name;
98101
swellRepositoriesArray.push(
99-
<List component="div" disablePadding>
102+
<List
103+
key={file.repository.id}
104+
component="div"
105+
disablePadding
106+
>
100107
<ListItemButton onClick={() => importFromGithub(owner,repo)} sx={{ pl: 4 }}>
101108
<ListItemText primary={file.repository.full_name} />
102109
</ListItemButton>
@@ -110,7 +117,11 @@ export default function ImportWorkspaceModal({ open, handleClose }) {
110117
if(workspaces !== undefined) {
111118
for (let workspace of workspaces) {
112119
exportDbWorkspacesToFiles.push(
113-
<List component="div" disablePadding>
120+
<List
121+
key={workspace.id}
122+
component="div"
123+
disablePadding
124+
>
114125
<ListItemButton onClick={() => collectionsController.exportToFile(workspace.id)} sx={{ pl: 4 }}>
115126
<ListItemText primary={workspace.name} />
116127
</ListItemButton>
@@ -122,16 +133,25 @@ export default function ImportWorkspaceModal({ open, handleClose }) {
122133
const exportDbWorkspacesToGithub = [];
123134
if(workspaces !== undefined) {
124135
for (let workspace of workspaces) {
136+
// onClick={() => collectionsController.exportToGithub(workspace.id)
125137
exportDbWorkspacesToGithub.push(
126-
<List component="div" disablePadding>
127-
<ListItemButton onClick={() => collectionsController.exportToGithub(workspace.id)} sx={{ pl: 4 }}>
138+
<List
139+
key={workspace.id}
140+
component="div"
141+
disablePadding
142+
>
143+
<ListItemButton sx={{ pl: 4 }} onClick={() => setDialogOpen(true)}>
128144
<ListItemText primary={workspace.name} />
129145
</ListItemButton>
130146
<ExportToGithubDialog
131147
allUserRepos={files}
148+
workspace={workspace}
132149
selectedRepo={selectedRepo}
133150
open={dialogOpen}
134-
onClose={handleClose}
151+
onClose={() => {
152+
setDialogOpen(false);
153+
handleClose();
154+
}}
135155
/>
136156
</List>
137157
)
@@ -216,7 +236,7 @@ export default function ImportWorkspaceModal({ open, handleClose }) {
216236
</ListItemButton>
217237
</ListItem>
218238
<Collapse in={exportToGithubList} timeout="auto" unmountOnExit>
219-
{exportDbWorkspacesToGithub}
239+
{exportDbWorkspacesToGithub}
220240
{/* We want to render a list of clickable workspaces,
221241
derived from the IndexedDB. Upon clicking each workspace,
222242
we want to open a dialog box, allowing the user to choose

src/client/controllers/collectionsController.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ const collectionsController = {
8989
});
9090
},
9191

92-
async exportToGithub(id: string): Promise<void> {
93-
console.log('exportToGithub', id)
92+
async exportToGithub(id: string, repo: string, sha: string): Promise<void> {
93+
// console.log('exportToGithub workspace id:', id)
94+
// console.log('exportToGitHub repo name:', repo)
9495
const token = await db.auth.toArray();
9596
const octokit = new Octokit({
9697
auth: token[0].auth,
9798
})
98-
let repos = await db.repos.toArray()
99+
// let repos = await db.repos.toArray()
99100
let userProfile = await db.profile.toArray()
100101

101102
const toExport = await db.table('collections')
@@ -115,9 +116,11 @@ const collectionsController = {
115116
// make popup, for now hardcoding
116117
const date = Date.now()
117118
console.log(date.toString())
119+
console.log('repo.sha', repo.sha);
118120
const response = await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
121+
sha: sha,
119122
owner: userProfile[0].login,
120-
repo: 'swell-file-does-not-exist',
123+
repo: repo,
121124
path: '.swell',
122125
message: `saving ${toExport.name} @ ${new Date(Date.now()).toString()}`,
123126
committer: {

src/client/controllers/githubController.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const githubController = {
1414
async importFromRepo(): Promise<string> {
1515
// setup authorization
1616
const token = await db.auth.toArray();
17-
// console.log(await db.files.toArray());
1817
const octokit = new Octokit({
1918
auth: token[0].auth,
2019
});
@@ -28,7 +27,6 @@ const githubController = {
2827
path: '.swell',
2928
}
3029
);
31-
// console.log('github import', Buffer.from(response.data.content, 'base64').toString('UTF-8'))
3230
return JSON.parse(
3331
Buffer.from(response.data.content, 'base64').toString('UTF-8')
3432
);
@@ -45,7 +43,6 @@ const githubController = {
4543
withCredentials: true,
4644
headers: { Accept: 'application/json', 'Content-Type': 'text/json' },
4745
});
48-
console.log('getUserData', response);
4946
return response.data;
5047
},
5148

src/client/controllers/historyController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const historyController = {
4040
history: historyGroupsObj[date].sort(
4141
(a: ReqRes, b: ReqRes) => b.createdAt.valueOf() - a.createdAt.valueOf()),
4242
}));
43-
console.log(historyGroupsArr)
43+
// console.log(historyGroupsArr)
4444
store.default.dispatch(actions.getHistory(historyGroupsArr));
4545
} catch {
4646
((err: string) => console.log('Error in getHistory', err))

src/client/db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface Repos {
2323
}
2424

2525
interface Files {
26+
repository: any;
2627
sha: string;
2728
}
2829

0 commit comments

Comments
 (0)