Skip to content
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

let error: string;
let currentColumn: Columns;
let editingColumn: Columns;

onMount(() => {
if (!isModal) {
Expand Down Expand Up @@ -54,7 +55,7 @@

export async function submit() {
try {
await option.update(databaseId, tableId, selectedColumn, originalKey);
await option.update(databaseId, tableId, editingColumn, originalKey);
await invalidate(Dependencies.TABLE);

if (isModal && !page.url.pathname.includes('columns')) {
Expand All @@ -65,12 +66,12 @@

addNotification({
type: 'success',
message: `Column ${selectedColumn.key} has been updated`
message: `Column ${editingColumn.key} has been updated`
});

showEdit = false;
const oldKey = originalKey;
const newKey = selectedColumn.key;
const newKey = editingColumn.key;

// TODO: these stores need to be added.
if (oldKey !== newKey && $columnsOrder.includes(oldKey)) {
Expand Down Expand Up @@ -106,17 +107,28 @@
$: onShow(showEdit);
$: title = `Update ${columnOptions.find((v) => v.name === option.name)?.sentenceName ?? ''} column`;

function deepCloneColumn(col: Columns): Columns {
return {
...col,
...('elements' in col && Array.isArray(col['elements'])
? { elements: [...col['elements']] }
: {})
} as Columns;
}

function onShow(show: boolean) {
if (show) {
currentColumn ??= { ...selectedColumn };
editingColumn = deepCloneColumn(selectedColumn);
currentColumn ??= deepCloneColumn(selectedColumn);
Comment on lines 120 to +122

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Open Sheet Keeps Stale Column

When the edit sheet is already open and selectedColumn changes without a showEdit false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte
Line: 120-122

Comment:
**Open Sheet Keeps Stale Column**

When the edit sheet is already open and `selectedColumn` changes without a `showEdit` false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

originalKey = currentColumn.key;
error = null;
} else {
currentColumn = null;
editingColumn = null;
}
}

$: $databaseColumnSheetOptions.disableSubmit = deepEqual(currentColumn, selectedColumn);
$: $databaseColumnSheetOptions.disableSubmit = deepEqual(currentColumn, editingColumn);
</script>

{#if isModal}
Expand All @@ -125,45 +137,45 @@
{option?.name}
</svelte:fragment>

{#if selectedColumn}
{#if selectedColumn?.type !== 'relationship'}
{#if editingColumn}
{#if editingColumn?.type !== 'relationship'}
<InputText
id="key"
label="Column key"
placeholder="Enter key"
bind:value={selectedColumn.key}
bind:value={editingColumn.key}
autofocus />
{/if}
{#if option}
<svelte:component
this={option.component}
editing
bind:data={selectedColumn}
bind:data={editingColumn}
onclose={() => (option = null)} />
{/if}
{/if}

<svelte:fragment slot="footer">
<Button secondary on:click={() => (showEdit = false)}>Cancel</Button>
<Button submit disabled={deepEqual(currentColumn, selectedColumn)}>Update</Button>
<Button submit disabled={deepEqual(currentColumn, editingColumn)}>Update</Button>
</svelte:fragment>
</Modal>
{:else if selectedColumn}
{:else if editingColumn}
<Layout.Stack gap="xxxl">
<Layout.Stack gap="l">
{#if selectedColumn?.type !== 'relationship'}
{#if editingColumn?.type !== 'relationship'}
<InputText
id="key"
label="Column key"
placeholder="Enter key"
bind:value={selectedColumn.key}
bind:value={editingColumn.key}
autofocus />
{/if}
{#if option}
<svelte:component
this={option.component}
editing
bind:data={selectedColumn}
bind:data={editingColumn}
onclose={() => (option = null)} />
{/if}
</Layout.Stack>
Expand Down