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

Use cell value for fk referenced columns #3239

Merged
merged 8 commits into from
Oct 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions mathesar_ui/src/components/cell-fabric/CellFabric.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<svelte:component
this={component}
{...props}
{columnFabric}
{isActive}
{isSelectedInRange}
{disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const recordSelector = getRecordSelectorFromContext();

export let isActive: $$Props['isActive'];
export let columnFabric: $$Props['columnFabric'];
export let isSelectedInRange: $$Props['isSelectedInRange'];
export let value: $$Props['value'] = undefined;
export let searchValue: $$Props['searchValue'] = undefined;
Expand All @@ -41,8 +42,13 @@
}
event?.stopPropagation();
const result = await recordSelector.acquireUserInput({ tableId });
const linkedFkColumnId = columnFabric.linkFk?.referent_columns[0];
if (result) {
value = result.recordId;
if (linkedFkColumnId) {
value = result.record[linkedFkColumnId];
} else {
value = result.recordId;
}
setRecordSummary(String(result.recordId), result.recordSummary);
dispatch('update', { value });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@ import type {
FormattedInputProps,
NumberFormatterOptions,
SelectProps,
ComponentAndProps,
} from '@mathesar-component-library/types';
import type { DBObjectEntry } from '@mathesar/AppTypes';
import type { DateTimeFormatter } from '@mathesar/utils/date-time/types';
import type { Column } from '@mathesar/api/types/tables/columns';
import type { FkConstraint } from '@mathesar/api/types/tables/constraints';

export type CellColumnLike = Pick<
Column,
'type' | 'type_options' | 'display_options'
>;

export interface CellColumnFabric {
id: string | number;
column: CellColumnLike;
/**
* Present when the column has one single-column FK constraint. In the
* unlikely (but theoretically possible) scenario that this column has more
* than one FK constraint, the first FK constraint is referenced.
*/
linkFk?: FkConstraint;
cellComponentAndProps: ComponentAndProps;
}

export type CellValueFormatter<T> = (
value: T | null | undefined,
Expand Down Expand Up @@ -36,7 +56,7 @@ export interface PrimaryKeyCellProps

// Foreign key

export type ForeignKeyCellValue = string | number | null;
export type ForeignKeyCellValue = string | number | boolean | null;

export interface LinkedRecordCellExternalProps {
tableId: DBObjectEntry['id'];
Expand All @@ -45,6 +65,7 @@ export interface LinkedRecordCellExternalProps {
export interface LinkedRecordCellProps
extends CellTypeProps<ForeignKeyCellValue>,
LinkedRecordCellExternalProps {
columnFabric: CellColumnFabric;
recordSummary?: string;
setRecordSummary?: (recordId: string, recordSummary: string) => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { Column } from '@mathesar/api/types/tables/columns';
import type { ComponentAndProps } from '@mathesar-component-library/types';
import type { CellValueFormatter } from './components/typeDefinitions';
import type {
CellValueFormatter,
CellColumnLike as CellColumnLikeInner,
} from './components/typeDefinitions';

export type CellColumnLike = CellColumnLikeInner;

// The types here are frontend types and are
// different from db types.
Expand All @@ -20,11 +24,6 @@ export type CompoundCellDataTypes = 'array';

export type CellDataType = SimpleCellDataTypes | CompoundCellDataTypes;

export type CellColumnLike = Pick<
Column,
'type' | 'type_options' | 'display_options'
>;

export interface CellComponentFactory {
initialInputValue?: unknown;
get(
Expand Down
14 changes: 4 additions & 10 deletions mathesar_ui/src/components/cell-fabric/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type { ComponentAndProps } from '@mathesar-component-library/types';
import type { CellColumnLike } from './data-types/typeDefinitions';

export interface CellColumnFabric {
id: string | number;
column: CellColumnLike;
cellComponentAndProps: ComponentAndProps;
}

export type { CellValueFormatter } from './data-types/components/typeDefinitions';
export type {
CellColumnFabric,
CellValueFormatter,
} from './data-types/components/typeDefinitions';
11 changes: 1 addition & 10 deletions mathesar_ui/src/stores/table-data/processedColumns.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { ComponentAndProps } from '@mathesar-component-library/types';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { Column } from '@mathesar/api/types/tables/columns';
import type {
Constraint,
FkConstraint,
} from '@mathesar/api/types/tables/constraints';
import type { Constraint } from '@mathesar/api/types/tables/constraints';
import type { CellColumnFabric } from '@mathesar/components/cell-fabric/types';
import {
getCellCap,
Expand Down Expand Up @@ -39,12 +36,6 @@ export interface ProcessedColumn extends CellColumnFabric {
exclusiveConstraints: Constraint[];
/** Constraints whose columns include this column and other columns too */
sharedConstraints: Constraint[];
/**
* Present when this column has one single-column FK constraint. In the
* unlikely (but theoretically possible) scenario that this column has more
* than one FK constraint, the first FK constraint is used.
*/
linkFk: FkConstraint | undefined;
abstractType: AbstractType;
initialInputValue: unknown;
inputComponentAndProps: ComponentAndProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
template,
transitiveData: buildRecordSummariesForSheet(previewData),
});
submitResult({ recordId, recordSummary });
submitResult({ recordId, recordSummary, record });
} catch (err) {
toast.error(getErrorMessage(err));
// TODO set errors in tabularData to appear within cells
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { writable } from 'svelte/store';

import type { Column } from '@mathesar/api/types/tables/columns';
import type { DBObjectEntry } from '@mathesar/AppTypes';
import type { Result as ApiRecord } from '@mathesar/api/types/tables/records';
import type { RecordSelectorPurpose } from './recordSelectorUtils';

interface RecordSelectorControllerProps {
Expand All @@ -16,6 +17,7 @@ type FkCellValue = string | number;
export interface RecordSelectorResult {
recordId: FkCellValue;
recordSummary: string;
record: ApiRecord;
}

export class RecordSelectorController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
inputData: buildInputData(record),
transitiveData: $recordSummaries,
});
submitResult({ recordId, recordSummary });
submitResult({ recordId, recordSummary, record });
}

function submitSelection() {
Expand Down