Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use ChangeDetectionStrategy.OnPush for spot components, update switch writeValue method to be synchronous

Benjamin Bädorf3c5ee2c2ce38
diff --git a/frontend/src/app/spot/components/checkbox/checkbox.component.ts b/frontend/src/app/spot/components/checkbox/checkbox.component.ts
index b54fa8965f9..7f104c83b82 100644
--- a/frontend/src/app/spot/components/checkbox/checkbox.component.ts
+++ b/frontend/src/app/spot/components/checkbox/checkbox.component.ts
@@ -7,6 +7,7 @@ import {
Input,
Output,
ViewChild,
+ ChangeDetectionStrategy,
} from '@angular/core';
import {
ControlValueAccessor,
@@ -23,6 +24,7 @@ export type SpotCheckboxState = true|false|null;
useExisting: forwardRef(() => SpotCheckboxComponent),
multi: true,
}],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SpotCheckboxComponent implements ControlValueAccessor {
@HostBinding('class.spot-checkbox') public className = true;
@@ -51,11 +53,7 @@ export class SpotCheckboxComponent implements ControlValueAccessor {
// which causes the input nativeElement to not be available yet.
setTimeout(() => {
const input = this.input.nativeElement as HTMLInputElement;
- if (value === null) {
- input.indeterminate = true;
- } else {
- input.indeterminate = false;
- }
+ input.indeterminate = value === null;
this.checked = !!value;
});
diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
index 96203793a17..bad731d70d7 100644
--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
@@ -1,4 +1,5 @@
import {
+ ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
@@ -15,6 +16,7 @@ import { findAllFocusableElementsWithin } from 'core-app/shared/helpers/focus-he
@Component({
selector: 'spot-drop-modal',
templateUrl: './drop-modal.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SpotDropModalComponent implements OnDestroy {
@HostBinding('class.spot-drop-modal') public className = true;
diff --git a/frontend/src/app/spot/components/switch/switch.component.html b/frontend/src/app/spot/components/switch/switch.component.html
index 75662dbf36a..6f6b0128da3 100644
--- a/frontend/src/app/spot/components/switch/switch.component.html
+++ b/frontend/src/app/spot/components/switch/switch.component.html
@@ -3,9 +3,9 @@
class="spot-switch--input"
[attr.name]="name"
[disabled]="disabled"
- [checked]="checked"
- (change)="onStateChange()"
[tabindex]="tabindex"
+ [ngModel]="checked"
+ (ngModelChange)="onToggle($event)"
#input
/>
<span class="spot-switch--fake"></span>
diff --git a/frontend/src/app/spot/components/switch/switch.component.ts b/frontend/src/app/spot/components/switch/switch.component.ts
index b00b4ab5a44..0661086185d 100644
--- a/frontend/src/app/spot/components/switch/switch.component.ts
+++ b/frontend/src/app/spot/components/switch/switch.component.ts
@@ -1,4 +1,5 @@
import {
+ ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
@@ -26,6 +27,7 @@ export const spotSwitchSelector = 'spot-switch';
useExisting: forwardRef(() => SpotSwitchComponent),
multi: true,
}],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SpotSwitchComponent implements ControlValueAccessor {
@HostBinding('class.spot-switch') public className = true;
@@ -56,18 +58,13 @@ export class SpotSwitchComponent implements ControlValueAccessor {
}
writeValue(value:SpotSwitchState):void {
- // This is set in a timeout because the initial value is set before the template is ready,
- // which causes the input nativeElement to not be available yet.
- setTimeout(() => {
- const input = this.input.nativeElement as HTMLInputElement;
- if (value === null) {
- input.indeterminate = true;
- } else {
- input.indeterminate = false;
- }
-
- this.checked = !!value;
- });
+ this.checked = !!value;
+ }
+
+ onToggle(value:SpotSwitchState):void {
+ this.writeValue(value);
+ this.onChange(value);
+ this.onTouched(value);
}
onChange = (_:SpotSwitchState):void => {};
diff --git a/frontend/src/app/spot/components/toggle/toggle.component.ts b/frontend/src/app/spot/components/toggle/toggle.component.ts
index f5ccd115e7f..e2d9abf640f 100644
--- a/frontend/src/app/spot/components/toggle/toggle.component.ts
+++ b/frontend/src/app/spot/components/toggle/toggle.component.ts
@@ -1,5 +1,6 @@
import {
ChangeDetectorRef,
+ ChangeDetectionStrategy,
Component,
EventEmitter,
forwardRef,
@@ -22,6 +23,7 @@ export interface SpotToggleOption<T> {
useExisting: forwardRef(() => SpotToggleComponent),
multi: true,
}],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SpotToggleComponent<T> implements ControlValueAccessor {
// TODO: These old styles will need to be replaced