Skip to content

Commit bae9b3f

Browse files
committed
Initial prototype of MergePickerDialog
1 parent fe252a7 commit bae9b3f

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

src/components/BranchStatusComponent.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useBranchStatus } from '../store/hooks/useBranchStatus';
77
const BranchComponent: React.FunctionComponent<{ repo: UUID, branch: string }> = props => {
88
const { cards, modified, status } = useBranchStatus(props.repo, props.branch);
99

10-
1110
return (
1211
<TreeItem nodeId={`${props.repo}-${props.branch}`} label={`${props.branch} [${modified.length}/${cards.length}]`} onClick={() => cards.map(async c => await status(c))} />
1312
);

src/components/MergePickerDialog.tsx

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,72 @@
1-
import React, { useState } from 'react';
2-
import { Button, Dialog } from '@material-ui/core';
1+
import React, { useEffect, useState } from 'react';
2+
import { Button, Dialog, DialogTitle, FormControl, Input, InputLabel, ListSubheader, MenuItem, Select } from '@material-ui/core';
33

4-
import { UUID } from '../types';
4+
import { Repository, UUID } from '../types';
5+
import { useSelector } from 'react-redux';
6+
import { RootState } from '../store/root';
7+
import { useBranchStatus } from '../store/hooks/useBranchStatus';
58

69
type DialogProps = {
710
open: boolean;
8-
options: string[];
11+
repos: Repository[];
912
onClose: (canceled: boolean, selected: [UUID, UUID]) => void;
1013
}
1114

1215
export const MergePickerDialog: React.FunctionComponent<DialogProps> = props => {
13-
const [selectedLeft] = useState('');
14-
const [selectedRight] = useState('');
16+
const [base, setBase] = useState<{ repo: UUID, branch: string }>({ repo: '', branch: '' });
17+
const [compare, setCompare] = useState<{ repo: UUID, branch: string }>({ repo: '', branch: '' });
18+
const baseStatus = useBranchStatus(base.repo, base.branch);
19+
const compareStatus = useBranchStatus(compare.repo, compare.branch);
20+
21+
useEffect(() => {
22+
if (base.repo !== '' && compare.repo !== '') console.log(`ready to analyze...`);
23+
}, [base, compare]);
24+
25+
const setSelected = (target: 'base' | 'compare', value: string) => {
26+
const repoBranch = { repo: value.split('/')[0], branch: value.split('/')[1] };
27+
(target === 'base') ? setBase(repoBranch) : setCompare(repoBranch);
28+
};
29+
30+
const analyze = () => {
31+
console.log(`base: ${base?.repo}/${base?.branch} (cards: ${baseStatus.cards.length}, modified: ${baseStatus.modified.length})`);
32+
console.log(`compare: ${compare?.repo}/${compare?.branch} (cards: ${compareStatus.cards.length}, modified: ${compareStatus.modified.length})`);
33+
};
1534

1635
return (
1736
<Dialog id='picker-dialog' open={props.open} onClose={() => props.onClose(false, ['', ''])}>
18-
<div>selectLeft: {selectedLeft}</div>
19-
<div>selectRight: {selectedRight}</div>
37+
<div className='diff-container'>
38+
<DialogTitle style={{ gridArea: 'header' }}>Select branches to compare</DialogTitle>
39+
<FormControl aria-label='Left Form' style={{ gridArea: 'left', width: 100 }}>
40+
<InputLabel htmlFor='merge-select-left' id='merge-select-left-label'>Base</InputLabel>
41+
<Select id='merge-select-left' aria-labelledby='merge-select-left-label' value={base.repo !== '' ? `${base?.repo}/${base?.branch}` : ''}
42+
autoWidth={true} onChange={(e) => setSelected('base', e.target.value as string)} input={<Input />}>
43+
<MenuItem value=''><em>None</em></MenuItem>
44+
{props.repos.map(repo => [
45+
<ListSubheader key={`${repo.id}-subheader`}>{repo.name}</ListSubheader>,
46+
...(repo.local.map(branch => <MenuItem key={`${repo.id}/${branch}`} value={`${repo.id}/${branch}`}>{branch}</MenuItem>))
47+
])}
48+
</Select>
49+
</FormControl>
50+
<FormControl aria-label='Right Form' style={{ gridArea: 'right', width: 100 }}>
51+
<InputLabel htmlFor='merge-select-right' id='merge-select-right-label'>Compare</InputLabel>
52+
<Select id='merge-select-right' aria-labelledby='merge-select-right-label' value={compare.repo !== '' ? `${compare?.repo}/${compare?.branch}` : ''}
53+
autoWidth={true} onChange={(e) => setSelected('compare', e.target.value as string)} input={<Input />}>
54+
<MenuItem value=''><em>None</em></MenuItem>
55+
{props.repos.map(repo => [
56+
<ListSubheader key={`${repo.id}-subheader`}>{repo.name}</ListSubheader>,
57+
...(repo.local.map(branch => <MenuItem key={`${repo.id}/${branch}`} value={`${repo.id}/${branch}`}>{branch}</MenuItem>))
58+
])}
59+
</Select>
60+
</FormControl>
61+
<button onClick={analyze}>View Selected...</button>
62+
</div>
2063
</Dialog >
2164
);
2265
}
2366

2467
const MergePickerButton: React.FunctionComponent = () => {
2568
const [open, setOpen] = useState(false);
69+
const repos = useSelector((state: RootState) => Object.values(state.repos));
2670

2771
const handleClose = () => {
2872
setOpen(!open);
@@ -31,7 +75,7 @@ const MergePickerButton: React.FunctionComponent = () => {
3175
return (
3276
<>
3377
<Button id='diffpicker-button' variant='contained' color='primary' onClick={() => setOpen(!open)}>Merge Branches...</Button>
34-
<MergePickerDialog open={open} options={['stuff']} onClose={handleClose} />
78+
{open ? <MergePickerDialog open={open} repos={repos} onClose={handleClose} /> : null}
3579
</>
3680
);
3781
}

src/store/selectors/repos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const getCardsByRepo = (repo: UUID, branch?: string) => (state: RootState
55
return Object.values(state.cards)
66
.filter(c => c.metafile !== undefined)
77
.filter(c => state.metafiles[c.metafile] ? (state.metafiles[c.metafile].repo === repo) : false)
8-
.filter(c => branch ? (state.metafiles[c.metafile[0]].branch === branch) : true);
8+
.filter(c => branch ? (state.metafiles[c.metafile].branch === branch) : true);
99
};

0 commit comments

Comments
 (0)