From 638ba17c89a03b99588241e3969edd04d3ef1a75 Mon Sep 17 00:00:00 2001 From: Kelani Tolulope Date: Tue, 11 Jul 2023 15:11:24 +0100 Subject: [PATCH] Abort ongoing backend request on a record list block when page is switched --- .../components/PageBlocks/AutomationBase.vue | 36 +- .../components/PageBlocks/CalendarBase.vue | 10 +- .../src/components/PageBlocks/CommentBase.vue | 13 +- .../components/PageBlocks/GeometryBase.vue | 10 +- .../src/components/PageBlocks/MetricBase.vue | 17 +- .../src/components/PageBlocks/RecordBase.vue | 21 +- .../components/PageBlocks/RecordListBase.vue | 34 +- .../PageBlocks/RecordOrganizerBase.vue | 18 +- .../src/components/PageBlocks/Report/Base.vue | 18 +- .../compose/src/views/Admin/Modules/Edit.vue | 16 +- .../src/views/Admin/Modules/Records/View.vue | 24 +- .../compose/src/views/Admin/Pages/Edit.vue | 24 +- .../compose/src/views/Admin/Pages/List.vue | 28 +- .../src/views/Public/Pages/Records/View.vue | 21 +- lib/js/src/api-clients/automation.ts | 336 +++ lib/js/src/api-clients/compose.ts | 1056 ++++++++++ lib/js/src/api-clients/federation.ts | 360 ++++ lib/js/src/api-clients/system.ts | 1872 +++++++++++++++++ .../types/page-block/calendar/feed-record.ts | 10 +- .../page-block/calendar/feed-reminder.ts | 4 +- .../types/page-block/geometry/feed-record.ts | 4 +- lib/js/tools/codegen/template.js | 12 + 22 files changed, 3893 insertions(+), 51 deletions(-) diff --git a/client/web/compose/src/components/PageBlocks/AutomationBase.vue b/client/web/compose/src/components/PageBlocks/AutomationBase.vue index dfa044fe08..1f5723d62c 100644 --- a/client/web/compose/src/components/PageBlocks/AutomationBase.vue +++ b/client/web/compose/src/components/PageBlocks/AutomationBase.vue @@ -40,6 +40,8 @@ export default { processing: false, automationScripts: [], + + abortRequests: [], } }, @@ -49,19 +51,37 @@ export default { }, }, + beforeDestroy () { + this.abortRequests.forEach((cancel) => { + cancel() + }) + }, + created () { if (this.$UIHooks.set && !!this.$UIHooks.set.length) { return } - this.processing = true - return this.$ComposeAPI.automationList({ eventTypes: ['onManual'], excludeInvalid: true }) - .then(({ set = [] }) => { - this.automationScripts = set - }) - .finally(() => { - this.processing = false - }) + this.fetchAutomationLists() + }, + + methods: { + fetchAutomationLists () { + this.processing = true + + const { response, cancel } = this.$ComposeAPI + .automationListCancellable({ eventTypes: ['onManual'], excludeInvalid: true }) + + this.abortRequests.push(cancel) + + return response() + .then(({ set = [] }) => { + this.automationScripts = set + }) + .finally(() => { + this.processing = false + }) + }, }, beforeDestroy () { diff --git a/client/web/compose/src/components/PageBlocks/CalendarBase.vue b/client/web/compose/src/components/PageBlocks/CalendarBase.vue index 9c9fc6c1ca..e7cc0efd3d 100644 --- a/client/web/compose/src/components/PageBlocks/CalendarBase.vue +++ b/client/web/compose/src/components/PageBlocks/CalendarBase.vue @@ -102,6 +102,7 @@ diff --git a/client/web/compose/src/components/PageBlocks/CommentBase.vue b/client/web/compose/src/components/PageBlocks/CommentBase.vue index 9678b6d093..f382cd1000 100644 --- a/client/web/compose/src/components/PageBlocks/CommentBase.vue +++ b/client/web/compose/src/components/PageBlocks/CommentBase.vue @@ -123,6 +123,8 @@ export default { title: '', content: '', }, + + abortRequests: [], } }, @@ -217,6 +219,10 @@ export default { beforeDestroy () { this.setDefaultValues() + + this.abortRequests.forEach((cancel) => { + cancel() + }) }, methods: { @@ -338,8 +344,11 @@ export default { sort, } - return this.$ComposeAPI - .recordList(params) + const { response, cancel } = this.$ComposeAPI + .recordListCancellable(params) + this.abortRequests.push(cancel) + + return response() .then(({ set }) => set.map(r => Object.freeze(new compose.Record(module, r)))) }, diff --git a/client/web/compose/src/components/PageBlocks/GeometryBase.vue b/client/web/compose/src/components/PageBlocks/GeometryBase.vue index 9963aca53e..21cf6d2c2d 100644 --- a/client/web/compose/src/components/PageBlocks/GeometryBase.vue +++ b/client/web/compose/src/components/PageBlocks/GeometryBase.vue @@ -65,6 +65,7 @@ diff --git a/client/web/compose/src/components/PageBlocks/MetricBase.vue b/client/web/compose/src/components/PageBlocks/MetricBase.vue index c279c518ae..15bd3cb585 100644 --- a/client/web/compose/src/components/PageBlocks/MetricBase.vue +++ b/client/web/compose/src/components/PageBlocks/MetricBase.vue @@ -66,6 +66,8 @@ export default { return { processing: false, reports: [], + + abortRequests: [], } }, @@ -94,6 +96,12 @@ export default { beforeDestroy () { this.setDefaultValues() this.destroyEvents() + this.$root.$off('metric.update', this.refresh) + this.$root.$off(`refetch-non-record-blocks:${this.page.pageID}`) + + this.abortRequests.forEach((cancel) => { + cancel() + }) }, created () { @@ -135,7 +143,14 @@ export default { try { const rtr = [] const namespaceID = this.namespace.namespaceID - const reporter = r => this.$ComposeAPI.recordReport({ ...r, namespaceID }) + const reporter = r => { + const { response, cancel } = this.$ComposeAPI + .recordReportCancellable({ ...r, namespaceID }) + + this.abortRequests.push(cancel) + + return response() + } for (const m of this.options.metrics) { if (m.moduleID) { diff --git a/client/web/compose/src/components/PageBlocks/RecordBase.vue b/client/web/compose/src/components/PageBlocks/RecordBase.vue index 466bd278c4..c1e1e263ba 100644 --- a/client/web/compose/src/components/PageBlocks/RecordBase.vue +++ b/client/web/compose/src/components/PageBlocks/RecordBase.vue @@ -101,6 +101,7 @@