Skip to content

Implement tables.list and tables.delete RPC APIs on the schema page #3651

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

Merged
merged 27 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b59608e
Rename `TableEntry` to `Table` and `id` to `oid`
seancolsen Jul 19, 2024
4f33808
Move Table type to RPC file
seancolsen Jul 19, 2024
e4fac4f
Flesh out tables RPC method types
seancolsen Jul 19, 2024
2b4fe81
Remove old properties from Table type
seancolsen Jul 19, 2024
9663023
Add TupleMap utility
seancolsen Jul 19, 2024
9235655
Light code cleanup in stores/tables.ts
seancolsen Jul 19, 2024
76057f5
Rename some stores exported from tables.ts
seancolsen Jul 19, 2024
b5170e3
Add connection params to tables functions
seancolsen Jul 19, 2024
8d2a524
Minor cleanup
seancolsen Jul 19, 2024
8be0d60
Update tables API types with new metadata fields
seancolsen Jul 19, 2024
6ff2b63
Adjust code to match Table type with metadata
seancolsen Jul 19, 2024
f095cbe
Begin replacing tables REST calls with RPC
seancolsen Jul 19, 2024
4f1272a
Adjust function name
seancolsen Jul 19, 2024
a30dbd6
Begin fleshing out updateTable function
seancolsen Jul 19, 2024
c273a49
Add code comment
seancolsen Jul 19, 2024
ca7340b
Handle API errors in front end when patching table
seancolsen Jul 19, 2024
bbab92d
Fix linting errors
seancolsen Jul 19, 2024
17b40e4
Run prettier
seancolsen Jul 21, 2024
05d9e5d
Fix small TODOs
seancolsen Jul 22, 2024
e2ea1c7
Merge branch 'develop' into tables_rpc_fe
seancolsen Jul 22, 2024
cb86c8a
Merge branch 'develop' into tables_rpc_fe
seancolsen Jul 23, 2024
e185d6d
Fix TS error after git merge
seancolsen Jul 23, 2024
8999c85
Merge branch 'develop' into tables_rpc_fe
pavish Jul 24, 2024
f3bcb0c
Merge branch 'develop' into tables_rpc_fe
seancolsen Jul 24, 2024
eeac691
Merge branch 'develop' into tables_rpc_fe
seancolsen Jul 25, 2024
a1b293e
Fix TS errors post-merge
seancolsen Jul 25, 2024
1886e00
Rename connection to database
seancolsen Jul 25, 2024
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
3 changes: 1 addition & 2 deletions mathesar_ui/src/api/rest/columns.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { TableEntry } from './types/tables';
import type { Column } from './types/tables/columns';
import { type PaginatedResponse, getAPI } from './utils/requestUtils';

function list(tableId: TableEntry['id']) {
function list(tableId: number) {
const url = `/api/db/v0/tables/${tableId}/columns/?limit=500`;
return getAPI<PaginatedResponse<Column>>(url);
}
Expand Down
39 changes: 0 additions & 39 deletions mathesar_ui/src/api/rest/types/tables.ts

This file was deleted.

6 changes: 3 additions & 3 deletions mathesar_ui/src/api/rest/types/tables/joinable_tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* endpoint: /api/db/v0/tables/<table_id>/joinable_tables/
*/

import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Table } from '@mathesar/api/rpc/tables';

import type { Column } from './columns';

Expand All @@ -13,7 +13,7 @@ type IsLinkReversed = boolean;
export type JpPath = [Column['id'], Column['id']][];

export interface JoinableTable {
target: TableEntry['id']; // baseTableId
target: Table['oid']; // baseTableId
jp_path: JpPath;
fk_path: [ForeignKeyId, IsLinkReversed][];
depth: number;
Expand All @@ -25,7 +25,7 @@ export interface JoinableTablesResult {
tables: Record<
string, // tableId
{
name: TableEntry['name'];
name: Table['name'];
columns: Column['id'][];
}
>;
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 @@ -4,6 +4,7 @@ import { buildRpcApi } from '@mathesar/packages/json-rpc-client-builder';

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

/** Mathesar's JSON-RPC API */
export const api = buildRpcApi({
Expand All @@ -12,5 +13,6 @@ export const api = buildRpcApi({
methodTree: {
connections,
schemas,
tables,
},
});
90 changes: 90 additions & 0 deletions mathesar_ui/src/api/rpc/tables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

export interface RawTable {
oid: number;
name: string;
/** The OID of the schema containing the table */
schema: number;
description: string | null;
}

interface TableMetadata {
import_verified: boolean | null;
column_order: number[] | null;
record_summary_customized: boolean | null;
record_summary_template: string | null;
}

export interface Table extends RawTable {
metadata: TableMetadata | null;
}

export const tables = {
list: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
},
RawTable[]
>(),

list_with_metadata: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
},
Table[]
>(),

get: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
},
RawTable
>(),

get_with_metadata: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
},
Table
>(),

/** Returns the oid of the table created */
add: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
table_name?: string;
comment?: string;
/** TODO */
column_data_list?: unknown;
/** TODO */
constraint_data_list?: unknown;
},
number
>(),

patch: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
table_data_dict: {
name?: string;
description?: string | null;
};
},
void
>(),

delete: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
cascade?: boolean;
},
void
>(),
};
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
return;
}
isCreatingNewEmptyTable = true;
const tableInfo = await createTable(database, schema, {});
const tableOid = await createTable(database, schema, {});
isCreatingNewEmptyTable = false;
router.goto(getTablePageUrl(database.id, schema.oid, tableInfo.id), false);
router.goto(getTablePageUrl(database.id, schema.oid, tableOid), false);
}
</script>

Expand Down
43 changes: 0 additions & 43 deletions mathesar_ui/src/components/EditTableHOC.svelte

This file was deleted.

13 changes: 6 additions & 7 deletions mathesar_ui/src/components/SelectTable.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
<script lang="ts">
import { _ } from 'svelte-i18n';

import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Table } from '@mathesar/api/rpc/tables';
import { Select } from '@mathesar-component-library';
import type { SelectProps } from '@mathesar-component-library/types';

import TableName from './TableName.svelte';

type $$Events = Select<TableEntry | undefined>['$$events_def'];
type $$Events = Select<Table | undefined>['$$events_def'];

export let tables: TableEntry[];
export let value: TableEntry | undefined = undefined;
export let tables: Table[];
export let value: Table | undefined = undefined;
/** TODO: Discuss, do we need prependBlank? */
export let prependBlank = false;
export let autoSelect: SelectProps<TableEntry | undefined>['autoSelect'] =
'first';
export let autoSelect: SelectProps<Table | undefined>['autoSelect'] = 'first';

$: tableList = prependBlank ? [undefined, ...tables] : tables;
</script>

<Select
options={tableList}
valuesAreEqual={(a, b) => a?.id === b?.id}
valuesAreEqual={(a, b) => a?.oid === b?.oid}
{autoSelect}
bind:value
on:change
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script lang="ts">
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Table } from '@mathesar/api/rpc/tables';
import { importVerifiedTables } from '@mathesar/stores/tables';
import type { SelectProps } from '@mathesar-component-library/types';

import SelectTable from './SelectTable.svelte';

export let value: TableEntry | undefined = undefined;
export let value: Table | undefined = undefined;
export let prependBlank = false;
export let autoSelect: SelectProps<TableEntry | undefined>['autoSelect'] =
'first';
export let autoSelect: SelectProps<Table | undefined>['autoSelect'] = 'first';

$: tables = [...$importVerifiedTables.values()];
</script>
Expand Down
13 changes: 5 additions & 8 deletions mathesar_ui/src/components/TableName.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';

import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Table } from '@mathesar/api/rpc/tables';
import { iconTable } from '@mathesar/icons';
import { isTableImportConfirmationRequired } from '@mathesar/utils/tables';
import { tableRequiresImportConfirmation } from '@mathesar/utils/tables';

import NameWithIcon from './NameWithIcon.svelte';

interface $$Props extends Omit<ComponentProps<NameWithIcon>, 'icon'> {
table: {
name: TableEntry['name'];
data_files?: TableEntry['data_files'];
import_verified?: TableEntry['import_verified'];
};
table: Pick<Table, 'name'> &
Parameters<typeof tableRequiresImportConfirmation>[0];
isLoading?: boolean;
}

export let table: $$Props['table'];
export let isLoading = false;

$: isNotConfirmed = isTableImportConfirmationRequired(table);
$: isNotConfirmed = tableRequiresImportConfirmation(table);
</script>

<NameWithIcon icon={iconTable} {isLoading} {...$$restProps}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
href={getRecordPageUrl(
item.database.id,
item.schema.oid,
item.table.id,
item.table.oid,
item.record.pk,
)}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Table } from '@mathesar/api/rpc/tables';
import { iconExpandRight } from '@mathesar/icons';
import { getRecordSelectorFromContext } from '@mathesar/systems/record-selector/RecordSelectorController';
import { Button, Icon, iconSearch } from '@mathesar-component-library';

const recordSelector = getRecordSelectorFromContext();
export let table: TableEntry;
export let table: Table;

function handleClick() {
recordSelector.navigateToRecordPage({ tableId: table.id });
recordSelector.navigateToRecordPage({ tableId: table.oid });
}
</script>

Expand Down
14 changes: 5 additions & 9 deletions mathesar_ui/src/components/breadcrumb/EntitySelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import { meta } from 'tinro';

import type { QueryInstance } from '@mathesar/api/rest/types/queries';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Schema } from '@mathesar/api/rpc/schemas';
import type { Table } from '@mathesar/api/rpc/tables';
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';
import {
currentTableId,
tables as tablesStore,
} from '@mathesar/stores/tables';
import { currentTableId, currentTables } from '@mathesar/stores/tables';
import { getLinkForTableItem } from '@mathesar/utils/tables';

import BreadcrumbSelector from './BreadcrumbSelector.svelte';
Expand All @@ -26,7 +23,7 @@
export let schema: Schema;

function makeTableBreadcrumbSelectorItem(
table: TableEntry,
table: Table,
): BreadcrumbSelectorEntryForTable {
return {
type: 'table',
Expand All @@ -35,7 +32,7 @@
href: getLinkForTableItem(database.id, schema.oid, table),
icon: iconTable,
isActive() {
return table.id === $currentTableId;
return table.oid === $currentTableId;
},
};
}
Expand Down Expand Up @@ -63,11 +60,10 @@
};
}

$: tables = [...$tablesStore.data.values()];
$: queries = [...$queriesStore.data.values()];

$: selectorData = new Map<string, BreadcrumbSelectorEntry[]>([
[$_('tables'), tables.map(makeTableBreadcrumbSelectorItem)],
[$_('tables'), $currentTables.map(makeTableBreadcrumbSelectorItem)],
[$_('explorations'), queries.map(makeQueryBreadcrumbSelectorItem)],
]);
</script>
Expand Down
Loading
Loading