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

Patch layer with new api #928

Merged
merged 32 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
97f0af1
Add layer update functionality
tschumpr Dec 19, 2023
09f7c34
Add tests for new layer update
tschumpr Dec 19, 2023
48d5387
Remove unused code
tschumpr Dec 19, 2023
ed01313
Get layer data from new api
tschumpr Dec 19, 2023
78e6aaa
Merge remote-tracking branch 'origin/main' into patch-layer-with-new-api
tschumpr Dec 19, 2023
0c3556d
Remove unused attribute
tschumpr Dec 19, 2023
9bfd552
Remove unused attribute
tschumpr Dec 19, 2023
e94b499
Revert removing isFetching
tschumpr Dec 19, 2023
f20d801
Wait for new api request
tschumpr Dec 19, 2023
6ca38dd
Remove deprecated code
tschumpr Dec 19, 2023
af5c960
Wait for correct layer request
tschumpr Dec 19, 2023
c9d893c
Use more accurate names for awaited requests
tschumpr Dec 19, 2023
c1a8fc7
Remove unnecessary hasOwnProperty
tschumpr Dec 20, 2023
daa397b
Revert "Remove unnecessary hasOwnProperty"
tschumpr Dec 20, 2023
d5a974e
Merge remote-tracking branch 'origin/main' into patch-layer-with-new-api
tschumpr Dec 20, 2023
f7ace73
Wait for get-layer response
tschumpr Dec 20, 2023
ce30dd9
Merge remote-tracking branch 'origin/main' into patch-layer-with-new-api
tschumpr Jan 8, 2024
082ca38
Update cy interceptor for layer put requests
tschumpr Jan 8, 2024
e7d3a49
Remove debug log
tschumpr Jan 8, 2024
1bb96e1
Use new api to update layer
tschumpr Jan 8, 2024
241289e
Fix merge conflict
tschumpr Jan 8, 2024
aed4995
Remove requests to old api
tschumpr Jan 8, 2024
5e89d45
Remove unused attribute
tschumpr Jan 8, 2024
7b1d720
Remove unused attribute
tschumpr Jan 8, 2024
0cdb790
Sort interceptors
tschumpr Jan 8, 2024
feb9ea9
Simplify code
tschumpr Jan 8, 2024
f4e7886
Add workaround for closing profile attribute list
tschumpr Jan 8, 2024
d78d440
Update changelog
tschumpr Jan 8, 2024
fe7d54f
Simplify code
tschumpr Jan 8, 2024
a2aede7
Merge branch 'patch-layer-with-new-api' of github.com:geoadmin/suite-…
tschumpr Jan 8, 2024
6d25913
Simplify code
tschumpr Jan 8, 2024
d7024c4
Remove unnecessary IsOk assert
tschumpr Jan 8, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Changed

- Updated layer management to use the .NET API.

## v2.0.506 - 2023-12-21

### Added
Expand Down
54 changes: 52 additions & 2 deletions src/api/Controllers/LayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,58 @@ public async Task<ActionResult<Layer>> GetByIdAsync(int id)

/// <inheritdoc />
[Authorize(Policy = PolicyNames.Viewer)]
public override Task<ActionResult<Layer>> EditAsync(Layer entity)
=> base.EditAsync(entity);
public async override Task<ActionResult<Layer>> EditAsync(Layer entity)
{
if (entity == null)
{
return BadRequest(ModelState);
}

var existingLayer = Context.Layers.Include(l => l.LayerCodelists).Include(c => c.Codelists).SingleOrDefault(l => l.Id == entity.Id);
var codelistIds = entity.CodelistIds?.ToList() ?? new List<int>();
if (existingLayer != default)
{
Context.Entry(existingLayer).CurrentValues.SetValues(entity);
}
else
{
return NotFound();
}

foreach (var layerCodelist in existingLayer.LayerCodelists)
{
if (!codelistIds.Contains(layerCodelist.CodelistId))
{
Context.Remove(layerCodelist);
}
}

foreach (var id in codelistIds)
{
if (!existingLayer.LayerCodelists.Any(lc => lc.CodelistId == id))
{
var codelist = await Context.Codelists.FindAsync(id).ConfigureAwait(false);
if (codelist != null)
{
existingLayer.LayerCodelists ??= new List<LayerCodelist>();

existingLayer.LayerCodelists.Add(new LayerCodelist { Codelist = codelist, CodelistId = codelist.Id, SchemaName = codelist.Schema! });
}
}
}

try
{
await Context.UpdateChangeInformationAndSaveChangesAsync(HttpContext).ConfigureAwait(false);
return await GetByIdAsync(entity.Id).ConfigureAwait(false);
}
catch (Exception ex)
{
var errorMessage = "An error occurred while saving the entity changes.";
Logger?.LogError(ex, errorMessage);
return Problem(errorMessage);
}
}

/// <inheritdoc />
[Authorize(Policy = PolicyNames.Viewer)]
Expand Down
2 changes: 1 addition & 1 deletion src/client/cypress/e2e/editor/chronostratigraphy.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Tests for the chronostratigraphy editor.", () => {
cy.get("@borehole_id").then(id =>
login(`editor/${id}/stratigraphy/chronostratigraphy`),
);
cy.wait("@layer-by-profileId");
cy.wait("@get-layers-by-profileId");

// start editing session
cy.contains("a", "Start editing").click();
Expand Down
5 changes: 3 additions & 2 deletions src/client/cypress/e2e/editor/layerform.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("Tests for the layer form.", () => {
cy.wait("@layer");

cy.get('[data-cy="styled-layer-0"] [data-testid="ModeEditIcon"]').click();
cy.wait("@get-layer-by-id");

// fill all dropdowns with two values
cy.get('[aria-multiselectable="true"]')
Expand All @@ -26,7 +27,7 @@ describe("Tests for the layer form.", () => {
.last()
.scrollIntoView()
.click();
cy.wait("@stratigraphy_layer_edit_patch");
cy.wait("@update-layer");
});

cy.get('[aria-multiselectable="true"]')
Expand All @@ -38,7 +39,7 @@ describe("Tests for the layer form.", () => {
.find('[role="option"]')
.eq(1)
.click();
cy.wait("@stratigraphy_layer_edit_patch");
cy.wait("@update-layer");
});

const multipleDropdownValues = [];
Expand Down
22 changes: 13 additions & 9 deletions src/client/cypress/e2e/editor/lithologicalDescription.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,37 @@ describe("Tests for the lithological description column.", () => {
cy.get('[data-cy="add-layer-icon"]').click();
cy.wait("@layer");
cy.get('[data-cy="styled-layer-0"] [data-testid="ModeEditIcon"]').click();
cy.wait("@layer");
cy.wait("@get-layer-by-id");
cy.contains("Show all fields").children(".checkbox").click();
cy.get('[data-cy="depth_to"]').click().clear().type(50);
cy.wait("@stratigraphy_layer_edit_patch");
cy.get('[data-cy="toDepth"]').click().clear().type(50);
cy.wait("@update-layer");
cy.wait("@layer");
cy.get('[data-cy="styled-layer-0"] [data-testid="ClearIcon"]').click();

cy.get('[data-cy="add-layer-icon"]').click();
cy.wait("@layer");
cy.get('[data-cy="styled-layer-1"] [data-testid="ModeEditIcon"]').click();
cy.wait("@layer");
cy.wait("@get-layer-by-id");
cy.contains("Show all fields").children(".checkbox").click();
cy.get('[data-cy="depth_to"]').click().clear().type(62.5);
cy.wait("@stratigraphy_layer_edit_patch");
cy.get('[data-cy="toDepth"]').click().clear().type(62.5);
cy.wait("@update-layer");
cy.wait("@layer");
cy.get('[data-cy="styled-layer-1"] [data-testid="ClearIcon"]').click();

cy.get('[data-cy="add-layer-icon"]').click();
cy.wait("@layer");
cy.get('[data-cy="styled-layer-2"] [data-testid="ModeEditIcon"]').click();
cy.wait("@layer");
cy.wait("@get-layer-by-id");
cy.contains("Show all fields").children(".checkbox").click();
cy.get('[data-cy="depth_to"]').click().clear().type(120);
cy.wait("@stratigraphy_layer_edit_patch");
cy.get('[data-cy="toDepth"]').click().clear().type(120);
cy.wait("@update-layer");
cy.wait("@layer");
cy.get('[data-cy="styled-layer-2"] [data-testid="ClearIcon"]').click();

// workaround because close button of profile attributes is sometimes not clickable
cy.get('[data-cy="borehole-menu-item"]').click();
cy.get('[data-cy="lithology-menu-item"]').click();

// add lithological description
cy.wait("@layer");
cy.get('[data-cy="add-litho-desc-icon"]').click();
Expand Down
2 changes: 1 addition & 1 deletion src/client/cypress/e2e/editor/lithostratigraphy.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("Tests for the lithostratigraphy editor.", () => {
cy.get("@borehole_id").then(id =>
login(`editor/${id}/stratigraphy/lithostratigraphy`),
);
cy.wait("@layer-by-profileId");
cy.wait("@get-layers-by-profileId");

// start editing session
cy.contains("a", "Start editing").click();
Expand Down
7 changes: 3 additions & 4 deletions src/client/cypress/e2e/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ export const interceptApiCalls = () => {
cy.intercept("/api/v1/workflow/edit", req => {
return (req.alias = `workflow_edit_${req.body.action.toLowerCase()}`);
});
cy.intercept("/api/v1/borehole/stratigraphy/layer/edit", req => {
return (req.alias = `stratigraphy_layer_edit_${req.body.action.toLowerCase()}`);
});
cy.intercept("/api/v1/setting").as("setting");
cy.intercept("api/v1/borehole/codes").as("codes");

// Api V2
cy.intercept("/api/v2/layer?profileId=**").as("layer-by-profileId");
cy.intercept("/api/v2/layer?profileId=**").as("get-layers-by-profileId");
cy.intercept("GET", "/api/v2/layer/**").as("get-layer-by-id");
cy.intercept("PUT", "/api/v2/layer").as("update-layer");
cy.intercept("/api/v2/location/identify**").as("location");
cy.intercept("/api/v2/borehole/copy*").as("borehole_copy");
cy.intercept("/api/v2/lithologicaldescription*").as(
Expand Down
10 changes: 5 additions & 5 deletions src/client/cypress/e2e/viewer/displayLayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ describe("Test for the borehole form.", () => {
.find('[role="option"]')
.eq(1)
.click();
cy.wait("@stratigraphy_layer_edit_patch");
cy.wait("@update-layer");
});

// fill text fields
cy.get('[data-cy="depth_from"]').click().clear().type(0);
cy.get('[data-cy="depth_to"]').click().clear().type(50);
cy.get('[data-cy="uscs_original"]')
cy.get('[data-cy="fromDepth"]').click().clear().type(0);
cy.get('[data-cy="toDepth"]').click().clear().type(50);
cy.get('[data-cy="originalUscs"]')
.find("input")
.click()
.clear()
Expand All @@ -80,7 +80,7 @@ describe("Test for the borehole form.", () => {
);
})
.type("S");
cy.get('[data-cy="original_lithology"]')
cy.get('[data-cy="originalLithology"]')
.find("input")
.click()
.clear()
Expand Down
8 changes: 0 additions & 8 deletions src/client/src/api-lib/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ export function getProfileLayers(id, withValidation = false) {
});
}

// Fetch the attributes of a single layer by its id
export function getLayerAttributes(id) {
return fetch("/borehole/profile/layer", {
action: "GET",
id: id,
});
}

// Update the attributes of a single layer by its id, field name and value
export function patchProfile(id, field, value) {
return fetch("/borehole/profile/edit", {
Expand Down
13 changes: 0 additions & 13 deletions src/client/src/api-lib/actions/stratigraphy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,3 @@ export function gapLayer(id, process = 0, value = null) {
value: value,
});
}

export function patchLayer(id, field, value) {
if (field === "layer_lithology_top_bedrock") {
// Fixes discrepancy between field name in client and API.
field = "lithology_top_bedrock";
}
return fetch("/borehole/stratigraphy/layer/edit", {
action: "PATCH",
id: id,
field: field,
value: value,
});
}
danjov marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 0 additions & 4 deletions src/client/src/api-lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ import {
deleteLayer,
gapLayer,
getLayers,
patchLayer,
} from "./actions/stratigraphy";

import {
getProfile,
getProfiles,
getProfileLayers,
patchProfile,
getLayerAttributes,
} from "./actions/profile";

import { loadDomains, patchCodeConfig } from "./actions/domains";
Expand Down Expand Up @@ -166,12 +164,10 @@ export {
deleteLayer,
gapLayer,
getLayers,
patchLayer,
getProfile,
getProfiles,
getProfileLayers,
patchProfile,
getLayerAttributes,
loadDomains,
patchCodeConfig,
getWms,
Expand Down

This file was deleted.

Loading