(core) Tests and bug fixes for bidirectional linking

Summary:
- Adding tests for bidirectional linking
- Fixing loop bug for bidirectional linking in custom widgets which use row filtering

Test Plan: New tests

Reviewers: JakubSerafin

Reviewed By: JakubSerafin

Differential Revision: https://phab.getgrist.com/D4070
This commit is contained in:
Jarosław Sadziński
2023-10-10 14:54:50 +02:00
parent a8e0f96813
commit 083a20417e
7 changed files with 439 additions and 80 deletions

View File

@@ -286,7 +286,7 @@ export class LinkingState extends Disposable {
// Get previous linkingstate's info, if applicable (2 or more hops back)
const prevLink = this._srcSection.linkingState?.();
const prevLinkHasCursor = prevLink &&
const prevLinkHasCursor = prevLink?.incomingCursorPos &&
(prevLink.linkTypeDescription() === "Cursor:Same-Table" ||
prevLink.linkTypeDescription() === "Cursor:Reference");
const [prevLinkedPos, prevLinkedVersion] = prevLinkHasCursor ? prevLink.incomingCursorPos() :

View File

@@ -156,6 +156,11 @@ function isValidLink(source: LinkNode, target: LinkNode) {
return false;
}
// If one of the section has custom row filter, we can't make cycles.
if (target.section.selectedRowsActive()) {
return false;
}
// We know our ancestors cycle back around to ourselves
// - lets walk back along the cyclic portion of the ancestor chain and verify that each link in that chain is
// a cursor-link
@@ -426,6 +431,18 @@ export class LinkConfig {
assert(srcTableId, "srcCol not a valid reference");
}
assert(srcTableId === tgtTableId, "mismatched tableIds");
// If this section has a custom link filter, it can't create cycles.
if (this.tgtSection.selectedRowsActive()) {
// Make sure we don't have a cycle.
let src = this.tgtSection.linkSrcSection();
while (!src.isDisposed() && src.getRowId()) {
assert(src.getRowId() !== this.srcSection.getRowId(),
"Sections with filter linking can't be part of a cycle (same record linking)'");
src = src.linkSrcSection();
}
}
} catch (e) {
throw new Error(`LinkConfig invalid: ` +
`${this.srcSection.getRowId()}:${this.srcCol?.getRowId()}[${srcTableId}] -> ` +