Skip to content
Merged
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 @@ -427,16 +427,23 @@
async function handleDelete() {
showDelete = false;
let hadErrors = false;
const rowIdsToDelete = selectedRowForDelete ? [selectedRowForDelete] : [...selectedRows];
const deletedRowsCount = rowIdsToDelete.length || 1;
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 The || 1 fallback is now unreachable dead code. rowIdsToDelete is built as [selectedRowForDelete] or [...selectedRows], so when any deletion occurs its length is always ≥ 1. In the original code the fallback was needed because selectedRows.length was checked separately and could be 0 when only selectedRowForDelete was set — but that split no longer exists here.

Suggested change
const deletedRowsCount = rowIdsToDelete.length || 1;
const deletedRowsCount = rowIdsToDelete.length;


try {
if (selectedRowForDelete) {
$spreadsheetLoading = true;
selectedRows = [];
selectedRowForDelete = null;
spreadsheetRenderKey.set(hash(rowIdsToDelete));

if (rowIdsToDelete.length === 1) {
await sdk.forProject(page.params.region, page.params.project).tablesDB.deleteRow({
databaseId,
tableId,
rowId: selectedRowForDelete
rowId: rowIdsToDelete[0]
});
} else {
if (selectedRows.length) {
if (rowIdsToDelete.length) {
const hasAnyRelationships = table.fields.some(isRelationship) ?? false;

const tablesSDK = sdk.forProject(
Expand All @@ -445,7 +452,7 @@
).tablesDB;

if (hasAnyRelationships) {
for (const batch of chunks(selectedRows)) {
for (const batch of chunks(rowIdsToDelete)) {
try {
await Promise.all(
batch.map((rowId) =>
Expand All @@ -469,7 +476,7 @@
});
}
} else {
for (const batch of chunks(selectedRows, 100)) {
for (const batch of chunks(rowIdsToDelete, 100)) {
await tablesSDK.deleteRows({
databaseId,
tableId,
Expand All @@ -487,24 +494,19 @@
// error is already shown above!
addNotification({
type: 'success',
message: `${selectedRows.length ? selectedRows.length : 1} row${selectedRows.length > 1 ? 's' : ''} deleted`
message: `${deletedRowsCount} row${deletedRowsCount > 1 ? 's' : ''} deleted`
});
}

spreadsheetRenderKey.set(
hash([
data.rows.total.toString(),
...(selectedRows as string[]),
selectedRowForDelete
])
);
spreadsheetRenderKey.set(hash([data.rows.total.toString(), ...rowIdsToDelete]));
} catch (error) {
addNotification({ type: 'error', message: error.message });
trackError(error, Submit.RowDelete);
} finally {
selectedRows = [];
showDelete = false;
selectedRowForDelete = null;
$spreadsheetLoading = false;
}
}

Expand Down