Skip to content

Commit

Permalink
Fix new site form not submitting with project_ids
Browse files Browse the repository at this point in the history
Following a change to the baw-server which required an array of
project_ids to be sent while site creation, the new site form started
throwing errors which stopped users from creating new sites.

This commit now sends project_ids when creating a new site, fixing the
bug which stopped users from creating new sites.

Fixes: #2143
  • Loading branch information
hudson-newey committed Sep 6, 2024
1 parent fc39563 commit 74de556
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/app/components/sites/pages/new/new.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ describe("SiteNewComponent", () => {
);
});

it("should contain the region and project id in the api calls site model", () => {
setup(defaultProject, defaultRegion);
api.create.and.callFake(() => new Subject());
const site = new Site(
generateSite(withRegion ? { regionId: defaultRegion.id } : {})
);

spec.component.submit({ ...site });

const expectedSiteModel = new Site({
...site,
projectIds: [defaultProject.id],
regionId: withRegion ? defaultRegion.id : undefined,
});

expect(api.create).toHaveBeenCalledWith(
expectedSiteModel,
defaultProject
);
});

it("should redirect to site", () => {
setup(defaultProject, defaultRegion);
const site = new Site(
Expand Down
14 changes: 13 additions & 1 deletion src/app/components/sites/pages/new/new.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Region } from "@models/Region";
import { Site } from "@models/Site";
import { List } from "immutable";
import { ToastrService } from "ngx-toastr";
import { isInstantiated } from "@helpers/isInstantiated/isInstantiated";

Check failure on line 20 in src/app/components/sites/pages/new/new.component.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest ChromeHeadless)

'isInstantiated' is defined but never used

Check failure on line 20 in src/app/components/sites/pages/new/new.component.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest FirefoxHeadless)

'isInstantiated' is defined but never used

Check failure on line 20 in src/app/components/sites/pages/new/new.component.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest ChromeHeadless)

'isInstantiated' is defined but never used

Check failure on line 20 in src/app/components/sites/pages/new/new.component.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest FirefoxHeadless)

'isInstantiated' is defined but never used
import pointSchema from "../../point.base.json";
import siteSchema from "../../site.base.json";

Expand All @@ -40,7 +41,18 @@ class SiteNewComponent extends FormTemplate<Site> implements OnInit {
successMsg: (model) => defaultSuccessMsg("created", model.name),
redirectUser: (model) =>
this.router.navigateByUrl(model.getViewUrl(this.project)),
getModel: () => (this.region ? { regionId: this.region.id } : {}),
getModel: () => {
const projectIds = new Set([this.project.id]);

if (this.region) {
return {
regionId: this.region.id,
projectIds,
};
}

return { projectIds };
},
});
}

Expand Down

0 comments on commit 74de556

Please sign in to comment.