Skip to content

Commit

Permalink
fix bug that did not let you delete action plans with set value
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel7373 committed Jan 30, 2025
1 parent 4604ad4 commit a356177
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/check-in.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ describe('okr check-in', () => {
.click();
});

it.skip('should be able to check actions of the action plan when creating a check-in', () => {
it('should be able to check actions of the action plan when creating a check-in', () => {
keyResultDetailPage.visit('This key-result will be used for testing the action plan while creating check-ins');

keyResultDetailPage.createCheckIn()
Expand All @@ -449,7 +449,7 @@ describe('okr check-in', () => {
.should('exist');
});

it.skip('should not save action plan changes when check-in is not saved', () => {
it('should not save action plan changes when check-in is not saved', () => {
keyResultDetailPage.visit('This key-result will be used for testing the action plan while creating check-ins');

keyResultDetailPage.createCheckIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<div
class="container-fluid"
*ngFor="let item of getFormControlArray().controls!; index as i; trackBy: trackByFn"
*ngFor="let item of getFormControlArray().controls!; index as i; trackBy: identity"
[formGroupName]="i"
cdkDrag
[cdkDragDisabled]="!movable"
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/app/components/action-plan/action-plan.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { AfterContentInit, Component, ElementRef, Input, QueryList, ViewChildren } from '@angular/core';
import {
AfterContentInit, ChangeDetectorRef,
Component,
ElementRef,
Input,
QueryList,
ViewChildren
} from '@angular/core';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { trackByFn } from '../../shared/common';
import { DialogService } from '../../services/dialog.service';
import {
AbstractControl,
Expand All @@ -10,7 +16,7 @@ import {
FormControl,
FormGroup
} from '@angular/forms';
import { Observable, ReplaySubject } from 'rxjs';
import { identity, Observable, ReplaySubject } from 'rxjs';

export type FormControlsOf<T> = {
[P in keyof T]: AbstractControl<T[P]>;
Expand Down Expand Up @@ -40,7 +46,7 @@ export class ActionPlanComponent implements AfterContentInit {

@Input() addItemSubject: ReplaySubject<Item | undefined> = new ReplaySubject<Item | undefined>();

constructor(public dialogService: DialogService, private formArrayNameF: FormArrayName) {
constructor(public dialogService: DialogService, private formArrayNameF: FormArrayName, private cdRef: ChangeDetectorRef) {
}

changeItemPosition(currentIndex: number, newIndex: number) {
Expand Down Expand Up @@ -76,6 +82,13 @@ export class ActionPlanComponent implements AfterContentInit {
if (result) {
this.getFormControlArray()
.removeAt(index);
const rawValue = this.getFormControlArray()
.getRawValue() as Item[];
this.getFormControlArray()
.clear();
this.cdRef.detectChanges();
rawValue.forEach((t) => this.addNewItem(t));
this.cdRef.detectChanges();
if (item.id && this.onDelete) {
this.onDelete(item.id)
.subscribe();
Expand Down Expand Up @@ -106,13 +119,13 @@ export class ActionPlanComponent implements AfterContentInit {
event.preventDefault();
}

protected readonly trackByFn = trackByFn;

getFormControlArray() {
return this.formArrayNameF.control as FormArray<FormGroup<FormControlsOf<Item>>>;
}

ngAfterContentInit(): void {
this.addItemSubject.subscribe((item) => this.addNewItem(item));
}

protected readonly identity = identity;
}

0 comments on commit a356177

Please sign in to comment.