Skip to content

Commit

Permalink
feat(lookup): fazendo lookup cancelar requisiçoes ao fechar modal
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanPonick committed Jan 30, 2024
1 parent 535cf44 commit 836b7aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {
this.language = languageService.getShortLanguage();
}

ngOnDestroy() {
// Metodo responsavel por cancelar todas as requisiçoes pendentes
unsubscribeAllSubscriptions() {
if (this.filterSubscription) {
this.filterSubscription.unsubscribe();
}
Expand All @@ -279,6 +280,10 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {
}
}

ngOnDestroy() {
this.unsubscribeAllSubscriptions();
}

ngOnInit() {
this.setAdvancedFilterModalProperties();
this.initializeData();
Expand Down Expand Up @@ -336,6 +341,9 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {

search(): void {
this.page = 1;
if (this.isLoading) {
this.unsubscribeAllSubscriptions();
}

if (this.searchValue) {
this.isLoading = true;
Expand All @@ -348,6 +356,9 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {
}

searchFilteredItems(): void {
if (this.isLoading) {
this.unsubscribeAllSubscriptions();
}
this.searchSubscription = this.getFilteredItems(this.searchValue)
.pipe(
catchError(error => {
Expand All @@ -362,6 +373,10 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {
}

showMoreEvent() {
if (this.isLoading) {
this.unsubscribeAllSubscriptions();
}

this.page++;
this.isLoading = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[p-primary-action]="isAdvancedFilter ? primaryActionAdvancedFilter : primaryAction"
[p-secondary-action]="isAdvancedFilter ? secondaryActionAdvancedFilter : secondaryAction"
[p-title]="isAdvancedFilter ? advancedFilterModalTitle : title"
(p-close)="unsubscribeAllSubscriptions()"
>
<div [hidden]="isAdvancedFilter">
<po-field-container class="po-lookup-header po-pull-right" [p-optional]="false">
Expand Down

0 comments on commit 836b7aa

Please sign in to comment.