-
Notifications
You must be signed in to change notification settings - Fork 4
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 #22 from vertex-center/feature/choose-database
Data page to configure the default Vertex DBMS
- Loading branch information
Showing
12 changed files
with
244 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@use "../../../styles/colors" | ||
|
||
.tag | ||
margin-right: 16px | ||
color: colors.$green |
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,172 @@ | ||
import Content from "../../../components/Content/Content"; | ||
import { | ||
Button, | ||
Horizontal, | ||
List, | ||
ListActions, | ||
ListDescription, | ||
ListIcon, | ||
ListInfo, | ||
ListItem, | ||
ListTitle, | ||
MaterialIcon, | ||
Paragraph, | ||
Title, | ||
Vertical, | ||
} from "@vertex-center/components"; | ||
import { SiPostgresql, SiSqlite } from "@icons-pack/react-simple-icons"; | ||
import styles from "./SettingsDb.module.sass"; | ||
import Popup from "../../../components/Popup/Popup"; | ||
import { Fragment, useState } from "react"; | ||
import { useDBMS } from "../hooks/useDBMS"; | ||
import Progress, { | ||
ProgressOverlay, | ||
} from "../../../components/Progress/Progress"; | ||
import { APIError } from "../../../components/Error/APIError"; | ||
import { useDBMSMutation } from "../hooks/useDBMSMutation"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
|
||
type DatabaseProps = { | ||
name: string; | ||
icon: JSX.Element; | ||
title: string; | ||
description: string; | ||
installed: boolean; | ||
onMigrate?: (db: string) => void; | ||
hideActions?: boolean; | ||
}; | ||
|
||
function Db(props: Readonly<DatabaseProps>) { | ||
const { | ||
name, | ||
icon, | ||
title, | ||
description, | ||
installed, | ||
onMigrate, | ||
hideActions, | ||
} = props; | ||
|
||
let actions = null; | ||
if (installed) { | ||
actions = ( | ||
<Horizontal className={styles.tag} alignItems="center"> | ||
<MaterialIcon icon="check" /> | ||
Active | ||
</Horizontal> | ||
); | ||
} else if (!hideActions) { | ||
actions = ( | ||
<Button | ||
variant="danger" | ||
rightIcon={<MaterialIcon icon="restart_alt" />} | ||
onClick={() => onMigrate(name)} | ||
> | ||
Migrate | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<ListItem> | ||
<ListIcon>{icon}</ListIcon> | ||
<ListInfo> | ||
<ListTitle>{title}</ListTitle> | ||
<ListDescription>{description}</ListDescription> | ||
</ListInfo> | ||
<ListActions>{actions}</ListActions> | ||
</ListItem> | ||
); | ||
} | ||
|
||
export default function SettingsDb() { | ||
const queryClient = useQueryClient(); | ||
|
||
const [showPopup, setShowPopup] = useState(false); | ||
const [selectedDB, setSelectedDB] = useState<string>(); | ||
|
||
const { dbms, isLoadingDbms, errorDbms } = useDBMS(); | ||
const { migrate, isMigrating, errorMigrate } = useDBMSMutation({ | ||
onMutate: () => { | ||
setShowPopup(false); | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ["admin_db_dbms"], | ||
}); | ||
}, | ||
}); | ||
|
||
const askMigrate = (db: string) => { | ||
setSelectedDB(db); | ||
setShowPopup(true); | ||
}; | ||
|
||
const dismissPopup = () => setShowPopup(false); | ||
|
||
const askMigrateActions = ( | ||
<Fragment> | ||
<Button variant="outlined" onClick={dismissPopup}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="danger" | ||
rightIcon={<MaterialIcon icon="restart_alt" />} | ||
onClick={() => migrate(selectedDB)} | ||
> | ||
Migrate | ||
</Button> | ||
</Fragment> | ||
); | ||
|
||
return ( | ||
<Content> | ||
<Title variant="h2">Database</Title> | ||
<Paragraph> | ||
You can choose between <b>SQLite</b> and <b>Postgres</b> to | ||
store your Vertex data. You don't need to worry about installing | ||
or configuring the database, Vertex will do that for you. | ||
{/*Vertex data can include users, permissions, settings....*/} | ||
</Paragraph> | ||
<ProgressOverlay show={isLoadingDbms} /> | ||
<APIError error={errorDbms || errorMigrate} /> | ||
<List> | ||
<Db | ||
name="sqlite" | ||
icon={<SiSqlite />} | ||
title="SQLite" | ||
description="Recommended for small setups." | ||
installed={dbms === "sqlite"} | ||
onMigrate={askMigrate} | ||
hideActions={isMigrating || isLoadingDbms} | ||
/> | ||
<Db | ||
name="postgres" | ||
icon={<SiPostgresql />} | ||
title="Postgres" | ||
description="Recommended for larger installations." | ||
installed={dbms === "postgres"} | ||
onMigrate={askMigrate} | ||
hideActions={isMigrating || isLoadingDbms} | ||
/> | ||
</List> | ||
{isMigrating && ( | ||
<Vertical gap={12}> | ||
<Paragraph>Migration to {selectedDB} ongoing...</Paragraph> | ||
<Progress infinite /> | ||
</Vertical> | ||
)} | ||
<Popup | ||
show={showPopup} | ||
onDismiss={dismissPopup} | ||
title="Migrate database?" | ||
actions={askMigrateActions} | ||
> | ||
<Paragraph> | ||
Are you sure you want to migrate from {dbms} to {selectedDB} | ||
? | ||
</Paragraph> | ||
</Popup> | ||
</Content> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { api } from "../../../backend/api/backend"; | ||
|
||
export const useDBMS = () => { | ||
const query = useQuery({ | ||
queryKey: ["admin_db_dbms"], | ||
queryFn: api.admin.data.dbms.get, | ||
}); | ||
const { data: dbms, isLoading: isLoadingDbms, error: errorDbms } = query; | ||
return { dbms, isLoadingDbms, errorDbms }; | ||
}; |
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 @@ | ||
import { useMutation, UseMutationOptions } from "@tanstack/react-query"; | ||
import { api } from "../../../backend/api/backend"; | ||
|
||
export const useDBMSMutation = ( | ||
options: UseMutationOptions<unknown, unknown, string> | ||
) => { | ||
const mutation = useMutation({ | ||
mutationKey: ["admin_db_dbms"], | ||
mutationFn: api.admin.data.dbms.migrate, | ||
...options, | ||
}); | ||
const { | ||
mutate: migrate, | ||
isLoading: isMigrating, | ||
error: errorMigrate, | ||
} = mutation; | ||
return { migrate, isMigrating, errorMigrate }; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
type Settings = { | ||
notifications?: { | ||
webhook?: string; | ||
}; | ||
|
||
updates?: { | ||
channel?: string; | ||
}; | ||
webhook?: string; | ||
updates_channel?: string; | ||
}; |