Skip to content

Commit 48189de

Browse files
committed
Link git clone button to file browser path
1 parent 9235b1e commit 48189de

File tree

1 file changed

+60
-13
lines changed

1 file changed

+60
-13
lines changed

Diff for: src/widgets/gitClone.tsx

+60-13
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,18 @@ export function addCloneButton(model: IGitExtension, filebrowser: FileBrowser) {
2020
'gitClone',
2121
ReactWidget.create(
2222
<UseSignal
23-
signal={model.repositoryChanged}
23+
signal={filebrowser.model.pathChanged}
2424
initialArgs={{
25-
name: 'pathRepository',
26-
oldValue: null,
27-
newValue: model.pathRepository
25+
name: 'path',
26+
oldValue: '/',
27+
newValue: filebrowser.model.path
2828
}}
2929
>
30-
{(_, change: IChangedArgs<string | null>) => (
31-
<ToolbarButtonComponent
32-
enabled={change.newValue === null}
33-
iconClassName={`${cloneButtonStyle} jp-Icon jp-Icon-16`}
34-
onClick={async () => {
35-
await doGitClone(model, filebrowser.model.path);
36-
filebrowser.model.refresh();
37-
}}
38-
tooltip={'Git Clone'}
30+
{(_, change: IChangedArgs<string>) => (
31+
<GitCloneButton
32+
model={model}
33+
filebrowser={filebrowser}
34+
change={change}
3935
/>
4036
)}
4137
</UseSignal>
@@ -151,3 +147,54 @@ class GitCloneForm extends Widget {
151147
return encodeURIComponent(this.node.querySelector('input').value);
152148
}
153149
}
150+
151+
/**
152+
* Git clone toolbar button properties
153+
*/
154+
interface IGitCloneButtonProps {
155+
/**
156+
* Git extension model
157+
*/
158+
model: IGitExtension;
159+
/**
160+
* File browser object
161+
*/
162+
filebrowser: FileBrowser;
163+
/**
164+
* File browser path change
165+
*/
166+
change: IChangedArgs<string>;
167+
}
168+
169+
const GitCloneButton: React.FunctionComponent<IGitCloneButtonProps> = (
170+
props: IGitCloneButtonProps
171+
) => {
172+
const [enable, setEnable] = React.useState(false);
173+
174+
React.useEffect(() => {
175+
model
176+
.showTopLevel(change.newValue)
177+
.then(answer => {
178+
setEnable(answer.code !== 0);
179+
})
180+
.catch(reason => {
181+
console.error(
182+
`Fail to get the top level path for ${change.newValue}.\n${reason}`
183+
);
184+
});
185+
});
186+
187+
const { model, filebrowser, change } = props;
188+
189+
return (
190+
<ToolbarButtonComponent
191+
enabled={enable}
192+
iconClassName={`${cloneButtonStyle} jp-Icon jp-Icon-16`}
193+
onClick={async () => {
194+
await doGitClone(model, filebrowser.model.path);
195+
filebrowser.model.refresh();
196+
}}
197+
tooltip={'Git Clone'}
198+
/>
199+
);
200+
};

0 commit comments

Comments
 (0)