Skip to content

Commit

Permalink
feat: Add tab visibility change detection when polling executions (no…
Browse files Browse the repository at this point in the history
…-changelog) (#6311)

feat: add tab visibility change detection when polling executions (no-changelog)
  • Loading branch information
alexgrozav authored and maspio committed May 25, 2023
1 parent 33b6b28 commit 7084b6f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
36 changes: 23 additions & 13 deletions packages/editor-ui/src/components/ExecutionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export default defineComponent({
},
mounted() {
setPageTitle(`n8n - ${this.pageTitle}`);
document.addEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
async created() {
await this.loadWorkflows();
Expand All @@ -354,10 +355,8 @@ export default defineComponent({
});
},
beforeDestroy() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
this.stopAutoRefreshInterval();
document.removeEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
computed: {
...mapStores(useUIStore, useWorkflowsStore),
Expand Down Expand Up @@ -412,15 +411,8 @@ export default defineComponent({
window.open(route.href, '_blank');
},
handleAutoRefreshToggle() {
if (this.autoRefreshInterval) {
// Clear any previously existing intervals (if any - there shouldn't)
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.loadAutoRefresh(), 4 * 1000); // refresh data every 4 secs
}
this.stopAutoRefreshInterval(); // Clear any previously existing intervals (if any - there shouldn't)
this.startAutoRefreshInterval();
},
handleCheckAllExistingChange() {
this.allExistingSelected = !this.allExistingSelected;
Expand Down Expand Up @@ -927,6 +919,24 @@ export default defineComponent({
this.selectAllVisibleExecutions();
}
},
startAutoRefreshInterval() {
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.loadAutoRefresh(), 4 * 1000); // refresh data every 4 secs
}
},
stopAutoRefreshInterval() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
},
onDocumentVisibilityChange() {
if (document.visibilityState === 'hidden') {
this.stopAutoRefreshInterval();
} else {
this.startAutoRefreshInterval();
}
},
},
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,38 @@ export default defineComponent({
},
mounted() {
this.autoRefresh = this.uiStore.executionSidebarAutoRefresh === true;
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.onRefresh(), 4000);
}
this.startAutoRefreshInterval();
// On larger screens, we need to load more then first page of executions
// for the scroll bar to appear and infinite scrolling is enabled
this.checkListSize();
this.scrollToActiveCard();
document.addEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
beforeDestroy() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
this.stopAutoRefreshInterval();
document.removeEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
methods: {
startAutoRefreshInterval() {
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.onRefresh(), 4000);
}
},
stopAutoRefreshInterval() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
},
onDocumentVisibilityChange() {
if (document.visibilityState === 'hidden') {
this.stopAutoRefreshInterval();
} else {
this.startAutoRefreshInterval();
}
},
loadMore(limit = 20): void {
if (!this.loading) {
const executionsListRef = this.$refs.executionList as HTMLElement | undefined;
Expand Down Expand Up @@ -169,14 +186,9 @@ export default defineComponent({
},
onAutoRefreshToggle(): void {
this.uiStore.executionSidebarAutoRefresh = this.autoRefresh;
if (this.autoRefreshInterval) {
// Clear any previously existing intervals (if any - there shouldn't)
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.onRefresh(), 4 * 1000); // refresh data every 4 secs
}
this.stopAutoRefreshInterval(); // Clear any previously existing intervals (if any - there shouldn't)
this.startAutoRefreshInterval();
},
checkListSize(): void {
const sidebarContainerRef = this.$refs.container as HTMLElement | undefined;
Expand Down

0 comments on commit 7084b6f

Please sign in to comment.