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

Db connection UI #3223

Merged
merged 40 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0bb7d38
add database connection page
rajatvijay Sep 22, 2023
e401e9f
edit database connection
rajatvijay Sep 22, 2023
5110a40
delete database connection
rajatvijay Sep 22, 2023
ad09ba3
lint fixes
rajatvijay Sep 22, 2023
7819bdd
Merge branch 'develop' of github.com:centerofci/mathesar into db-conn…
rajatvijay Sep 25, 2023
62b4ee4
add db connection button on the admin pages
rajatvijay Sep 25, 2023
e7a9d1c
database connection list page & rounting
rajatvijay Sep 26, 2023
19c845e
Merge branch 'db_config_api' of github.com:centerofci/mathesar into d…
rajatvijay Sep 27, 2023
9b6c339
Merge branch 'db_config_api' of github.com:centerofci/mathesar into d…
rajatvijay Sep 27, 2023
cce8e0c
renamed user form component
rajatvijay Sep 27, 2023
10d814f
no database found component
rajatvijay Sep 27, 2023
6e80ec9
database connection error ui
rajatvijay Oct 2, 2023
7c12f77
renamed connections list vars
rajatvijay Oct 2, 2023
fea9634
lint fixes
rajatvijay Oct 2, 2023
8c194d4
user flow bug fixes
rajatvijay Oct 2, 2023
1043ca4
Merge branch 'db_config_api' of github.com:centerofci/mathesar into d…
rajatvijay Oct 2, 2023
070bd90
lint fixes
rajatvijay Oct 2, 2023
668f922
removed todos
rajatvijay Oct 2, 2023
a8424f7
bring back old todo
rajatvijay Oct 2, 2023
25c5b24
Merge branch 'develop' into db-connection-pages
pavish Oct 3, 2023
1d768c3
removed instaces of successfullDatabases
rajatvijay Oct 5, 2023
9781a7e
Merge branch 'db-connection-pages' of github.com:centerofci/mathesar …
rajatvijay Oct 5, 2023
a94015d
fixed formatting
rajatvijay Oct 5, 2023
5eb453f
loader while reloading the db
rajatvijay Oct 5, 2023
ddb942b
placeholder for links
rajatvijay Oct 5, 2023
0fa711d
created database utils
rajatvijay Oct 5, 2023
41853f3
created database utils
rajatvijay Oct 5, 2023
1967ee1
moved isMatch out of parent function
rajatvijay Oct 5, 2023
d4b4813
lint fixes
rajatvijay Oct 5, 2023
810f49f
database store to have done as initial state
rajatvijay Oct 5, 2023
ef901b6
regression fix on users flow
rajatvijay Oct 5, 2023
d1353b4
regression fix on users flow
rajatvijay Oct 5, 2023
bd018fb
Merge branch 'db-connection-pages' of github.com:centerofci/mathesar …
rajatvijay Oct 5, 2023
ce24035
connections list ui fixes
rajatvijay Oct 5, 2023
fe6c7b6
no condition on schema page on connection error
rajatvijay Oct 5, 2023
e590725
disconnect database flow ux fixes
rajatvijay Oct 5, 2023
60b53e5
lint fixes
rajatvijay Oct 5, 2023
3edd094
Merge branch 'develop' into db-connection-pages
rajatvijay Oct 5, 2023
cb08572
fixes related to review comments
rajatvijay Oct 10, 2023
8028323
Merge branch 'develop' into db-connection-pages
seancolsen Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mathesar/urls.py
Expand Up @@ -53,6 +53,9 @@
path('administration/users/', views.admin_home, name='admin_users_home'),
path('administration/users/<user_id>/', views.admin_home, name='admin_users_edit'),
path('administration/update/', views.admin_home, name='admin_update'),
path('administration/db-connection/', views.list_database_connection, name='list_database_connection'),
path('administration/db-connection/add/', views.add_database_connection, name='add_database_connection'),
path('administration/db-connection/edit/<db_name>/', views.edit_database_connection, name='edit_database_connection'),
path('shares/tables/<slug>/', views.shared_table, name='shared_table'),
path('shares/explorations/<slug>/', views.shared_query, name='shared_query'),
path('db/', views.home, name='db_home'),
Expand Down
27 changes: 27 additions & 0 deletions mathesar/views.py
Expand Up @@ -80,7 +80,12 @@ def get_database_list(request):
failed_db_data = []
for db in permission_restricted_failed_db_qs:
failed_db_data.append({
'id': db.id,
'username': db.username,
'port': db.port,
'host': db.host,
'name': db.name,
'db_name': db.db_name,
Comment on lines +84 to +89
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anish9901 added attributes here required when editing

'editable': db.editable,
pavish marked this conversation as resolved.
Show resolved Hide resolved
'error': 'Error connecting to the database'
})
Expand Down Expand Up @@ -301,6 +306,28 @@ def schemas(request, db_name):
})


@login_required
def list_database_connection(request):
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request)
})


@login_required
def add_database_connection(request):
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request)
})


@login_required
def edit_database_connection(request, db_name):
database = get_current_database(request, db_name)
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request, database, None)
})


def shared_table(request, slug):
shared_table_link = SharedTable.get_by_slug(slug) if is_valid_uuid_v4(slug) else None
table = shared_table_link.table if shared_table_link else None
Expand Down
18 changes: 17 additions & 1 deletion mathesar_ui/src/AppTypes.ts
@@ -1,12 +1,28 @@
import type { TreeItem } from '@mathesar-component-library/types';

export interface Database {
interface BaseDatabase {
id: number;
name: string;
editable: boolean;
username: string;
host: string;
port: string;
db_name: string;
}

export interface DatabaseWithConnectionError extends BaseDatabase {
error: string;
}

export interface SuccessfullyConnectedDatabase extends BaseDatabase {
deleted: boolean;
supported_types: string[];
}

export type Database =
| SuccessfullyConnectedDatabase
| DatabaseWithConnectionError;

export interface DBObjectEntry {
id: number;
name: string;
Expand Down
38 changes: 38 additions & 0 deletions mathesar_ui/src/api/databaseConnection.ts
@@ -0,0 +1,38 @@
import type { SuccessfullyConnectedDatabase } 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<SuccessfullyConnectedDatabase>(
'/api/db/v0/databases/',
connectionDetails,
);
}

function update(databaseId: number, updates: ConnectionUpdates) {
return patchAPI<SuccessfullyConnectedDatabase>(
`/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,
};
9 changes: 6 additions & 3 deletions mathesar_ui/src/api/users.ts
@@ -1,4 +1,7 @@
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
SuccessfullyConnectedDatabase,
SchemaEntry,
} from '@mathesar/AppTypes';
import {
deleteAPI,
getAPI,
Expand All @@ -18,7 +21,7 @@ export type UserRole = 'viewer' | 'editor' | 'manager';

export interface DatabaseRole {
id: number;
database: Database['id'];
database: SuccessfullyConnectedDatabase['id'];
role: UserRole;
}

Expand Down Expand Up @@ -73,7 +76,7 @@ function resetPassword(userId: User['id'], password: string) {

function addDatabaseRole(
userId: User['id'],
databaseId: Database['id'],
databaseId: SuccessfullyConnectedDatabase['id'],
role: UserRole,
) {
return postAPI<DatabaseRole>('/api/ui/v0/database_roles/', {
Expand Down
Expand Up @@ -83,6 +83,7 @@
--size-ultra-large: 2.074rem; //2.074rem/33.18px
--size-super-ultra-large: 2.488rem; //2.488rem/39.81px

--border-radius-xs: 0.071rem; //1px
--border-radius-s: 0.142rem; //2px
--border-radius-m: 0.285rem; //4px
--border-radius-l: 0.571rem; //8px
Expand Down
6 changes: 3 additions & 3 deletions mathesar_ui/src/components/breadcrumb/DatabaseSelector.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
import type { Database } from '@mathesar/AppTypes';
import type { SuccessfullyConnectedDatabase } from '@mathesar/AppTypes';
import { iconDatabase } from '@mathesar/icons';
import { getDatabasePageUrl } from '@mathesar/routes/urls';
import {
Expand All @@ -10,7 +10,7 @@
import type { BreadcrumbSelectorEntry } from './breadcrumbTypes';

function makeBreadcrumbSelectorItem(
dbEntry: Database,
dbEntry: SuccessfullyConnectedDatabase,
): BreadcrumbSelectorEntry {
return {
type: 'simple',
Expand All @@ -23,7 +23,7 @@
};
}

$: databases = [...$dbStore.data.values()];
$: databases = [...$dbStore.successfulConnections.values()];
</script>

<BreadcrumbSelector
Expand Down
7 changes: 5 additions & 2 deletions mathesar_ui/src/components/breadcrumb/EntitySelector.svelte
Expand Up @@ -6,7 +6,10 @@
} from '@mathesar/stores/tables';
import type { TableEntry } from '@mathesar/api/types/tables';
import { getExplorationPageUrl } from '@mathesar/routes/urls';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
SuccessfullyConnectedDatabase,
SchemaEntry,
} from '@mathesar/AppTypes';
import { iconTable } from '@mathesar/icons';
import { queries as queriesStore } from '@mathesar/stores/queries';
import type { QueryInstance } from '@mathesar/api/types/queries';
Expand All @@ -18,7 +21,7 @@
BreadcrumbSelectorEntryForTable,
} from './breadcrumbTypes';

export let database: Database;
export let database: SuccessfullyConnectedDatabase;
export let schema: SchemaEntry;

function makeTableBreadcrumbSelectorItem(
Expand Down
7 changes: 5 additions & 2 deletions mathesar_ui/src/components/breadcrumb/SchemaSelector.svelte
@@ -1,5 +1,8 @@
<script lang="ts">
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
SuccessfullyConnectedDatabase,
SchemaEntry,
} from '@mathesar/AppTypes';
import { iconSchema } from '@mathesar/icons';
import { getSchemaPageUrl } from '@mathesar/routes/urls';
import {
Expand All @@ -9,7 +12,7 @@
import BreadcrumbSelector from './BreadcrumbSelector.svelte';
import type { BreadcrumbSelectorEntry } from './breadcrumbTypes';

export let database: Database;
export let database: SuccessfullyConnectedDatabase;

function makeBreadcrumbSelectorItem(
schemaEntry: SchemaEntry,
Expand Down
14 changes: 9 additions & 5 deletions mathesar_ui/src/components/breadcrumb/breadcrumbTypes.ts
@@ -1,6 +1,10 @@
import type { QueryInstance } from '@mathesar/api/types/queries';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
SuccessfullyConnectedDatabase,
Database,
SchemaEntry,
} from '@mathesar/AppTypes';
import type {
ComponentAndProps,
IconProps,
Expand All @@ -13,13 +17,13 @@ export interface BreadcrumbItemDatabase {

export interface BreadcrumbItemSchema {
type: 'schema';
database: Database;
database: SuccessfullyConnectedDatabase;
schema: SchemaEntry;
}

export interface BreadcrumbItemTable {
type: 'table';
database: Database;
database: SuccessfullyConnectedDatabase;
schema: SchemaEntry;
table: TableEntry;
}
Expand All @@ -33,7 +37,7 @@ export interface BreadcrumbItemSimple {

export interface BreadcrumbItemRecord {
type: 'record';
database: Database;
database: SuccessfullyConnectedDatabase;
schema: SchemaEntry;
table: TableEntry;
record: {
Expand All @@ -44,7 +48,7 @@ export interface BreadcrumbItemRecord {

export interface BreadcrumbItemExploration {
type: 'exploration';
database: Database;
database: SuccessfullyConnectedDatabase;
schema: SchemaEntry;
query: Pick<QueryInstance, 'id' | 'name'>;
}
Expand Down
Expand Up @@ -7,7 +7,7 @@
} from '@mathesar-component-library';
import { Field, type FieldStore } from '@mathesar/components/form';
import type { ComponentWithProps } from '@mathesar-component-library/types';
import UserFormInputRow from './UserFormInputRow.svelte';
import GridFormInputRow from './GridFormInputRow.svelte';

const labelController = new LabelController();
$: setLabelControllerInContext(labelController);
Expand All @@ -22,7 +22,7 @@
export let bypassRow = false;
</script>

<UserFormInputRow bypass={bypassRow}>
<GridFormInputRow bypass={bypassRow}>
<div class="left cell">
<Label controller={labelController}>
{label}
Expand All @@ -39,7 +39,7 @@
</div>
{/if}
</div>
</UserFormInputRow>
</GridFormInputRow>

<style lang="scss">
.left {
Expand All @@ -48,5 +48,12 @@
justify-content: end;
margin-right: var(--size-large);
padding-top: var(--size-ultra-small);
margin-left: var(--size-large);
}

.help {
color: var(--slate-500);
margin-top: var(--size-extreme-small);
font-size: var(--size-small);
}
</style>
19 changes: 17 additions & 2 deletions mathesar_ui/src/pages/admin-users/AdminNavigation.svelte
@@ -1,10 +1,15 @@
<script lang="ts">
import { active } from 'tinro';
import { Menu, MenuItemContents } from '@mathesar-component-library';
import { iconSettingsMajor, iconMultipleUsers } from '@mathesar/icons';
import {
iconSettingsMajor,
iconMultipleUsers,
iconDatabase,
} from '@mathesar/icons';
import {
ADMIN_UPDATE_PAGE_URL,
ADMIN_USERS_PAGE_URL,
DATABASE_CONNECTION_LIST_URL,
} from '@mathesar/routes/urls';
import { getReleaseDataStoreFromContext } from '@mathesar/stores/releases';

Expand Down Expand Up @@ -36,12 +41,22 @@
>
<MenuItemContents icon={iconMultipleUsers}>Users</MenuItemContents>
</a>
<a
role="menuitem"
href={DATABASE_CONNECTION_LIST_URL}
class="menu-item menu-item-link"
use:active
>
<MenuItemContents icon={iconDatabase}
>Database Connection</MenuItemContents
>
</a>
</Menu>
</div>

<style lang="scss">
.admin-navigation {
font-size: var(--text-size-large);
font-size: var(--text-size-base);
--min-width: 100%;
--Menu__item-border-radius: var(--border-radius-m);
--Menu__item-hover-background: var(--sand-100);
Expand Down
7 changes: 5 additions & 2 deletions mathesar_ui/src/pages/data-explorer/DataExplorerPage.svelte
@@ -1,6 +1,9 @@
<script lang="ts">
import { router } from 'tinro';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
SuccessfullyConnectedDatabase,
SchemaEntry,
} from '@mathesar/AppTypes';
import LayoutWithHeader from '@mathesar/layouts/LayoutWithHeader.svelte';
import { DataExplorer } from '@mathesar/systems/data-explorer';
import type { QueryManager } from '@mathesar/systems/data-explorer/types';
Expand All @@ -13,7 +16,7 @@

const userProfile = getUserProfileStoreFromContext();

export let database: Database;
export let database: SuccessfullyConnectedDatabase;
export let schema: SchemaEntry;
export let queryManager: QueryManager;

Expand Down