Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly opening creating new page when clicking "+" button #2211

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>;
Expand Down Expand Up @@ -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)]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class EntitiesTableComponent<T extends Entity> implements AfterViewInit {
case "navigate":
this.router.navigate([
entity.getConstructor().route,
entity.getId(true),
entity.isNew ? "new" : entity.getId(true),
]);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
[columnsToDisplay]="columnsToDisplay"
[newRecordFactory]="createNewRecordFactory()"
[showInactive]="showInactive"
[clickMode]="clickMode"
></app-entities-table>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class RelatedEntitiesComponent<E extends Entity> implements OnInit {

@Input() showInactive: boolean;

@Input() clickMode: "popup" | "navigate" = "popup";

data: E[];
private isArray = false;
protected entityCtr: EntityConstructor<E>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class RelatedTimePeriodEntitiesComponent<E extends TimePeriod>

@Input() single = true;
@Input() showInactive = false;
@Input() clickMode: "popup" | "navigate" = "popup";

@Input() set columns(value: FormFieldConfig[]) {
this._columns = [...value, isActiveIndicator];
Expand Down
Loading