-
-
Notifications
You must be signed in to change notification settings - Fork 338
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 #3223 from centerofci/db-connection-pages
Db connection UI
- Loading branch information
Showing
31 changed files
with
993 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Database } from '@mathesar/AppTypes'; | ||
import { deleteAPI, patchAPI, postAPI } from './utils/requestUtils'; | ||
|
||
export interface NewConnection { | ||
name: string; | ||
db_name: string; | ||
username: string; | ||
host: string; | ||
port: string; | ||
password: string; | ||
} | ||
|
||
export type ConnectionUpdates = Partial<Omit<NewConnection, 'name'>>; | ||
|
||
function add(connectionDetails: NewConnection) { | ||
return postAPI<Database>('/api/db/v0/databases/', connectionDetails); | ||
} | ||
|
||
function update(databaseId: number, updates: ConnectionUpdates) { | ||
return patchAPI<Database>(`/api/db/v0/databases/${databaseId}/`, updates); | ||
} | ||
|
||
function deleteConnection(databaseId: number, removeMathesarSchemas = false) { | ||
const param = removeMathesarSchemas ? '?del_msar_schemas=True' : ''; | ||
return deleteAPI(`/api/db/v0/databases/${databaseId}/${param}`); | ||
} | ||
|
||
export default { | ||
add, | ||
update, | ||
delete: deleteConnection, | ||
}; |
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
File renamed without changes.
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
File renamed without changes.
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
43 changes: 43 additions & 0 deletions
43
mathesar_ui/src/pages/database-connection/AddDatabaseConnection.svelte
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,43 @@ | ||
<script lang="ts"> | ||
import AppendBreadcrumb from '@mathesar/components/breadcrumb/AppendBreadcrumb.svelte'; | ||
import { iconAddNew } from '@mathesar/icons'; | ||
import { | ||
DATABASE_CONNECTION_ADD_URL, | ||
getDatabasePageUrl, | ||
} from '@mathesar/routes/urls'; | ||
import { toast } from '@mathesar/stores/toast'; | ||
import type { Database } from '@mathesar/AppTypes'; | ||
import { router } from 'tinro'; | ||
import { reloadDatabases } from '@mathesar/stores/databases'; | ||
import { reflectApi } from '@mathesar/api/reflect'; | ||
import FormBox from '@mathesar/components/form/FormBox.svelte'; | ||
import DatabaseConnectionForm from './DatabaseConnectionForm.svelte'; | ||
async function handleSuccess(database: Database) { | ||
toast.success(`${database.name} connected successfully!`); | ||
try { | ||
await reflectApi.reflect(); | ||
await reloadDatabases(); | ||
} catch (e) { | ||
toast.fromError(e); | ||
} finally { | ||
router.goto(getDatabasePageUrl(database.name)); | ||
} | ||
} | ||
</script> | ||
|
||
<AppendBreadcrumb | ||
item={{ | ||
type: 'simple', | ||
href: DATABASE_CONNECTION_ADD_URL, | ||
label: 'Add Database Connection', | ||
icon: iconAddNew, | ||
}} | ||
/> | ||
|
||
<h1>Add Database Connection</h1> | ||
|
||
<FormBox> | ||
<DatabaseConnectionForm onCreate={handleSuccess} /> | ||
</FormBox> |
Oops, something went wrong.