Skip to content

Commit

Permalink
Merge branch 'develop' into records_grouping_bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mathemancer authored Aug 13, 2024
2 parents a32d79c + 58b7f95 commit 27be75c
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 761 deletions.
2 changes: 0 additions & 2 deletions mathesar/rpc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ class RecordAdded(TypedDict):
results: An array of a single record objects (the one added).
preview_data: Information for previewing foreign key values.
"""
count: int
results: list[dict]
grouping: GroupingResponse
preview_data: list[dict]

@classmethod
Expand Down
26 changes: 14 additions & 12 deletions mathesar_ui/src/api/rpc/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Table extends RawTable {
}

/** [table oid, column attnum][] */
export type JoinPath = [number, number][];
export type JoinPath = [number, number][][];

export interface JoinableTable {
target: Table['oid'];
Expand All @@ -45,18 +45,19 @@ export interface JoinableTable {

export interface JoinableTablesResult {
joinable_tables: JoinableTable[];
tables: Record<
string, // stringified table_oid
/** Keys are stringified table OID values */
target_table_info: Record<
string,
{
name: Table['name'];
columns: number[];
}
>;
columns: Record<
string, // stringified column_oid
{
name: string;
type: string;
/** Keys are stringified column attnum values */
columns: Record<
string,
{
name: string;
type: string;
}
>;
}
>;
}
Expand Down Expand Up @@ -133,7 +134,8 @@ export const tables = {
list_joinable: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
table_oid: number;
max_depth?: number;
},
JoinableTablesResult
>(),
Expand Down
14 changes: 9 additions & 5 deletions mathesar_ui/src/pages/record/RecordPageContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { _ } from 'svelte-i18n';
import { getDetailedRecordsErrors } from '@mathesar/api/rest/utils/recordUtils';
import { getAPI } from '@mathesar/api/rest/utils/requestUtils';
import type { JoinableTablesResult } from '@mathesar/api/rpc/tables';
import { api } from '@mathesar/api/rpc';
import type { Table } from '@mathesar/api/rpc/tables';
import {
FormSubmit,
Expand All @@ -17,6 +16,7 @@
import TableName from '@mathesar/components/TableName.svelte';
import { iconRecord, iconSave, iconUndo } from '@mathesar/icons';
import InsetPageLayout from '@mathesar/layouts/InsetPageLayout.svelte';
import { currentDatabase } from '@mathesar/stores/databases';
import type { TableStructure } from '@mathesar/stores/table-data';
import { currentTable } from '@mathesar/stores/tables';
Expand All @@ -41,9 +41,13 @@
$: form = makeForm(formFields);
function getJoinableTablesResult(tableId: number) {
return getAPI<JoinableTablesResult>(
`/api/db/v0/tables/${tableId}/joinable_tables/?max_depth=1`,
);
return api.tables
.list_joinable({
database_id: $currentDatabase.id,
table_oid: tableId,
max_depth: 1,
})
.run();
}
</script>

Expand Down
14 changes: 4 additions & 10 deletions mathesar_ui/src/pages/record/Widgets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@
export let recordSummary: string;
export let joinableTablesResult: JoinableTablesResult;
$: columnNameMap = new Map(
Object.entries(joinableTablesResult.columns).map(([columnId, column]) => [
parseInt(columnId, 10),
column.name,
]),
);
function buildWidgetInput(joinableTable: JoinableTable) {
const table = $currentTablesData.tablesMap.get(joinableTable.target);
if (!table) return undefined;
const id = joinableTable.join_path[0].slice(-1)[0];
const name = columnNameMap.get(id) ?? `(${$_('unknown_column')})`;
return { table, fkColumn: { id, name } };
const fkColumnId = joinableTable.join_path[0].slice(-1)[0][1];
const { name } =
joinableTablesResult.target_table_info[table.oid].columns[fkColumnId];
return { table, fkColumn: { id: fkColumnId, name } };
}
$: tableWidgetInputs = joinableTablesResult.joinable_tables
Expand Down
18 changes: 1 addition & 17 deletions mathesar_ui/src/stores/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import { api } from '@mathesar/api/rpc';
import type { Database } from '@mathesar/api/rpc/databases';
import type { Schema } from '@mathesar/api/rpc/schemas';
import type { JoinableTablesResult, Table } from '@mathesar/api/rpc/tables';
import type { Table } from '@mathesar/api/rpc/tables';
import { invalidIf } from '@mathesar/components/form';
import { TupleMap } from '@mathesar/packages/tuple-map';
import { preloadCommonData } from '@mathesar/utils/preloadData';
Expand Down Expand Up @@ -441,22 +441,6 @@ export const currentTable = derived(
: $tables.tablesMap.get($currentTableId),
);

export function getJoinableTablesResult(
tableId: number,
maxDepth = 1,
): Promise<JoinableTablesResult> {
return Promise.resolve({
joinable_tables: [],
tables: {},
columns: {},
});
// TODO_BETA: re-implement this with the RPC API.

// return getAPI<JoinableTablesResult>(
// `/api/db/v0/tables/${tableId}/joinable_tables/?max_depth=${maxDepth}`,
// );
}

export async function refetchTablesForCurrentSchema() {
const database = get(currentDatabase);
const schemaOid = get(currentSchemaId);
Expand Down
21 changes: 12 additions & 9 deletions mathesar_ui/src/systems/data-explorer/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
QueryRunResponse,
} from '@mathesar/api/rest/types/queries';
import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import { getAPI } from '@mathesar/api/rest/utils/requestUtils';
import { api } from '@mathesar/api/rpc';
import type { JoinableTablesResult, Table } from '@mathesar/api/rpc/tables';
import type { AbstractTypesMap } from '@mathesar/stores/abstract-types/types';
Expand Down Expand Up @@ -65,7 +64,7 @@ export default class QueryManager extends QueryRunner {

private baseTableFetchPromise: CancellablePromise<Table> | undefined;

private joinableColumnsfetchPromise:
private joinableColumnsFetchPromise:
| CancellablePromise<JoinableTablesResult>
| undefined;

Expand Down Expand Up @@ -127,8 +126,9 @@ export default class QueryManager extends QueryRunner {
}

try {
const database = get(currentDatabase);
this.baseTableFetchPromise?.cancel();
this.joinableColumnsfetchPromise?.cancel();
this.joinableColumnsFetchPromise?.cancel();

this.state.update((state) => ({
...state,
Expand All @@ -137,17 +137,20 @@ export default class QueryManager extends QueryRunner {

this.baseTableFetchPromise = api.tables
.get_with_metadata({
database_id: get(currentDatabase).id,
database_id: database.id,
table_oid: baseTableId,
})
.run();

this.joinableColumnsfetchPromise = getAPI<JoinableTablesResult>(
`/api/db/v0/tables/${baseTableId}/joinable_tables/`,
);
this.joinableColumnsFetchPromise = api.tables
.list_joinable({
database_id: database.id,
table_oid: baseTableId,
})
.run();
const [baseTableResult, joinableColumnsResult] = await Promise.all([
this.baseTableFetchPromise,
this.joinableColumnsfetchPromise,
this.joinableColumnsFetchPromise,
]);
const baseTableColumns = getBaseTableColumnsWithLinks(
joinableColumnsResult,
Expand Down Expand Up @@ -381,7 +384,7 @@ export default class QueryManager extends QueryRunner {
destroy(): void {
super.destroy();
this.baseTableFetchPromise?.cancel();
this.joinableColumnsfetchPromise?.cancel();
this.joinableColumnsFetchPromise?.cancel();
this.querySavePromise?.cancel();
}
}
Loading

0 comments on commit 27be75c

Please sign in to comment.