Skip to content

Commit

Permalink
Merge branch 'develop' into records_list_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mathemancer committed Jul 22, 2024
2 parents 6294458 + 2f698bf commit 68ced5e
Show file tree
Hide file tree
Showing 54 changed files with 337 additions and 365 deletions.
21 changes: 13 additions & 8 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3383,17 +3383,19 @@ WITH orderable_cte AS (
INNER JOIN pg_catalog.pg_cast ON atttypid=castsource
INNER JOIN pg_catalog.pg_operator ON casttarget=oprleft
WHERE
attrelid=tab_id
AND attnum>0
AND castcontext='i'
AND oprname='<'
attrelid = tab_id
AND attnum > 0
AND NOT attisdropped
AND castcontext = 'i'
AND oprname = '<'
UNION SELECT attnum
FROM pg_catalog.pg_attribute
INNER JOIN pg_catalog.pg_operator ON atttypid=oprleft
WHERE
attrelid=tab_id
AND attnum>0
AND oprname='<'
attrelid = tab_id
AND attnum > 0
AND NOT attisdropped
AND oprname = '<'
ORDER BY attnum
)
SELECT COALESCE(jsonb_agg(jsonb_build_object('attnum', attnum, 'direction', 'asc')), '[]'::jsonb)
Expand Down Expand Up @@ -3443,7 +3445,10 @@ Args:
SELECT string_agg(format('msar.format_data(%I) AS %I', attname, attnum), ', ')
FROM pg_catalog.pg_attribute
WHERE
attrelid = tab_id AND attnum > 0 AND has_column_privilege(attrelid, attnum, 'SELECT');
attrelid = tab_id
AND attnum > 0
AND NOT attisdropped
AND has_column_privilege(attrelid, attnum, 'SELECT');
$$ LANGUAGE SQL RETURNS NULL ON NULL INPUT;


Expand Down
4 changes: 3 additions & 1 deletion db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2858,8 +2858,10 @@ BEGIN
col1 integer,
col2 varchar,
col3 json,
col4 jsonb
col4 jsonb,
coltodrop integer
);
ALTER TABLE atable DROP COLUMN coltodrop;
INSERT INTO atable (col1, col2, col3, col4) VALUES
(5, 'sdflkj', '"s"', '{"a": "val"}'),
(34, 'sdflfflsk', null, '[1, 2, 3, 4]'),
Expand Down
2 changes: 1 addition & 1 deletion mathesar/rpc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def list_(
group: list[dict] = None,
search: list[dict] = None,
**kwargs
) -> dict:
) -> RecordList:
"""
List records from a table, and its row count. Exposed as `list`.
Expand Down
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
Loading

0 comments on commit 68ced5e

Please sign in to comment.