(core) Move cursor to new record in link target when selecting new record in link source

Summary: Update LinkingState._makeSrcCellGetter to account for 'new'

Test Plan: Extended test in RightPanelSelectBy.ts

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3037
This commit is contained in:
Alex Hall 2021-09-22 22:08:31 +02:00
parent 33f056a187
commit de76cc48d1

View File

@ -59,7 +59,7 @@ type FilterColValues = Pick<ClientQuery, "filters" | "operations">;
*/ */
export class LinkingState extends Disposable { export class LinkingState extends Disposable {
// If linking affects target section's cursor, this will be a computed for the cursor rowId. // If linking affects target section's cursor, this will be a computed for the cursor rowId.
public readonly cursorPos?: ko.Computed<number>; public readonly cursorPos?: ko.Computed<RowId>;
// If linking affects filtering, this is a computed for the current filtering state, as a // If linking affects filtering, this is a computed for the current filtering state, as a
// {[colId]: colValues} mapping, with a dependency on srcSection.activeRowId() // {[colId]: colValues} mapping, with a dependency on srcSection.activeRowId()
@ -119,7 +119,7 @@ export class LinkingState extends Disposable {
const srcValueFunc = srcColId ? this._makeSrcCellGetter() : _.identity; const srcValueFunc = srcColId ? this._makeSrcCellGetter() : _.identity;
if (srcValueFunc) { if (srcValueFunc) {
this.cursorPos = this.autoDispose(ko.computed(() => this.cursorPos = this.autoDispose(ko.computed(() =>
srcValueFunc(srcSection.activeRowId()) as number srcValueFunc(srcSection.activeRowId()) as RowId
)); ));
} }
} }
@ -178,6 +178,9 @@ export class LinkingState extends Disposable {
} }
return (rowId: RowId | null) => { return (rowId: RowId | null) => {
srcRowModel.assign(rowId); srcRowModel.assign(rowId);
if (rowId === 'new') {
return 'new';
}
return srcCellObs(); return srcCellObs();
}; };
} }