From e6104205269903c0cee10ad0f306e5541d520157 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 1 Feb 2024 23:48:35 +0100 Subject: [PATCH 1/2] fix: correctly opening creating new page when clicking "+" button --- .../entities-table.component.spec.ts | 16 ++++++++++++++++ .../entities-table/entities-table.component.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/core/common-components/entities-table/entities-table.component.spec.ts b/src/app/core/common-components/entities-table/entities-table.component.spec.ts index a56a2e91ad..ba3887961c 100644 --- a/src/app/core/common-components/entities-table/entities-table.component.spec.ts +++ b/src/app/core/common-components/entities-table/entities-table.component.spec.ts @@ -18,6 +18,7 @@ import { of } from "rxjs"; import { CoreTestingModule } from "../../../utils/core-testing.module"; import { FormDialogService } from "../../form-dialog/form-dialog.service"; import { DateDatatype } from "../../basic-datatypes/date/date.datatype"; +import { Router } from "@angular/router"; describe("EntitiesTableComponent", () => { let component: EntitiesTableComponent; @@ -273,4 +274,19 @@ describe("EntitiesTableComponent", () => { component._columns.find((c) => c.id === "children").noSorting, ).toBeTrue(); }); + + it("should navigate to '/new' route on newly created entities", () => { + const navigateSpy = spyOn(TestBed.inject(Router), "navigate"); + component.clickMode = "navigate"; + + const child = new Child(); + expect(child.isNew).toBeTrue(); + component.showEntity(child); + expect(navigateSpy).toHaveBeenCalledWith(["/child", "new"]); + + child._rev = "1-existing"; + expect(child.isNew).toBeFalse(); + component.showEntity(child); + expect(navigateSpy).toHaveBeenCalledWith(["/child", child.getId(true)]); + }); }); diff --git a/src/app/core/common-components/entities-table/entities-table.component.ts b/src/app/core/common-components/entities-table/entities-table.component.ts index 5fd398f037..5c0ef22b0d 100644 --- a/src/app/core/common-components/entities-table/entities-table.component.ts +++ b/src/app/core/common-components/entities-table/entities-table.component.ts @@ -278,7 +278,7 @@ export class EntitiesTableComponent implements AfterViewInit { case "navigate": this.router.navigate([ entity.getConstructor().route, - entity.getId(true), + entity.isNew ? "new" : entity.getId(true), ]); break; } From 687c9afe77c1c9f30ce23d67ce5940a5ce447a81 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 2 Feb 2024 00:21:25 +0100 Subject: [PATCH 2/2] moved click mode to parent component --- .../related-entities/related-entities.component.html | 1 + .../related-entities/related-entities.component.ts | 2 ++ .../related-time-period-entities.component.ts | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/core/entity-details/related-entities/related-entities.component.html b/src/app/core/entity-details/related-entities/related-entities.component.html index b54a0757d0..d333b6845b 100644 --- a/src/app/core/entity-details/related-entities/related-entities.component.html +++ b/src/app/core/entity-details/related-entities/related-entities.component.html @@ -6,4 +6,5 @@ [columnsToDisplay]="columnsToDisplay" [newRecordFactory]="createNewRecordFactory()" [showInactive]="showInactive" + [clickMode]="clickMode" > diff --git a/src/app/core/entity-details/related-entities/related-entities.component.ts b/src/app/core/entity-details/related-entities/related-entities.component.ts index 33c242cf07..e2c552b7c2 100644 --- a/src/app/core/entity-details/related-entities/related-entities.component.ts +++ b/src/app/core/entity-details/related-entities/related-entities.component.ts @@ -61,6 +61,8 @@ export class RelatedEntitiesComponent implements OnInit { @Input() showInactive: boolean; + @Input() clickMode: "popup" | "navigate" = "popup"; + data: E[]; private isArray = false; protected entityCtr: EntityConstructor; diff --git a/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.ts b/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.ts index aebec695e6..ba1a816d96 100644 --- a/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.ts +++ b/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.ts @@ -45,7 +45,6 @@ export class RelatedTimePeriodEntitiesComponent @Input() single = true; @Input() showInactive = false; - @Input() clickMode: "popup" | "navigate" = "popup"; @Input() set columns(value: FormFieldConfig[]) { this._columns = [...value, isActiveIndicator];