Skip to content

Commit c24824d

Browse files
refactor/AB#82357_update-angular-fix-memory-leak-issues-and-other-fixes refactor: inner subscription in order to keep single subscription in all involved observables for front-office and web-components and app and rest of libraries fix: add missing unsubscription logic
1 parent 619c5f0 commit c24824d

File tree

49 files changed

+1248
-1009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1248
-1009
lines changed

apps/front-office/src/app/application/pages/form/form.component.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -77,50 +77,50 @@ export class FormComponent extends UnsubscribeComponent implements OnInit {
7777
* Subscribes to the route to load the form.
7878
*/
7979
ngOnInit(): void {
80-
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
81-
this.loading = true;
82-
this.id = params.id;
83-
this.isStep = this.router.url.includes('/workflow/');
84-
// If a query is already loading, cancel it
85-
if (this.querySubscription) {
86-
this.querySubscription.unsubscribe();
87-
}
88-
if (this.isStep) {
89-
this.querySubscription = this.apollo
90-
.query<StepQueryResponse>({
91-
query: GET_STEP_BY_ID,
92-
variables: {
93-
id: this.id,
94-
},
95-
})
96-
.pipe(
97-
switchMap((res) => {
98-
this.step = res.data.step;
99-
return this.getFormQuery(this.step.content ?? '');
100-
})
101-
)
102-
.subscribe(({ data, loading }) => {
103-
this.handleApplicationLoadResponse(data, loading);
104-
});
105-
} else {
106-
this.querySubscription = this.apollo
107-
.query<PageQueryResponse>({
108-
query: GET_PAGE_BY_ID,
109-
variables: {
110-
id: this.id,
111-
},
112-
})
113-
.pipe(
114-
switchMap((res) => {
115-
this.page = res.data.page;
116-
return this.getFormQuery(this.page.content ?? '');
117-
})
118-
)
119-
.subscribe(({ data, loading }) => {
120-
this.handleApplicationLoadResponse(data, loading);
121-
});
122-
}
123-
});
80+
this.querySubscription = this.route.params
81+
.pipe(
82+
switchMap((params: any) => {
83+
this.loading = true;
84+
this.id = params.id;
85+
this.isStep = this.router.url.includes('/workflow/');
86+
let currentQuery!: any;
87+
if (this.isStep) {
88+
currentQuery = this.apollo.query<StepQueryResponse>({
89+
query: GET_STEP_BY_ID,
90+
variables: {
91+
id: this.id,
92+
},
93+
});
94+
} else {
95+
currentQuery = this.apollo.query<PageQueryResponse>({
96+
query: GET_PAGE_BY_ID,
97+
variables: {
98+
id: this.id,
99+
},
100+
});
101+
}
102+
return currentQuery;
103+
}),
104+
switchMap((res: any) => {
105+
let currentFormQuery!: any;
106+
if (this.isStep) {
107+
this.step = res.data.step;
108+
currentFormQuery = this.getFormQuery(this.step?.content ?? '');
109+
} else {
110+
this.page = res.data.page;
111+
currentFormQuery = this.getFormQuery(this.page?.content ?? '');
112+
}
113+
return currentFormQuery;
114+
}),
115+
takeUntil(this.destroy$)
116+
)
117+
.subscribe((res: any) => {
118+
// If a query is already loading, cancel it
119+
if (this.querySubscription) {
120+
this.querySubscription.unsubscribe();
121+
}
122+
this.handleApplicationLoadResponse(res.data, res.loading);
123+
});
124124
}
125125

126126
/**

apps/front-office/src/app/application/pages/share/share.component.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
UnsubscribeComponent,
99
} from '@oort-front/shared';
1010
import { GET_SHARE_DASHBOARD_BY_ID } from './graphql/queries';
11-
import { takeUntil } from 'rxjs/operators';
11+
import { switchMap, takeUntil } from 'rxjs/operators';
1212
import { SnackbarService } from '@oort-front/ui';
1313

1414
/**
@@ -44,45 +44,45 @@ export class ShareComponent extends UnsubscribeComponent implements OnInit {
4444
*/
4545
ngOnInit(): void {
4646
this.route.params
47-
.pipe(takeUntil(this.destroy$))
48-
.subscribe((params: any) => {
49-
this.apollo
50-
.query<DashboardQueryResponse>({
47+
.pipe(
48+
switchMap((params: any) => {
49+
return this.apollo.query<DashboardQueryResponse>({
5150
query: GET_SHARE_DASHBOARD_BY_ID,
5251
variables: {
5352
id: params.id,
5453
},
55-
})
56-
.subscribe(({ data }) => {
57-
let url = '';
58-
const dashboard: Dashboard = data.dashboard;
59-
if (dashboard) {
60-
if (dashboard.step) {
61-
url +=
62-
'/' + data.dashboard.step?.workflow?.page?.application?.id;
63-
url += '/workflow/' + data.dashboard.step?.workflow?.id;
64-
url += '/dashboard/' + data.dashboard.id;
65-
} else {
66-
url += '/' + data.dashboard.page?.application?.id;
67-
url += '/dashboard/' + data.dashboard.id;
68-
}
69-
} else {
70-
// Error handling
71-
this.snackBar.openSnackBar(
72-
this.translateService.instant(
73-
'common.notifications.accessNotProvided',
74-
{
75-
type: this.translateService
76-
.instant('common.dashboard.one')
77-
.toLowerCase(),
78-
error: '',
79-
}
80-
),
81-
{ error: true }
82-
);
83-
}
84-
this.router.navigate([url]);
8554
});
55+
}),
56+
takeUntil(this.destroy$)
57+
)
58+
.subscribe(({ data }) => {
59+
let url = '';
60+
const dashboard: Dashboard = data.dashboard;
61+
if (dashboard) {
62+
if (dashboard.step) {
63+
url += '/' + data.dashboard.step?.workflow?.page?.application?.id;
64+
url += '/workflow/' + data.dashboard.step?.workflow?.id;
65+
url += '/dashboard/' + data.dashboard.id;
66+
} else {
67+
url += '/' + data.dashboard.page?.application?.id;
68+
url += '/dashboard/' + data.dashboard.id;
69+
}
70+
} else {
71+
// Error handling
72+
this.snackBar.openSnackBar(
73+
this.translateService.instant(
74+
'common.notifications.accessNotProvided',
75+
{
76+
type: this.translateService
77+
.instant('common.dashboard.one')
78+
.toLowerCase(),
79+
error: '',
80+
}
81+
),
82+
{ error: true }
83+
);
84+
}
85+
this.router.navigate([url]);
8686
});
8787
}
8888
}

apps/front-office/src/app/application/pages/workflow/workflow.component.ts

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@oort-front/shared';
1111
import { GET_WORKFLOW_BY_ID } from './graphql/queries';
1212
import { TranslateService } from '@ngx-translate/core';
13-
import { filter, takeUntil } from 'rxjs/operators';
13+
import { filter, switchMap, takeUntil } from 'rxjs/operators';
1414
import { SnackbarService } from '@oort-front/ui';
1515
import { Subscription } from 'rxjs';
1616

@@ -73,68 +73,67 @@ export class WorkflowComponent extends UnsubscribeComponent implements OnInit {
7373
this.onOpenStep(0);
7474
}
7575
});
76-
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
77-
this.loading = true;
78-
this.id = params.id;
79-
this.apollo
80-
.watchQuery<WorkflowQueryResponse>({
81-
query: GET_WORKFLOW_BY_ID,
82-
variables: {
83-
id: this.id,
84-
},
85-
})
86-
.valueChanges.pipe(takeUntil(this.destroy$))
87-
.subscribe({
88-
next: ({ data, loading }) => {
89-
if (data.workflow) {
90-
this.workflow = data.workflow;
91-
this.steps = data.workflow.steps || [];
92-
this.loading = loading;
93-
if (this.steps.length > 0) {
94-
const currentStepId = this.router.url.split('/').pop();
95-
// If redirect to the workflow beginning, just go to the firstStep
96-
const firstStep = this.steps[0];
97-
const firstStepIsForm = firstStep.type === ContentType.form;
98-
let currentActiveStep = 0;
99-
if (
100-
!(firstStepIsForm
101-
? firstStep.id === currentStepId
102-
: firstStep.content === currentStepId)
103-
) {
104-
// If not, URL contains the step id so redirect to the selected step (used for when refresh page or shared dashboard step link)
105-
data.workflow?.steps?.forEach((step: Step, index: number) => {
106-
const stepIsForm = step.type === ContentType.form;
107-
if (
108-
(stepIsForm && step.id === currentStepId) ||
109-
step.content === currentStepId
110-
) {
111-
currentActiveStep = index;
112-
return;
113-
}
114-
});
115-
}
116-
this.onOpenStep(currentActiveStep);
117-
}
118-
} else {
119-
this.snackBar.openSnackBar(
120-
this.translate.instant(
121-
'common.notifications.accessNotProvided',
122-
{
123-
type: this.translate
124-
.instant('common.workflow.one')
125-
.toLowerCase(),
126-
error: '',
76+
this.route.params
77+
.pipe(
78+
switchMap((params: any) => {
79+
this.loading = true;
80+
this.id = params.id;
81+
return this.apollo.watchQuery<WorkflowQueryResponse>({
82+
query: GET_WORKFLOW_BY_ID,
83+
variables: {
84+
id: this.id,
85+
},
86+
}).valueChanges;
87+
}),
88+
takeUntil(this.destroy$)
89+
)
90+
.subscribe({
91+
next: ({ data, loading }) => {
92+
if (data.workflow) {
93+
this.workflow = data.workflow;
94+
this.steps = data.workflow.steps || [];
95+
this.loading = loading;
96+
if (this.steps.length > 0) {
97+
const currentStepId = this.router.url.split('/').pop();
98+
// If redirect to the workflow beginning, just go to the firstStep
99+
const firstStep = this.steps[0];
100+
const firstStepIsForm = firstStep.type === ContentType.form;
101+
let currentActiveStep = 0;
102+
if (
103+
!(firstStepIsForm
104+
? firstStep.id === currentStepId
105+
: firstStep.content === currentStepId)
106+
) {
107+
// If not, URL contains the step id so redirect to the selected step (used for when refresh page or shared dashboard step link)
108+
data.workflow?.steps?.forEach((step: Step, index: number) => {
109+
const stepIsForm = step.type === ContentType.form;
110+
if (
111+
(stepIsForm && step.id === currentStepId) ||
112+
step.content === currentStepId
113+
) {
114+
currentActiveStep = index;
115+
return;
127116
}
128-
),
129-
{ error: true }
130-
);
117+
});
118+
}
119+
this.onOpenStep(currentActiveStep);
131120
}
132-
},
133-
error: (err) => {
134-
this.snackBar.openSnackBar(err.message, { error: true });
135-
},
136-
});
137-
});
121+
} else {
122+
this.snackBar.openSnackBar(
123+
this.translate.instant('common.notifications.accessNotProvided', {
124+
type: this.translate
125+
.instant('common.workflow.one')
126+
.toLowerCase(),
127+
error: '',
128+
}),
129+
{ error: true }
130+
);
131+
}
132+
},
133+
error: (err) => {
134+
this.snackBar.openSnackBar(err.message, { error: true });
135+
},
136+
});
138137
}
139138

140139
/**

0 commit comments

Comments
 (0)