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

Merge breaking changes into develop #3695

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mathesar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
path('i18n/', include('django.conf.urls.i18n')),
re_path(
r'^db/(?P<connection_id>\w+)/(?P<schema_id>\w+)/',
views.schema_home,
views.schemas,
name='schema_home'
),
]
37 changes: 6 additions & 31 deletions mathesar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response

from mathesar.rpc.schemas import list_ as schemas_list
from mathesar.api.db.permissions.database import DatabaseAccessPolicy
from mathesar.api.db.permissions.query import QueryAccessPolicy
from mathesar.api.db.permissions.schema import SchemaAccessPolicy
Expand All @@ -26,14 +27,10 @@


def get_schema_list(request, database):
qs = Schema.objects.filter(database=database)
permission_restricted_qs = SchemaAccessPolicy.scope_queryset(request, qs)
schema_serializer = SchemaSerializer(
permission_restricted_qs,
many=True,
context={'request': request}
)
return schema_serializer.data
if database is not None:
return schemas_list(request=request, database_id=database.id)
else:
return []


def _get_permissible_db_queryset(request):
Expand Down Expand Up @@ -180,19 +177,6 @@ def get_current_database(request, connection_id):
return current_database


def get_current_schema(request, schema_id, database):
# if there's a schema ID passed in, try to retrieve the schema, or return a 404 error.
if schema_id is not None:
permitted_schemas = SchemaAccessPolicy.scope_queryset(request, Schema.objects.all())
return get_object_or_404(permitted_schemas, id=schema_id)
else:
try:
# Try to get the first schema in the DB
return Schema.objects.filter(database=database).order_by('id').first()
except Schema.DoesNotExist:
return None


def render_schema(request, database, schema):
# if there's no schema available, redirect to the schemas page.
if not schema:
Expand Down Expand Up @@ -300,16 +284,7 @@ def admin_home(request, **kwargs):


@login_required
def schema_home(request, connection_id, schema_id, **kwargs):
database = get_current_database(request, connection_id)
schema = get_current_schema(request, schema_id, database)
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request, database, schema)
})


@login_required
def schemas(request, connection_id):
def schemas(request, connection_id, **kwargs):
database = get_current_database(request, connection_id)
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request, database, None)
Expand Down
12 changes: 0 additions & 12 deletions mathesar_ui/src/AppTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { TreeItem } from '@mathesar-component-library/types';

/** @deprecated in favor of Connection */
export interface Database {
id: number;
Expand All @@ -16,16 +14,6 @@ export interface DBObjectEntry {
description: string | null;
}

export interface SchemaEntry extends DBObjectEntry {
has_dependencies: boolean;
num_tables: number;
num_queries: number;
}

export interface SchemaResponse extends SchemaEntry, TreeItem {
tables: DBObjectEntry[];
}

export type DbType = string;

export interface FilterConfiguration {
Expand Down
50 changes: 0 additions & 50 deletions mathesar_ui/src/api/rest/schemas.ts

This file was deleted.

4 changes: 2 additions & 2 deletions mathesar_ui/src/api/rest/types/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Column } from '@mathesar/api/rest/types/tables/columns';
import type { JpPath } from '@mathesar/api/rest/types/tables/joinable_tables';
import type { PaginatedResponse } from '@mathesar/api/rest/utils/requestUtils';
import type { SchemaEntry } from '@mathesar/AppTypes';
import type { Schema } from '@mathesar/api/rpc/schemas';

export type QueryColumnAlias = string;

Expand Down Expand Up @@ -182,7 +182,7 @@ export interface QueryResultsResponse {

export interface QueryRunResponse extends QueryResultsResponse {
query: {
schema: SchemaEntry['id'];
schema: Schema['oid'];
base_table: QueryInstance['base_table'];
initial_columns: QueryInstanceInitialColumn[];
transformations?: QueryInstanceTransformation[];
Expand Down
7 changes: 4 additions & 3 deletions mathesar_ui/src/api/rest/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type { Schema } from '@mathesar/api/rpc/schemas';
import type { Database } from '@mathesar/AppTypes';
import type { Language } from '@mathesar/i18n/languages/utils';

import {
Expand Down Expand Up @@ -27,7 +28,7 @@ export interface DatabaseRole {

export interface SchemaRole {
id: number;
schema: SchemaEntry['id'];
schema: Schema['oid'];
role: UserRole;
}

Expand Down Expand Up @@ -92,7 +93,7 @@ function deleteDatabaseRole(roleId: DatabaseRole['id']) {

function addSchemaRole(
userId: User['id'],
schemaId: SchemaEntry['id'],
schemaId: Schema['oid'],
role: UserRole,
) {
return postAPI<SchemaRole>('/api/ui/v0/schema_roles/', {
Expand Down
2 changes: 2 additions & 0 deletions mathesar_ui/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Cookies from 'js-cookie';
import { buildRpcApi } from '@mathesar/packages/json-rpc-client-builder';

import { connections } from './connections';
import { schemas } from './schemas';

/** Mathesar's JSON-RPC API */
export const api = buildRpcApi({
endpoint: '/api/rpc/v0/',
getHeaders: () => ({ 'X-CSRFToken': Cookies.get('csrftoken') }),
methodTree: {
connections,
schemas,
},
});
47 changes: 47 additions & 0 deletions mathesar_ui/src/api/rpc/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

export interface Schema {
oid: number;
name: string;
description: string;
table_count: number;
}

export const schemas = {
list: rpcMethodTypeContainer<
{
database_id: number;
},
Schema[]
>(),

/** Returns the OID of the newly-created schema */
add: rpcMethodTypeContainer<
{
database_id: number;
name: string;
description?: string;
},
number
>(),

patch: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
patch: {
name?: string;
description?: string;
};
},
void
>(),

delete: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
},
void
>(),
};
6 changes: 3 additions & 3 deletions mathesar_ui/src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
isCreatingNewEmptyTable = true;
const tableInfo = await createTable(database, schema, {});
isCreatingNewEmptyTable = false;
router.goto(getTablePageUrl(database.id, schema.id, tableInfo.id), false);
router.goto(getTablePageUrl(database.id, schema.oid, tableInfo.id), false);
}
</script>

Expand Down Expand Up @@ -90,14 +90,14 @@
</ButtonMenuItem>
<LinkMenuItem
icon={iconAddNew}
href={getImportPageUrl(database.id, schema.id)}
href={getImportPageUrl(database.id, schema.oid)}
>
{$_('new_table_from_data_import')}
</LinkMenuItem>
{/if}
<LinkMenuItem
icon={iconExploration}
href={getDataExplorerPageUrl(database.id, schema.id)}
href={getDataExplorerPageUrl(database.id, schema.oid)}
>
{$_('open_data_explorer')}
</LinkMenuItem>
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/SchemaName.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import type { SchemaEntry } from '@mathesar/AppTypes';
import type { Schema } from '@mathesar/api/rpc/schemas';
import { iconSchema } from '@mathesar/icons';

import NameWithIcon from './NameWithIcon.svelte';

export let schema: SchemaEntry;
export let schema: Schema;
export let iconHasBox = false;

$: isLocked = schema.name === 'public';
Expand Down
8 changes: 4 additions & 4 deletions mathesar_ui/src/components/breadcrumb/BreadcrumbItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
{:else if item.type === 'schema'}
<SchemaSelector database={item.database} />
<div class="breadcrumb-item truncate">
<BreadcrumbLink href={getSchemaPageUrl(item.database.id, item.schema.id)}>
<BreadcrumbLink href={getSchemaPageUrl(item.database.id, item.schema.oid)}>
<SchemaName schema={item.schema} />
</BreadcrumbLink>
</div>
{:else if item.type === 'table'}
<EntitySelector database={item.database} schema={item.schema} />
<div class="breadcrumb-item truncate">
<BreadcrumbLink
href={getLinkForTableItem(item.database.id, item.schema.id, item.table)}
href={getLinkForTableItem(item.database.id, item.schema.oid, item.table)}
>
<TableName table={item.table} />
</BreadcrumbLink>
Expand All @@ -67,7 +67,7 @@
<BreadcrumbLink
href={getRecordPageUrl(
item.database.id,
item.schema.id,
item.schema.oid,
item.table.id,
item.record.pk,
)}
Expand All @@ -83,7 +83,7 @@
<BreadcrumbLink
href={getExplorationPageUrl(
item.database.id,
item.schema.id,
item.schema.oid,
item.query.id,
)}
>
Expand Down
11 changes: 6 additions & 5 deletions mathesar_ui/src/components/breadcrumb/EntitySelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import type { QueryInstance } from '@mathesar/api/rest/types/queries';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type { Schema } from '@mathesar/api/rpc/schemas';
import type { Database } from '@mathesar/AppTypes';
import { iconTable } from '@mathesar/icons';
import { getExplorationPageUrl } from '@mathesar/routes/urls';
import { queries as queriesStore } from '@mathesar/stores/queries';
Expand All @@ -22,7 +23,7 @@
} from './breadcrumbTypes';

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

function makeTableBreadcrumbSelectorItem(
table: TableEntry,
Expand All @@ -31,7 +32,7 @@
type: 'table',
table,
label: table.name,
href: getLinkForTableItem(database.id, schema.id, table),
href: getLinkForTableItem(database.id, schema.oid, table),
icon: iconTable,
isActive() {
return table.id === $currentTableId;
Expand All @@ -47,13 +48,13 @@
return {
type: 'simple',
label: queryInstance.name,
href: getExplorationPageUrl(database.id, schema.id, queryInstance.id),
href: getExplorationPageUrl(database.id, schema.oid, queryInstance.id),
icon: iconTable,
isActive() {
// TODO we don't have a store for what the current query is, so we fallback to comparing hrefs.
const entryhref = getExplorationPageUrl(
database.id,
schema.id,
schema.oid,
queryInstance.id,
);
const currentHref = $currentRoute.url;
Expand Down
Loading
Loading