Skip to content

Commit 7308b2a

Browse files
committed
Merge branch 'develop' of https://github.com/mathesar-foundation/mathesar into simplify-install
2 parents 2a02b3f + f398b75 commit 7308b2a

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

mathesar_ui/src/stores/table-data/records.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ export class RecordsData {
412412

413413
forEachRow((blueprint) => {
414414
if (blueprint.row.record[pkColumn.id] === undefined) {
415+
if (isDraftRecordRow(blueprint.row)) {
416+
throw new Error(
417+
'Pasting data into a selection that contains unsaved rows is not yet supported. Please open an issue if you need this feature.',
418+
);
419+
}
415420
throw new Error(
416421
'Unable to update record for a row with a missing primary key value',
417422
);
@@ -448,39 +453,39 @@ export class RecordsData {
448453
),
449454
);
450455

451-
// TODO: Fix bug - Update this for new record rows as well
452-
this.fetchedRecordRows.update((rows) =>
453-
rows.map((row) => {
454-
const responseMapValue = responseMap.get(row.identifier);
455-
if (!responseMapValue) return row;
456-
const { blueprint, response } = responseMapValue;
457-
if (response.status === 'error') {
458-
// NOTE: this is a bit weird and could potentially be improved. If we
459-
// were unable to save the record we need to indicate to the user that
460-
// all target cells in the record have failed to update. The code
461-
// below is a rather crude way of doing this. If one cells caused the
462-
// whole record to fail, then the error message will be repeated for
463-
// each cell in the record. We could potentially improve on this by
464-
// using our `extractDetailedFieldBasedErrors` utility. But we'd still
465-
// need to figure how to show some kind of errors in other cells.
466-
blueprint.cells.forEach((cell) => {
467-
const cellKey = getCellKey(row.identifier, cell.columnId);
468-
return cellStatus.set(cellKey, {
469-
state: 'failure',
470-
errors: [response],
471-
});
472-
});
473-
return row;
474-
}
475-
const result = first(response.value.results);
476-
if (!result) return row;
456+
function mutateRow<R extends RecordRow>(row: R): R {
457+
const responseMapValue = responseMap.get(row.identifier);
458+
if (!responseMapValue) return row;
459+
const { blueprint, response } = responseMapValue;
460+
if (response.status === 'error') {
461+
// NOTE: this is a bit weird and could potentially be improved. If we
462+
// were unable to save the record we need to indicate to the user that
463+
// all target cells in the record have failed to update. The code
464+
// below is a rather crude way of doing this. If one cells caused the
465+
// whole record to fail, then the error message will be repeated for
466+
// each cell in the record. We could potentially improve on this by
467+
// using our `extractDetailedFieldBasedErrors` utility. But we'd still
468+
// need to figure how to show some kind of errors in other cells.
477469
blueprint.cells.forEach((cell) => {
478470
const cellKey = getCellKey(row.identifier, cell.columnId);
479-
return cellStatus.set(cellKey, { state: 'success' });
471+
return cellStatus.set(cellKey, {
472+
state: 'failure',
473+
errors: [response],
474+
});
480475
});
481-
return row.withRecord(result);
482-
}),
483-
);
476+
return row;
477+
}
478+
const result = first(response.value.results);
479+
if (!result) return row;
480+
blueprint.cells.forEach((cell) => {
481+
const cellKey = getCellKey(row.identifier, cell.columnId);
482+
return cellStatus.set(cellKey, { state: 'success' });
483+
});
484+
return row.withRecord(result) as R;
485+
}
486+
487+
this.fetchedRecordRows.update((rows) => rows.map(mutateRow));
488+
this.newRecords.update((rows) => rows.map(mutateRow));
484489

485490
let newRecordSummaries: RecordSummariesForSheet = new ImmutableMap();
486491
for (const response of responses) {

mathesar_ui/src/systems/table-view/TableView.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
getRecordSummaries: () => get(recordsData.linkedRecordSummaries),
5353
},
5454
pastingContext: {
55-
// TODO: pasting context should also take new records into account
56-
getRecordRows: () => get(recordsData.fetchedRecordRows),
55+
getRecordRows: () => [
56+
...get(recordsData.fetchedRecordRows),
57+
...get(recordsData.newRecords),
58+
],
5759
getSheetColumns: () => [
5860
...map(({ column }) => column, get(processedColumns).values()),
5961
],

0 commit comments

Comments
 (0)