Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web: UI for different remote types #329

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { getDatabaseType } from "@components/DatabaseTypeLabel";
import DoltLink from "@components/links/DoltLink";
import DoltgresLink from "@components/links/DoltgresLink";
import css from "./index.module.css";
import Radios, { RemoteType } from "./Radios";
import RemoteUrl from "./RemoteUrl";

type Props = {
params: DatabaseParams;
Expand All @@ -30,9 +32,7 @@ export default function AddRemoteForm(props: Props): JSX.Element {
const router = useRouter();
const { data: databaseDetails, loading: databaseDetailsLoading } =
useDoltDatabaseDetailsQuery();
const { dbLink, urlPlaceHolder } = getDbNameAndLink(
databaseDetails?.doltDatabaseDetails,
);
const dbLink = getDbNameAndLink(databaseDetails?.doltDatabaseDetails);
const [remoteName, setRemoteName] = useState("");
const [remoteUrl, setRemoteUrl] = useState("");
const {
Expand Down Expand Up @@ -62,6 +62,8 @@ export default function AddRemoteForm(props: Props): JSX.Element {
router.push(href, as).catch(console.error);
};

const [type, setType] = useState(RemoteType.DoltHub);
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<form onSubmit={onSubmit}>
Expand All @@ -73,12 +75,13 @@ export default function AddRemoteForm(props: Props): JSX.Element {
placeholder="i.e. origin"
className={css.input}
/>
<FormInput
value={remoteUrl}
onChangeString={setRemoteUrl}
label="Add remote url"
placeholder={urlPlaceHolder}
className={css.input}
<span className={css.label}>Remote type</span>
<Radios type={type} setType={setType} />
<RemoteUrl
type={type}
remoteUrl={remoteUrl}
setRemoteUrl={setRemoteUrl}
currentDbName={props.params.databaseName}
/>
<ButtonsWithError
onCancel={goToRemotesPage}
Expand All @@ -105,25 +108,16 @@ export default function AddRemoteForm(props: Props): JSX.Element {
);
}

type ReturnType = {
dbLink: JSX.Element;
urlPlaceHolder: string;
};

function getDbNameAndLink(dbDetails?: DoltDatabaseDetails): ReturnType {
function getDbNameAndLink(dbDetails?: DoltDatabaseDetails): JSX.Element {
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
const type = getDatabaseType(
dbDetails?.type ?? undefined,
!!dbDetails?.isDolt,
);
const universalUrl = "i.e. https://url-of-remote.com";
if (type === "Dolt") {
return {
dbLink: <DoltLink />,
urlPlaceHolder: "i.e. https://doltremoteapi.dolthub.com/owner/repo",
};
return <DoltLink />;
}
if (type === "DoltgreSQL") {
return { dbLink: <DoltgresLink />, urlPlaceHolder: universalUrl };
return <DoltgresLink />;
}
return { dbLink: <span>{type}</span>, urlPlaceHolder: universalUrl };
return <span>{type}</span>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Radio } from "@dolthub/react-components";
import css from "./index.module.css";

export enum RemoteType {
DoltHub,
Other,
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
}

type Props = {
type: RemoteType;
setType: (t: RemoteType) => void;
};

export default function Radios(props: Props) {
return (
<div className={css.radios}>
<Radio
name="DoltHub"
checked={props.type === RemoteType.DoltHub}
onChange={() => props.setType(RemoteType.DoltHub)}
label="DoltHub"
/>
<Radio
name="Other"
checked={props.type === RemoteType.Other}
onChange={() => props.setType(RemoteType.Other)}
label="Other"
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { FormInput } from "@dolthub/react-components";
import { useState } from "react";
import { RemoteType } from "./Radios";
import css from "./index.module.css";

type Props = {
type: RemoteType;
remoteUrl: string;
setRemoteUrl: (t: string) => void;
currentDbName: string;
};

export default function RemoteUrl({
type,
remoteUrl,
setRemoteUrl,
currentDbName,
}: Props) {
const [ownerName, setOwnerName] = useState("");
const [dbName, setDbName] = useState(currentDbName);
if (type === RemoteType.Other) {
return (
<FormInput
value={remoteUrl}
onChangeString={setRemoteUrl}
label="Add remote url"
placeholder="i.e. https://url-of-remote.com"
className={css.input}
/>
);
}
return (
<div>
<FormInput
value={ownerName}
onChangeString={(s: string) => {
setOwnerName(s);
setRemoteUrl(`https://doltremoteapi.dolthub.com/${s}/${dbName}`);
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
}}
label="Owner Name"
placeholder="i.e. dolthub"
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
className={css.input}
/>
<FormInput
value={dbName}
onChangeString={(s: string) => {
setDbName(s);
setRemoteUrl(`https://doltremoteapi.dolthub.com/${ownerName}/${s}`);
}}
label="Database Name"
placeholder="i.e. example-db"
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
className={css.input}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
@apply max-w-2xl mx-auto;
}

.label {
@apply text-base font-semibold py-2;
}

.input {
@apply mt-4 px-0;
input {
Expand All @@ -20,3 +24,7 @@
.text {
@apply text-sm text-stone-500 mb-5 max-w-xl mt-4;
}

.radios {
@apply flex justify-between w-72 mt-2;
}