Skip to content

Commit a0f3423

Browse files
committed
checkboxes in simple staging now have correct appearance
stil don't actually do anything
1 parent 4ea7029 commit a0f3423

File tree

7 files changed

+114
-41
lines changed

7 files changed

+114
-41
lines changed

src/components/FileItemSimple.tsx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { Dialog, showDialog } from '@jupyterlab/apputils';
22
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
33
import * as React from 'react';
44
import { classes } from 'typestyle';
5-
import { GitExtension } from '../model';
5+
import { BranchMarker, GitExtension } from '../model';
66
import {
77
fileButtonStyle,
88
fileGitButtonStyle,
99
fileIconStyle,
1010
fileLabelStyle,
1111
fileStyle
1212
} from '../style/FileItemStyle';
13+
import { gitMarkBoxStyle } from '../style/FileItemSimpleStyle';
1314
import {
1415
changeStageButtonStyle,
1516
diffFileButtonStyle,
@@ -21,19 +22,51 @@ import { isDiffSupported } from './diff/Diff';
2122
import { openDiffView } from './diff/DiffWidget';
2223
import { ISpecialRef } from './diff/model';
2324

25+
export interface IGitMarkBoxProps {
26+
fname: string;
27+
stage: string;
28+
marker: BranchMarker;
29+
}
30+
31+
export class GitMarkBox extends React.Component<IGitMarkBoxProps> {
32+
constructor(props: IGitMarkBoxProps) {
33+
super(props);
34+
35+
this._onClick = this._onClick.bind(this);
36+
}
37+
38+
protected _onClick(event: React.ChangeEvent<HTMLInputElement>) {
39+
this.props.marker.toggle(this.props.fname);
40+
console.log(this.props.marker);
41+
this.forceUpdate();
42+
}
43+
44+
render() {
45+
// idempotent, will only run once per file
46+
this.props.marker.add(this.props.fname, this.props.stage !== 'untracked');
47+
48+
return (
49+
<input
50+
name="gitMark"
51+
className={gitMarkBoxStyle}
52+
type="checkbox"
53+
checked={this.props.marker.get(this.props.fname)}
54+
onChange={this._onClick}
55+
/>
56+
);
57+
}
58+
}
59+
2460
export interface IFileItemSimpleProps {
2561
file: Git.IStatusFileResult;
2662
stage: string;
63+
marker: BranchMarker;
2764
model: GitExtension;
2865
discardFile: (file: string) => Promise<void>;
2966
renderMime: IRenderMimeRegistry;
3067
}
3168

32-
export class FileItemSimple extends React.Component<IFileItemSimpleProps, {}> {
33-
constructor(props: IFileItemSimpleProps) {
34-
super(props);
35-
}
36-
69+
export class FileItemSimple extends React.Component<IFileItemSimpleProps> {
3770
getDiffFileIconClass() {
3871
return classes(
3972
fileButtonStyle,
@@ -73,6 +106,11 @@ export class FileItemSimple extends React.Component<IFileItemSimpleProps, {}> {
73106
render() {
74107
return (
75108
<li className={fileStyle}>
109+
<GitMarkBox
110+
marker={this.props.marker}
111+
stage={this.props.stage}
112+
fname={this.props.file.to}
113+
/>
76114
<span
77115
className={classes(
78116
fileIconStyle,
@@ -93,7 +131,7 @@ export class FileItemSimple extends React.Component<IFileItemSimpleProps, {}> {
93131
>
94132
{this.props.file.to}
95133
</span>
96-
{this.props.stage === 'Changed' && (
134+
{this.props.stage === 'unstaged' && (
97135
<React.Fragment>
98136
<button
99137
className={`jp-Git-button ${this.getDiscardFileIconClass()}`}
@@ -106,7 +144,7 @@ export class FileItemSimple extends React.Component<IFileItemSimpleProps, {}> {
106144
this.diffButton({ specialRef: 'WORKING' })}
107145
</React.Fragment>
108146
)}
109-
{this.props.stage === 'Staged' &&
147+
{this.props.stage === 'staged' &&
110148
isDiffSupported(this.props.file.to) &&
111149
this.diffButton({ specialRef: 'INDEX' })}
112150
</li>

src/components/FileList.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,16 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
484484
/>
485485
);
486486

487-
const allFilesExcludingUnmodified = () =>
488-
this.props.untrackedFiles.concat(
487+
const allFilesExcludingUnmodified = () => {
488+
let files = this.props.untrackedFiles.concat(
489489
this.props.unstagedFiles,
490490
this.props.stagedFiles
491491
);
492492

493+
files.sort((a, b) => a.to.localeCompare(b.to));
494+
return files;
495+
};
496+
493497
return (
494498
<div onContextMenu={event => event.preventDefault()}>
495499
<CommitBox
@@ -501,6 +505,10 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
501505
<GitStageSimple
502506
heading={'Changed'}
503507
files={allFilesExcludingUnmodified()}
508+
marker={this.props.model.getMarker(
509+
this.props.model.pathRepository,
510+
''
511+
)}
504512
model={this.props.model}
505513
discardAllFiles={this.discardAllChanges}
506514
discardFile={this.discardChanges}

src/components/GitPanel.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ISettingRegistry } from '@jupyterlab/coreutils';
22
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
33
import * as React from 'react';
4-
import { GitExtension, BranchMarker } from '../model';
4+
import { GitExtension } from '../model';
55
import {
66
findRepoButtonStyle,
77
panelContainerStyle,
88
panelWarningStyle
99
} from '../style/GitPanelStyle';
1010
import { Git } from '../tokens';
11+
import { decodeStage } from '../utils';
1112
import { BranchHeader } from './BranchHeader';
1213
import { FileList } from './FileList';
1314
import { HistorySideBar } from './HistorySideBar';
@@ -28,8 +29,6 @@ export interface IGitSessionNodeState {
2829
untrackedFiles: Git.IStatusFileResult[];
2930
hasChangedFiles: boolean;
3031

31-
marker: BranchMarker;
32-
3332
isHistoryVisible: boolean;
3433
}
3534

@@ -57,7 +56,6 @@ export class GitPanel extends React.Component<
5756
stagedFiles: [],
5857
unstagedFiles: [],
5958
untrackedFiles: [],
60-
marker: null,
6159
isHistoryVisible: false
6260
};
6361

@@ -99,14 +97,15 @@ export class GitPanel extends React.Component<
9997
}
10098
}
10199

100+
this.props.model.getMarker(
101+
this.props.model.pathRepository,
102+
currentBranch
103+
);
104+
102105
this.setState({
103106
branches: branchData.branches,
104107
currentBranch: currentBranch,
105-
upstreamBranch: upstreamBranch,
106-
marker: this.props.model.getMarker(
107-
this.props.model.pathRepository,
108-
currentBranch
109-
)
108+
upstreamBranch: upstreamBranch
110109
});
111110
}
112111
};
@@ -138,32 +137,26 @@ export class GitPanel extends React.Component<
138137
let statusFiles = this.props.model.status;
139138
if (statusFiles.length > 0) {
140139
for (let i = 0; i < statusFiles.length; i++) {
140+
const file = statusFiles[i];
141+
const { x, y } = file;
142+
const stage = decodeStage(x, y);
143+
141144
// If file has been changed
142-
if (statusFiles[i].x !== '?' && statusFiles[i].x !== '!') {
145+
if (x !== '?' && x !== '!') {
143146
changedFiles++;
144147
}
148+
145149
// If file is untracked
146-
if (statusFiles[i].x === '?' && statusFiles[i].y === '?') {
147-
untrackedFiles.push(statusFiles[i]);
148-
} else {
149-
// If file is staged
150-
if (statusFiles[i].x !== ' ' && statusFiles[i].y !== 'D') {
151-
stagedFiles.push(statusFiles[i]);
152-
}
153-
// If file is unstaged but tracked
154-
if (statusFiles[i].y !== ' ') {
155-
unstagedFiles.push(statusFiles[i]);
156-
}
150+
if (stage === 'untracked') {
151+
untrackedFiles.push(file);
152+
} else if (stage === 'unstaged') {
153+
unstagedFiles.push(file);
154+
} else if (stage === 'staged') {
155+
stagedFiles.push(file);
157156
}
158157
}
159158
}
160159

161-
this.state.marker.addMarked(
162-
...stagedFiles.map(x => x.to),
163-
...unstagedFiles.map(x => x.to)
164-
);
165-
this.state.marker.addUnmarked(...untrackedFiles.map(x => x.to));
166-
167160
this.setState({
168161
stagedFiles: stagedFiles,
169162
unstagedFiles: unstagedFiles,

src/components/GitStageSimple.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Dialog, showDialog } from '@jupyterlab/apputils';
22
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
33
import * as React from 'react';
44
import { classes } from 'typestyle';
5-
import { GitExtension } from '../model';
5+
import { BranchMarker, GitExtension } from '../model';
66
import {
77
changeStageButtonStyle,
88
discardFileButtonStyle,
@@ -12,10 +12,12 @@ import {
1212
} from '../style/GitStageStyle';
1313
import { Git } from '../tokens';
1414
import { FileItemSimple } from './FileItemSimple';
15+
import { decodeStage } from '../utils';
1516

1617
export interface IGitStageSimpleProps {
1718
heading: string;
1819
files: Git.IStatusFileResult[];
20+
marker: BranchMarker;
1921
model: GitExtension;
2022
discardAllFiles: () => Promise<void>;
2123
discardFile: (file: string) => Promise<void>;
@@ -80,7 +82,8 @@ export class GitStageSimple extends React.Component<IGitStageSimpleProps> {
8082
<FileItemSimple
8183
key={fileIndex}
8284
file={file}
83-
stage={this.props.heading}
85+
stage={decodeStage(file.x, file.y)}
86+
marker={this.props.marker}
8487
model={this.props.model}
8588
discardFile={this.props.discardFile}
8689
renderMime={this.props.renderMime}

src/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,17 +879,21 @@ export class BranchMarker {
879879
}
880880

881881
addMarked(...fnames: string[]) {
882-
for (let fname in fnames) {
882+
for (let fname of fnames) {
883883
this.add(fname, true);
884884
}
885885
}
886886

887887
addUnmarked(...fnames: string[]) {
888-
for (let fname in fnames) {
888+
for (let fname of fnames) {
889889
this.add(fname, false);
890890
}
891891
}
892892

893+
get(fname: string) {
894+
return this._marks[fname];
895+
}
896+
893897
mark(fname: string) {
894898
this._marks[fname] = true;
895899
}

src/style/FileItemSimpleStyle.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { style } from 'typestyle';
2+
import { NestedCSSProperties } from 'typestyle/lib/types';
3+
4+
export const gitMarkBoxCss: NestedCSSProperties = {
5+
flex: '0 0 auto',
6+
margin: 'auto 8px auto 4px'
7+
};
8+
9+
export const gitMarkBoxStyle = style(gitMarkBoxCss);

src/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ export function extractFilename(path: string): string {
3131
}
3232
}
3333

34+
export function decodeStage(x: string, y: string) {
35+
// If file is untracked
36+
if (x === '?' && y === '?') {
37+
return 'untracked';
38+
} else {
39+
// If file is staged
40+
if (x !== ' ' && y !== 'D') {
41+
return 'staged';
42+
}
43+
// If file is unstaged but tracked
44+
if (y !== ' ') {
45+
return 'unstaged';
46+
}
47+
}
48+
49+
return undefined;
50+
}
51+
3452
/** Open a file in the git listing */
3553
export async function openListedFile(
3654
typeX: string,

0 commit comments

Comments
 (0)