Skip to content

Commit

Permalink
Link git clone button to file browser path
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Jan 3, 2020
1 parent 9235b1e commit 48189de
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions src/widgets/gitClone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@ export function addCloneButton(model: IGitExtension, filebrowser: FileBrowser) {
'gitClone',
ReactWidget.create(
<UseSignal
signal={model.repositoryChanged}
signal={filebrowser.model.pathChanged}
initialArgs={{
name: 'pathRepository',
oldValue: null,
newValue: model.pathRepository
name: 'path',
oldValue: '/',
newValue: filebrowser.model.path
}}
>
{(_, change: IChangedArgs<string | null>) => (
<ToolbarButtonComponent
enabled={change.newValue === null}
iconClassName={`${cloneButtonStyle} jp-Icon jp-Icon-16`}
onClick={async () => {
await doGitClone(model, filebrowser.model.path);
filebrowser.model.refresh();
}}
tooltip={'Git Clone'}
{(_, change: IChangedArgs<string>) => (
<GitCloneButton
model={model}
filebrowser={filebrowser}
change={change}
/>
)}
</UseSignal>
Expand Down Expand Up @@ -151,3 +147,54 @@ class GitCloneForm extends Widget {
return encodeURIComponent(this.node.querySelector('input').value);
}
}

/**
* Git clone toolbar button properties
*/
interface IGitCloneButtonProps {
/**
* Git extension model
*/
model: IGitExtension;
/**
* File browser object
*/
filebrowser: FileBrowser;
/**
* File browser path change
*/
change: IChangedArgs<string>;
}

const GitCloneButton: React.FunctionComponent<IGitCloneButtonProps> = (
props: IGitCloneButtonProps
) => {
const [enable, setEnable] = React.useState(false);

React.useEffect(() => {
model
.showTopLevel(change.newValue)
.then(answer => {
setEnable(answer.code !== 0);
})
.catch(reason => {
console.error(
`Fail to get the top level path for ${change.newValue}.\n${reason}`
);
});
});

const { model, filebrowser, change } = props;

return (
<ToolbarButtonComponent
enabled={enable}
iconClassName={`${cloneButtonStyle} jp-Icon jp-Icon-16`}
onClick={async () => {
await doGitClone(model, filebrowser.model.path);
filebrowser.model.refresh();
}}
tooltip={'Git Clone'}
/>
);
};

0 comments on commit 48189de

Please sign in to comment.