Skip to content

Commit

Permalink
disconnect database flow ux fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatvijay committed Oct 5, 2023
1 parent fe6c7b6 commit e590725
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import EntityContainerWithFilterBar from '@mathesar/components/EntityContainerWithFilterBar.svelte';
import { AnchorButton, Icon } from '@mathesar/component-library';
import { labeledCount } from '@mathesar/utils/languageUtils';
import { isSuccessfullyConnectedDatabase } from '@mathesar/utils/database';
import DatabaseConnectionSkeleton from './DatabaseConnectionSkeleton.svelte';
import { makeSimplePageTitle } from '../pageTitleUtils';
import DatabaseConnectionItem from './DatabaseConnectionItem.svelte';
Expand All @@ -24,9 +23,6 @@
$: databasesLoadError = $databases.error;
function isMatch(database: Database, q: string) {
if (!isSuccessfullyConnectedDatabase(database)) {
return database.name.toLowerCase().includes(q);
}
return (
database.name.toLowerCase().includes(q) ||
database.db_name.toLowerCase().includes(q)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<script lang="ts">
import AppendBreadcrumb from '@mathesar/components/breadcrumb/AppendBreadcrumb.svelte';
import { iconEdit } from '@mathesar/icons';
import { iconDeleteMajor, iconEdit } from '@mathesar/icons';
import { toast } from '@mathesar/stores/toast';
import {
getDatabaseConnectionEditUrl,
getDatabasePageUrl,
} from '@mathesar/routes/urls';
import { reloadDatabases } from '@mathesar/stores/databases';
import { databases, reloadDatabases } from '@mathesar/stores/databases';
import { reflectApi } from '@mathesar/api/reflect';
import { router } from 'tinro';
import FormBox from '../admin-users/FormBox.svelte';
import DatabaseConnectionForm from './DatabaseConnectionForm.svelte';
import DeleteDatabaseConnectionConfirmationModal from '../database/DeleteDatabaseConnectionConfirmationModal.svelte';
import { modal } from '@mathesar/stores/modal';

Check failure on line 15 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/stores/modal` import should occur before import of `../admin-users/FormBox.svelte`

Check failure on line 15 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/stores/modal` import should occur before import of `../admin-users/FormBox.svelte`
import Button from '@mathesar/component-library/button/Button.svelte';

Check failure on line 16 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/component-library/button/Button.svelte` import should occur before import of `../admin-users/FormBox.svelte`

Check failure on line 16 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/component-library/button/Button.svelte` import should occur before import of `../admin-users/FormBox.svelte`
import { Icon } from '@mathesar/component-library';

Check failure on line 17 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/component-library` import should occur before import of `../admin-users/FormBox.svelte`

Check failure on line 17 in mathesar_ui/src/pages/database-connection/EditDatabaseConnection.svelte

View workflow job for this annotation

GitHub Actions / lint

`@mathesar/component-library` import should occur before import of `../admin-users/FormBox.svelte`
export let databaseName: string;
const deleteConnectionModal = modal.spawnModalController();
$: database = $databases.data.find((db) => db.name === databaseName);
async function handleSuccess() {
toast.success(`${databaseName} updated successfully!`);
Expand All @@ -26,6 +34,11 @@
router.goto(getDatabasePageUrl(databaseName));
}
}
async function handleSuccessfulDeleteConnection() {
await reloadDatabases();
router.goto('/');
}
</script>

<AppendBreadcrumb
Expand All @@ -42,3 +55,21 @@
<FormBox>
<DatabaseConnectionForm {databaseName} onUpdate={handleSuccess} />
</FormBox>

{#if database}
<FormBox>
<Button
on:click={() => deleteConnectionModal.open()}
danger
appearance="default"
>
<Icon {...iconDeleteMajor} />
<span>Disconnect Database</span>
</Button>
</FormBox>
<DeleteDatabaseConnectionConfirmationModal
controller={deleteConnectionModal}
{database}
on:success={handleSuccessfulDeleteConnection}
/>
{/if}
9 changes: 5 additions & 4 deletions mathesar_ui/src/pages/database/ConnectionError.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import type { DatabaseWithConnectionError } from '@mathesar/AppTypes';
import { States } from '@mathesar/api/utils/requestUtils';
import { Button, Icon, iconLoading } from '@mathesar/component-library';
import AnchorButton from '@mathesar/component-library/anchorButton/AnchorButton.svelte';
Expand All @@ -7,20 +8,20 @@
import { getDatabaseConnectionEditUrl } from '@mathesar/routes/urls';
import { refetchSchemasForDB, schemas } from '@mathesar/stores/schemas';
export let databaseName: string;
export let database: DatabaseWithConnectionError;
$: ({ state } = $schemas);
async function handleRetry() {
void refetchSchemasForDB(databaseName);
void refetchSchemasForDB(database.name);
}
</script>

<ErrorBox fullWidth>
<p>Error connecting to the database</p>
<p>{database.error}</p>
<div class="action-buttons">
<AnchorButton
href={getDatabaseConnectionEditUrl(databaseName)}
href={getDatabaseConnectionEditUrl(database.name)}
appearance="secondary"
>
<Icon {...iconEdit} />
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/pages/database/DatabaseDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
icon={iconDeleteMajor}
on:click={() => deleteConnectionModal.open()}
>
Delete Connection
Disconnect Database
</ButtonMenuItem>
{/if}
</DropdownMenu>
Expand All @@ -199,7 +199,7 @@
<h2 class="schema-list-title">Schemas ({schemasMap.size})</h2>
</div>
{#if !isSuccessfullyConnectedDatabase(database)}
<ConnectionError databaseName={database.name} />
<ConnectionError {database} />
{:else}
<EntityContainerWithFilterBar
searchPlaceholder="Search Schemas"
Expand Down

0 comments on commit e590725

Please sign in to comment.