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

Add description to column properties, frontend impl. #3219

Merged
merged 2 commits into from
Sep 25, 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/api/types/tables/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface TimeStampDisplayOptions extends Record<string, unknown> {
export interface BaseColumn {
id: number;
name: string;
description: string | null;
type: DbType;
index: number;
nullable: boolean;
Expand Down
18 changes: 18 additions & 0 deletions mathesar_ui/src/stores/table-data/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ export class ColumnsDataStore extends EventHandler<{
await this.dispatch('columnRenamed', id);
}

async updateDescription(
id: Column['id'],
description: string | null,
): Promise<void> {
await this.api.update(id, { description });
this.fetchedColumns.update((columns) =>
columns.map((column) => {
if (column.id === id) {
return {
...column,
description,
};
}
return column;
}),
);
}

async setNullabilityOfColumn(
column: Column,
nullable: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getUserProfileStoreFromContext } from '@mathesar/stores/userProfile';
import { currentDatabase } from '@mathesar/stores/databases';
import { currentSchema } from '@mathesar/stores/schemas';
import RenameColumn from './RenameColumn.svelte';
import ColumnNameAndDescription from './ColumnNameAndDescription.svelte';
import ColumnActions from './ColumnActions.svelte';
import ColumnOptions from './ColumnOptions.svelte';
import ColumnType from './ColumnType.svelte';
Expand Down Expand Up @@ -63,33 +63,35 @@
</span>
{/if}
{#if column}
<Collapsible isOpen triggerAppearance="plain">
<CollapsibleHeader
slot="header"
title="Properties"
isDbLevelConfiguration
/>
<div slot="content" class="content-container">
<RenameColumn
{column}
columnsDataStore={$tabularData.columnsDataStore}
{canExecuteDDL}
{#key column}
<Collapsible isOpen triggerAppearance="plain">
<CollapsibleHeader
slot="header"
title="Properties"
isDbLevelConfiguration
/>
{#if column.column.primary_key}
<ColumnTypeSpecifierTag {column} type="primaryKey" />
{:else}
{#if !!column.linkFk}
<ColumnTypeSpecifierTag {column} type="foreignKey" />
{/if}
<ColumnOptions
<div slot="content" class="content-container column-properties">
<ColumnNameAndDescription
{column}
columnsDataStore={$tabularData.columnsDataStore}
constraintsDataStore={$tabularData.constraintsDataStore}
{canExecuteDDL}
/>
{/if}
</div>
</Collapsible>
{#if column.column.primary_key}
<ColumnTypeSpecifierTag {column} type="primaryKey" />
{:else}
{#if !!column.linkFk}
<ColumnTypeSpecifierTag {column} type="foreignKey" />
{/if}
<ColumnOptions
{column}
columnsDataStore={$tabularData.columnsDataStore}
constraintsDataStore={$tabularData.constraintsDataStore}
{canExecuteDDL}
/>
{/if}
</div>
</Collapsible>
{/key}
{/if}

{#if column}
Expand Down Expand Up @@ -175,6 +177,12 @@
> :global(* + *) {
margin-top: 0.5rem;
}

&.column-properties {
> :global(* + *) {
margin-top: 1rem;
}
}
}

.columns-selected-count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@
toast.error(`Unable to rename column. ${getErrorMessage(error)}`);
}
}

async function handleColumnDescriptionChange(
description: string,
): Promise<void> {
try {
await columnsDataStore.updateDescription(column.id, description ?? null);
} catch (error) {
toast.error(
`Unable to update column description. ${getErrorMessage(error)}`,
);
}
}
</script>

<div class="rename-column-property-container">
<div class="column-property column-name">
<span>Name</span>
<EditableTextWithActions
initialValue={column.column.name}
Expand All @@ -46,8 +58,18 @@
/>
</div>

<div class="column-property column-description">
<span>Description</span>
<EditableTextWithActions
initialValue={column.column.description ?? ''}
onSubmit={handleColumnDescriptionChange}
isLongText
disabled={!canExecuteDDL}
/>
</div>

<style lang="scss">
.rename-column-property-container {
.column-property {
display: flex;
flex-direction: column;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

<style lang="scss">
.column-options {
padding: 1rem 0;
padding: 0.5rem 0;
display: flex;
flex-direction: column;

Expand Down