-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from dolthub/liuliu/add-remote
Graphql, Web: Add and delete remote
- Loading branch information
Showing
27 changed files
with
568 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...enderer/components/pageComponents/DatabasePage/ForRemotes/AddRemotePage/AddRemoteForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
Button, | ||
ButtonsWithError, | ||
FormInput, | ||
Loader, | ||
} from "@dolthub/react-components"; | ||
import { useReactiveWidth } from "@dolthub/react-hooks"; | ||
import { useAddRemoteMutation } from "@gen/graphql-types"; | ||
import useMutation from "@hooks/useMutation"; | ||
import { DatabaseParams } from "@lib/params"; | ||
import { refetchBranchQueries } from "@lib/refetchQueries"; | ||
import { remotes } from "@lib/urls"; | ||
import { useRouter } from "next/router"; | ||
import { SyntheticEvent, useState } from "react"; | ||
import css from "./index.module.css"; | ||
|
||
type Props = { | ||
params: DatabaseParams; | ||
}; | ||
|
||
export default function AddRemoteForm(props: Props): JSX.Element { | ||
const router = useRouter(); | ||
const [remoteName, setRemoteName] = useState(""); | ||
const [remoteUrl, setRemoteUrl] = useState(""); | ||
const { | ||
mutateFn: addRemote, | ||
err, | ||
loading, | ||
} = useMutation({ | ||
hook: useAddRemoteMutation, | ||
refetchQueries: refetchBranchQueries(props.params), | ||
}); | ||
const { isMobile } = useReactiveWidth(); | ||
|
||
const goToRemotesPage = () => { | ||
const { href, as } = remotes(props.params); | ||
router.push(href, as).catch(() => {}); | ||
}; | ||
|
||
const onSubmit = async (e: SyntheticEvent) => { | ||
e.preventDefault(); | ||
if (!remoteName || !remoteUrl) return; | ||
|
||
const { data } = await addRemote({ | ||
variables: { ...props.params, remoteName, remoteUrl }, | ||
}); | ||
if (!data) return; | ||
const { href, as } = remotes(props.params); | ||
router.push(href, as).catch(console.error); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={onSubmit}> | ||
<div className={css.remoteForm}> | ||
<FormInput | ||
value={remoteName} | ||
onChangeString={setRemoteName} | ||
label="Add remote name" | ||
placeholder="i.e. origin" | ||
className={css.input} | ||
/> | ||
<FormInput | ||
value={remoteUrl} | ||
onChangeString={setRemoteUrl} | ||
label="Add remote url" | ||
className={css.input} | ||
/> | ||
<ButtonsWithError | ||
onCancel={goToRemotesPage} | ||
left | ||
stackedButton={isMobile} | ||
error={err} | ||
> | ||
<Button type="submit" disabled={!remoteName || !remoteUrl}> | ||
Add remote | ||
</Button> | ||
</ButtonsWithError> | ||
</div> | ||
<Loader loaded={!loading} /> | ||
</form> | ||
</div> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
...renderer/components/pageComponents/DatabasePage/ForRemotes/AddRemotePage/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.container { | ||
@apply m-6; | ||
} | ||
|
||
.remoteForm { | ||
@apply max-w-2xl mx-auto; | ||
} | ||
|
||
.input { | ||
@apply mt-4 px-0; | ||
input { | ||
@apply text-sm rounded bg-stone-50 border border-stone-100; | ||
|
||
&:focus { | ||
@apply bg-white; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
web/renderer/components/pageComponents/DatabasePage/ForRemotes/AddRemotePage/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DatabaseParams } from "@lib/params"; | ||
import AddRemoteForm from "./AddRemoteForm"; | ||
import css from "./index.module.css"; | ||
|
||
type Props = { | ||
params: DatabaseParams; | ||
}; | ||
|
||
export default function AddRemotePage(props: Props): JSX.Element { | ||
return ( | ||
<div className={css.container}> | ||
<h1>Add Remote</h1> | ||
<AddRemoteForm {...props} /> | ||
</div> | ||
); | ||
} |
22 changes: 0 additions & 22 deletions
22
web/renderer/components/pageComponents/DatabasePage/ForRemotes/RemoteRow.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.