From 102921b82614c1850ed7c572b2ec914b7b138168 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 29 Dec 2023 15:51:05 +0200 Subject: [PATCH] syncWithModel relationship param --- client/src/views/record/panels/relationship.js | 18 ++++++++++++++++++ schema/metadata/clientDefs.json | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/client/src/views/record/panels/relationship.js b/client/src/views/record/panels/relationship.js index 1367cdb2c7..8e2bbea0af 100644 --- a/client/src/views/record/panels/relationship.js +++ b/client/src/views/record/panels/relationship.js @@ -290,6 +290,24 @@ class RelationshipPanelView extends BottomPanelView { this.listenTo(this.model, 'update-all', () => collection.fetch()); + if (this.defs.syncWithModel) { + this.listenTo(this.model, 'sync', (m, a, o) => { + if (!o.patch && !o.highlight) { + // Skip if not save and not web-socket update. + return; + } + + if ( + this.collection.lastSyncPromise && + this.collection.lastSyncPromise.getReadyState() < 4 + ) { + return; + } + + this.collection.fetch(); + }); + } + const viewName = this.defs.recordListView || this.getMetadata().get(['clientDefs', this.entityType, 'recordViews', 'listRelated']) || diff --git a/schema/metadata/clientDefs.json b/schema/metadata/clientDefs.json index 0b2fe8125e..e94434837b 100644 --- a/schema/metadata/clientDefs.json +++ b/schema/metadata/clientDefs.json @@ -467,6 +467,10 @@ "selectLayout": { "type": "string", "description": "A list layout name for the select dialog." + }, + "syncWithModel": { + "type": "boolean", + "description": "Re-fetch records when the parent model is saved." } } }