Skip to content

Commit

Permalink
[ACS-8959] Introduce new takeUntilDestroyed operator (#4237)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikiwanekhyland authored Nov 21, 2024
1 parent dec6c41 commit adda597
Show file tree
Hide file tree
Showing 52 changed files with 875 additions and 915 deletions.
3 changes: 0 additions & 3 deletions app/src/app/app.components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import { Component, ViewEncapsulation } from '@angular/core';
import { Subject } from 'rxjs';
import { AppService } from '@alfresco/aca-shared';

@Component({
Expand All @@ -33,8 +32,6 @@ import { AppService } from '@alfresco/aca-shared';
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
onDestroy$: Subject<boolean> = new Subject<boolean>();

constructor(private appService: AppService) {
this.appService.init();
}
Expand Down
811 changes: 437 additions & 374 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
},
"private": true,
"dependencies": {
"@alfresco/adf-content-services": "7.0.0-alpha.6",
"@alfresco/adf-core": "7.0.0-alpha.6",
"@alfresco/adf-extensions": "7.0.0-alpha.6",
"@alfresco/eslint-plugin-eslint-angular": "7.0.0-alpha.6",
"@alfresco/js-api": "8.0.0-alpha.6",
"@alfresco/adf-content-services": "7.0.0-alpha.6-11937616463",
"@alfresco/adf-core": "7.0.0-alpha.6-11937616463",
"@alfresco/adf-extensions": "7.0.0-alpha.6-11937616463",
"@alfresco/eslint-plugin-eslint-angular": "7.0.0-alpha.6-11937616463",
"@alfresco/js-api": "8.0.0-alpha.6-11937616463",
"@angular/animations": "16.2.9",
"@angular/cdk": "16.2.9",
"@angular/common": "16.2.9",
Expand Down Expand Up @@ -62,7 +62,7 @@
"zone.js": "0.13.3"
},
"devDependencies": {
"@alfresco/adf-cli": "7.0.0-alpha.6",
"@alfresco/adf-cli": "7.0.0-alpha.6-11937616463",
"@angular-devkit/build-angular": "16.2.9",
"@angular-devkit/core": "16.2.9",
"@angular-devkit/schematics": "16.2.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { ChangeDetectionStrategy, Component, DestroyRef, inject, OnInit, ViewEncapsulation } from '@angular/core';
import { CommonModule, Location } from '@angular/common';
import { FolderRulesService } from '../services/folder-rules.service';
import { Observable, Subject, Subscription } from 'rxjs';
import { Observable } from 'rxjs';
import { Rule } from '../model/rule.model';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { NodeInfo } from '@alfresco/aca-shared/store';
import { delay, takeUntil } from 'rxjs/operators';
import { delay } from 'rxjs/operators';
import { EditRuleDialogUiComponent } from '../rule-details/edit-rule-dialog.ui-component';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { NotificationService, TemplateModule, ToolbarModule, ConfirmDialogComponent } from '@alfresco/adf-core';
import { ConfirmDialogComponent, NotificationService, TemplateModule, ToolbarModule } from '@alfresco/adf-core';
import { ActionDefinitionTransformed } from '../model/rule-action.model';
import { ActionsService } from '../services/actions.service';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
Expand All @@ -48,6 +48,7 @@ import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatDividerModule } from '@angular/material/divider';
import { RuleListUiComponent } from '../rule-list/rule-list/rule-list.ui-component';
import { RuleDetailsUiComponent } from '../rule-details/rule-details.ui-component';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
standalone: true,
Expand Down Expand Up @@ -75,7 +76,7 @@ import { RuleDetailsUiComponent } from '../rule-details/rule-details.ui-componen
changeDetection: ChangeDetectionStrategy.Default,
host: { class: 'aca-manage-rules' }
})
export class ManageRulesSmartComponent implements OnInit, OnDestroy {
export class ManageRulesSmartComponent implements OnInit {
nodeId = '';
isInheritanceEnabled = true;
isInheritanceToggleDisabled = false;
Expand All @@ -96,8 +97,7 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
isMainRuleSetNotEmpty = false;
isInheritedRuleSetsNotEmpty = false;

private destroyed$ = new Subject<void>();
private _actionDefinitionsSub: Subscription;
private readonly destroyRef = inject(DestroyRef);

constructor(
private location: Location,
Expand All @@ -122,7 +122,7 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
this.actionDefinitions$ = this.actionsService.actionDefinitionsListing$;
this.parameterConstraints$ = this.actionsService.parameterConstraints$;

this.folderRulesService.deletedRuleId$.pipe(takeUntil(this.destroyed$)).subscribe((deletedRuleId) => this.onRuleDelete(deletedRuleId));
this.folderRulesService.deletedRuleId$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((deletedRuleId) => this.onRuleDelete(deletedRuleId));

this.actionsService.loadActionDefinitions();

Expand All @@ -137,30 +137,24 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
}
});

this._actionDefinitionsSub = this.actionDefinitions$.subscribe((actionDefinitions: ActionDefinitionTransformed[]) =>
this.actionsService.loadActionParameterConstraints(actionDefinitions)
);
this.actionDefinitions$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((actionDefinitions: ActionDefinitionTransformed[]) => this.actionsService.loadActionParameterConstraints(actionDefinitions));

this.mainRuleSet$.pipe(takeUntil(this.destroyed$)).subscribe((ruleSet) => {
this.mainRuleSet$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((ruleSet) => {
this.canEditMainRule = this.canEditRule(ruleSet);
this.isMainRuleSetNotEmpty = !!ruleSet;
});

this.inheritedRuleSets$.pipe(takeUntil(this.destroyed$)).subscribe((inheritedRuleSet) => {
this.inheritedRuleSets$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((inheritedRuleSet) => {
this.isInheritedRuleSetsNotEmpty = inheritedRuleSet.some((ruleSet) => ruleSet.rules.some((rule: Rule) => rule.isEnabled));
});

this.selectedRuleSet$.pipe(takeUntil(this.destroyed$)).subscribe((ruleSet) => {
this.selectedRuleSet$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((ruleSet) => {
this.canEditSelectedRule = this.canEditRule(ruleSet);
});
}

ngOnDestroy() {
this.destroyed$.next();
this.destroyed$.complete();
this._actionDefinitionsSub.unsubscribe();
}

goBack(): void {
this.location.back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, forwardRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { Component, DestroyRef, forwardRef, inject, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validators } from '@angular/forms';
import { ActionDefinitionTransformed, RuleAction } from '../../model/rule-action.model';
import {
Expand All @@ -37,23 +37,24 @@ import {
} from '@alfresco/adf-core';
import { ActionParameterDefinition, Category, Node, SecurityMark } from '@alfresco/js-api';
import { from, of, Subject } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { ActionParameterConstraint, ConstraintValue } from '../../model/action-parameter-constraint.model';
import {
CategorySelectorDialogComponent,
CategorySelectorDialogOptions,
CategoryService,
ContentNodeSelectorComponent,
ContentNodeSelectorComponentData,
NodeAction,
TagService,
CategorySelectorDialogComponent,
CategorySelectorDialogOptions,
SecurityControlsService
SecurityControlsService,
TagService
} from '@alfresco/adf-content-services';
import { MatDialog } from '@angular/material/dialog';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
standalone: true,
Expand All @@ -72,7 +73,7 @@ import { MatSelectModule } from '@angular/material/select';
CardViewUpdateService
]
})
export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnChanges, OnDestroy {
export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnChanges {
@Input()
nodeId = '';

Expand Down Expand Up @@ -107,7 +108,6 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh

cardViewItems: CardViewItem[] = [];
parameters: { [key: string]: unknown } = {};
private onDestroy$ = new Subject<void>();

get selectedActionDefinitionId(): string {
return this.form.get('actionDefinitionId').value;
Expand All @@ -120,6 +120,8 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
onChange: (action: RuleAction) => void = () => undefined;
onTouch: () => void = () => undefined;

private readonly destroyRef = inject(DestroyRef);

constructor(
private cardViewUpdateService: CardViewUpdateService,
private dialog: MatDialog,
Expand Down Expand Up @@ -156,7 +158,7 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
firstActionDefinition.title.localeCompare(secondActionDefinition.title)
);

this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.form.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.setDefaultParameters();
this.setCardViewProperties();
this.onChange({
Expand All @@ -166,7 +168,7 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
this.onTouch();
});

this.cardViewUpdateService.itemUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe((updateNotification: UpdateNotification) => {
this.cardViewUpdateService.itemUpdated$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((updateNotification: UpdateNotification) => {
const isSecurityGroupUpdated = updateNotification.target.key === 'securityGroupId';
if (isSecurityGroupUpdated) {
this.parameters.securityMarkId = null;
Expand Down Expand Up @@ -202,11 +204,6 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
}
}

ngOnDestroy() {
this.onDestroy$.next();
this.onDestroy$.complete();
}

setCardViewProperties(securityMarkOptions?: CardViewSelectItemOption<string>[]) {
const disabledTags = !this.tagService.areTagsEnabled();
const disabledCategories = !this.categoryService.areCategoriesEnabled();
Expand Down Expand Up @@ -338,7 +335,7 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
width: '630px'
});

data.select.pipe(takeUntil(this.onDestroy$)).subscribe((selections: Category[]) => {
data.select.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((selections: Category[]) => {
if (selections[0].id) {
this.writeValue({
actionDefinitionId: this.selectedActionDefinitionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, forwardRef, inject, Input, OnDestroy, OnInit, ViewEncapsulation, OnChanges, SimpleChanges } from '@angular/core';
import { Component, DestroyRef, forwardRef, inject, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { RuleSimpleCondition } from '../../model/rule-simple-condition.model';
import { comparatorHiddenForConditionFieldType, RuleConditionField, ruleConditionFields } from './rule-condition-fields';
Expand All @@ -34,12 +34,13 @@ import { MatSelectModule } from '@angular/material/select';
import { MatInputModule } from '@angular/material/input';
import { CategoryService, TagService } from '@alfresco/adf-content-services';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { debounceTime, distinctUntilChanged, first, takeUntil } from 'rxjs/operators';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, first } from 'rxjs/operators';
import { Subscription } from 'rxjs';
import { MatOptionModule } from '@angular/material/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { CategoryEntry } from '@alfresco/js-api';
import { AlfrescoMimeType, AppSettingsService } from '@alfresco/aca-shared';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

interface AutoCompleteOption {
displayLabel: string;
Expand Down Expand Up @@ -75,7 +76,7 @@ const AUTOCOMPLETE_OPTIONS_DEBOUNCE_TIME = 500;
}
]
})
export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAccessor, OnChanges, OnDestroy {
export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAccessor, OnChanges {
private appSettings = inject(AppSettingsService);
private categoryService = inject(CategoryService);
private tagService = inject(TagService);
Expand All @@ -92,9 +93,9 @@ export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAcces

@Input() readOnly = false;

private onDestroy$ = new Subject<void>();
private autoCompleteOptionsSubscription: Subscription;

private readonly destroyRef = inject(DestroyRef);
private readonly disabledTags = !this.tagService.areTagsEnabled();
private readonly disabledCategories = !this.categoryService.areCategoriesEnabled();

Expand Down Expand Up @@ -175,25 +176,20 @@ export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAcces
}
}

ngOnDestroy() {
this.onDestroy$.next();
this.onDestroy$.complete();
}

ngOnInit() {
this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe((value: RuleSimpleCondition) => {
this.form.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((value: RuleSimpleCondition) => {
this.onChange(value);
this.onTouch();
});

this.form
.get('field')
.valueChanges.pipe(distinctUntilChanged(), takeUntil(this.onDestroy$))
.valueChanges.pipe(distinctUntilChanged(), takeUntilDestroyed(this.destroyRef))
.subscribe((field: string) => {
if (field === 'category') {
this.autoCompleteOptionsSubscription = this.form
.get('parameter')
.valueChanges.pipe(distinctUntilChanged(), debounceTime(AUTOCOMPLETE_OPTIONS_DEBOUNCE_TIME), takeUntil(this.onDestroy$))
.valueChanges.pipe(distinctUntilChanged(), debounceTime(AUTOCOMPLETE_OPTIONS_DEBOUNCE_TIME), takeUntilDestroyed(this.destroyRef))
.subscribe((categoryName) => {
this.getCategories(categoryName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { UntypedFormGroup, UntypedFormControl, Validators, ReactiveFormsModule } from '@angular/forms';
import { Subject } from 'rxjs';
import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators';
import { Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { ReactiveFormsModule, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { Rule, RuleForForm } from '../model/rule.model';
import { ruleCompositeConditionValidator } from './validators/rule-composite-condition.validator';
import { FolderRulesService } from '../services/folder-rules.service';
Expand All @@ -41,6 +40,7 @@ import { RuleCompositeConditionUiComponent } from './conditions/rule-composite-c
import { RuleActionListUiComponent } from './actions/rule-action-list.ui-component';
import { RuleOptionsUiComponent } from './options/rule-options.ui-component';
import { CategoryService } from '@alfresco/adf-content-services';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
standalone: true,
Expand All @@ -61,7 +61,7 @@ import { CategoryService } from '@alfresco/adf-content-services';
encapsulation: ViewEncapsulation.None,
host: { class: 'aca-rule-details' }
})
export class RuleDetailsUiComponent implements OnInit, OnDestroy {
export class RuleDetailsUiComponent implements OnInit {
@Input()
readOnly: boolean;

Expand Down Expand Up @@ -115,7 +115,6 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
@Output()
formValueChanged = new EventEmitter<Partial<Rule>>();

private onDestroy$ = new Subject<void>();
form: UntypedFormGroup;

errorScriptConstraint: ActionParameterConstraint;
Expand All @@ -137,6 +136,8 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
return !this.readOnly || this.value.isAsynchronous || this.value.isInheritable;
}

private readonly destroyRef = inject(DestroyRef);

constructor(private categoryService: CategoryService) {}

ngOnInit() {
Expand Down Expand Up @@ -169,14 +170,14 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
.pipe(
map(() => this.form.valid),
distinctUntilChanged(),
takeUntil(this.onDestroy$)
takeUntilDestroyed(this.destroyRef)
)
.subscribe((value: boolean) => {
this.formValidationChanged.emit(value);
});
this.formValidationChanged.emit(this.form.valid);

this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.form.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.formValueChanged.emit(this.value);
});

Expand All @@ -194,9 +195,4 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
(parameterConstraint: ActionParameterConstraint) => parameterConstraint.name === 'script-ref'
);
}

ngOnDestroy() {
this.onDestroy$.next();
this.onDestroy$.complete();
}
}
Loading

0 comments on commit adda597

Please sign in to comment.