-
-
Notifications
You must be signed in to change notification settings - Fork 9
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: added connections and databases selector, changed theme color #302
Changes from 43 commits
c5fd504
0c61823
8a51cbb
d8272a2
e10306e
bb7938e
b1b57c5
68696d9
f65f9d9
74024a1
b20259b
bd50529
a30dc4a
c0625dc
dce6e2e
65411ec
4d108ba
9f5d54a
cbb0254
498749d
9c5b32f
e3196ff
7d08936
55d76a3
488af3f
76bb6d3
bfc9566
2b7418b
c522458
7a8dbc1
2ba37df
af12a83
c4362ea
eadfde7
a1ca0ad
7fbe51b
1a5c3b0
c5abb76
6f92205
f4b758e
26af6ad
8d84e7c
50d72fb
977d422
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
DatabaseConnection, | ||
DatabaseConnectionFragment, | ||
} from "@gen/graphql-types"; | ||
import { MdRemoveRedEye } from "@react-icons/all-files/md/MdRemoveRedEye"; | ||
import { FaChevronRight } from "@react-icons/all-files/fa/FaChevronRight"; | ||
import { Button } from "@dolthub/react-components"; | ||
import { excerpt } from "@dolthub/web-utils"; | ||
import cx from "classnames"; | ||
import { StateType } from "./useSelectedConnection"; | ||
import { DatabaseTypeLabel } from "./DatabaseTypeLabel"; | ||
import css from "./index.module.css"; | ||
|
||
type Props = { | ||
conn: DatabaseConnectionFragment; | ||
state: StateType; | ||
onSelected: (conn: DatabaseConnection) => void; | ||
currentConnection: DatabaseConnection; | ||
}; | ||
export default function ConnectionItem({ | ||
conn, | ||
state, | ||
onSelected, | ||
currentConnection, | ||
}: Props) { | ||
return ( | ||
<Button.Link | ||
key={conn.name} | ||
className={cx(css.connection, { | ||
[css.selected]: state.connection.name === conn.name, | ||
})} | ||
onClick={async () => onSelected(conn)} | ||
> | ||
<div className={css.connectionTop}> | ||
<div className={css.nameAndLabel}> | ||
<span className={css.connectionName}>{excerpt(conn.name, 16)}</span> | ||
<DatabaseTypeLabel conn={conn} /> | ||
{conn.name === currentConnection.name && ( | ||
<MdRemoveRedEye className={css.viewing} /> | ||
)} | ||
</div> | ||
<FaChevronRight className={css.arrow} /> | ||
</div> | ||
<div className={css.connectionUrl}> | ||
{excerpt(getHostAndPort(conn.connectionUrl), 42)} | ||
</div> | ||
</Button.Link> | ||
); | ||
} | ||
|
||
function getHostAndPort(connectionString: string) { | ||
const url = new URL(connectionString); | ||
return `${url.hostname}:${url.port}`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Button, ErrorMsg, Loader } from "@dolthub/react-components"; | ||
import { MdRemoveRedEye } from "@react-icons/all-files/md/MdRemoveRedEye"; | ||
import { | ||
DatabaseConnectionFragment, | ||
DatabaseType, | ||
useAddDatabaseConnectionMutation, | ||
useResetDatabaseMutation, | ||
} from "@gen/graphql-types"; | ||
import useMutation from "@hooks/useMutation"; | ||
import { useRouter } from "next/router"; | ||
import { maybeDatabase } from "@lib/urls"; | ||
import { excerpt } from "@dolthub/web-utils"; | ||
import cx from "classnames"; | ||
import css from "./index.module.css"; | ||
|
||
type Props = { | ||
db: string; | ||
conn: DatabaseConnectionFragment; | ||
currentConnection: DatabaseConnectionFragment; | ||
currentDatabase: string; | ||
}; | ||
|
||
export default function DatabaseItem({ | ||
db, | ||
conn, | ||
currentConnection, | ||
currentDatabase, | ||
}: Props) { | ||
const { | ||
mutateFn: resetDB, | ||
loading, | ||
err, | ||
} = useMutation({ | ||
hook: useResetDatabaseMutation, | ||
}); | ||
const router = useRouter(); | ||
const [addDb, res] = useAddDatabaseConnectionMutation(); | ||
|
||
const onClick = async (databaseName: string) => { | ||
const addedDb = await addDb({ variables: conn }); | ||
await res.client.clearStore(); | ||
if (!addedDb.data) { | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
if (conn.type === DatabaseType.Postgres) { | ||
await resetDB({ variables: { newDatabase: databaseName } }); | ||
} | ||
const { href, as } = maybeDatabase(databaseName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
router.push(href, as).catch(console.error); | ||
}; | ||
|
||
if (loading) { | ||
return <Loader loaded={!loading} />; | ||
} | ||
|
||
if (err) { | ||
return <ErrorMsg err={err} />; | ||
} | ||
const dbName = excerpt(db, 32); | ||
if (db === currentDatabase && conn.name === currentConnection.name) { | ||
return ( | ||
<span className={css.dbItem}> | ||
{dbName} | ||
<MdRemoveRedEye className={css.viewing} /> | ||
</span> | ||
); | ||
} | ||
return ( | ||
<Button.Link | ||
className={cx(css.dbItem, css.link)} | ||
onClick={async () => onClick(db)} | ||
> | ||
{dbName} | ||
</Button.Link> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getDatabaseType } from "@components/DatabaseTypeLabel"; | ||
import { DatabaseConnectionFragment } from "@gen/graphql-types"; | ||
import css from "./index.module.css"; | ||
|
||
type Props = { | ||
conn: DatabaseConnectionFragment; | ||
}; | ||
|
||
export function DatabaseTypeLabel({ conn }: Props) { | ||
const type = getDatabaseType(conn.type ?? undefined, !!conn.isDolt); | ||
switch (type) { | ||
case "Dolt": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it's a string returned from |
||
return ( | ||
<span className={css.label}> | ||
<img src="/images/dolt-logo.png" alt="Dolt" /> | ||
</span> | ||
); | ||
case "MySQL": | ||
return ( | ||
<span className={css.label}> | ||
<img src="/images/mysql-logo.png" alt="MySQL" /> | ||
</span> | ||
); | ||
case "PostgreSQL": | ||
return ( | ||
<span className={css.label}> | ||
<img src="/images/postgres-logo.png" alt="PostgreSQL" /> | ||
</span> | ||
); | ||
case "DoltgreSQL": | ||
return ( | ||
<span className={css.label}> | ||
<img src="/images/doltgres-logo.png" alt="DoltgreSQL" /> | ||
</span> | ||
); | ||
default: | ||
return <span className={css.label}>{type}</span>; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { DatabaseConnection, DatabaseType } from "@gen/graphql-types"; | ||
import { DatabaseParams } from "@lib/params"; | ||
import cx from "classnames"; | ||
import Link from "@components/links/Link"; | ||
import { ErrorMsg, SmallLoader } from "@dolthub/react-components"; | ||
import CreateDatabase from "@components/CreateDatabase"; | ||
import { FiTool } from "@react-icons/all-files/fi/FiTool"; | ||
import { StateType } from "./useSelectedConnection"; | ||
import DatabaseItem from "./DatabaseItem"; | ||
import css from "./index.module.css"; | ||
import ConnectionItem from "./ConnectionItem"; | ||
|
||
type Props = { | ||
params: DatabaseParams; | ||
currentConnection: DatabaseConnection; | ||
onSelected: (conn: DatabaseConnection) => void; | ||
storedConnections: DatabaseConnection[]; | ||
state: StateType; | ||
}; | ||
|
||
export default function Popup({ | ||
params, | ||
currentConnection, | ||
onSelected, | ||
storedConnections, | ||
state, | ||
}: Props) { | ||
return ( | ||
<div className={css.container}> | ||
<div className={css.top}> | ||
<div className={cx(css.header, css.left)}> | ||
<span>CONNECTIONS</span> | ||
<Link href="/connections"> | ||
<FiTool className={css.wrench} /> | ||
</Link> | ||
</div> | ||
<div className={cx(css.header, css.right)}> | ||
<span>DATABASES</span> | ||
<CreateDatabase | ||
isPostgres={currentConnection.type === DatabaseType.Postgres} | ||
/> | ||
</div> | ||
</div> | ||
<div className={css.middle}> | ||
<div className={css.left}> | ||
{storedConnections.map(conn => ( | ||
<ConnectionItem | ||
key={conn.name} | ||
conn={conn} | ||
currentConnection={currentConnection} | ||
onSelected={onSelected} | ||
state={state} | ||
/> | ||
))} | ||
</div> | ||
<div className={css.right}> | ||
{state.loading && <SmallLoader loaded={!state.loading} />} | ||
{state.databases.map(db => ( | ||
<DatabaseItem | ||
key={db} | ||
db={db} | ||
conn={state.connection} | ||
currentConnection={currentConnection} | ||
currentDatabase={params.databaseName} | ||
/> | ||
))} | ||
<ErrorMsg err={state.err} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to pass the whole
state
? Seems like you only needconnection
(which could use a clearer name to distinguish fromconn
)?