diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dd8cd9da..d42511274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Changed + +- Updated layer management to use the .NET API. + ## v2.0.506 - 2023-12-21 ### Added diff --git a/src/api/Controllers/LayerController.cs b/src/api/Controllers/LayerController.cs index 41469bf1b..a2f83a0bd 100644 --- a/src/api/Controllers/LayerController.cs +++ b/src/api/Controllers/LayerController.cs @@ -55,8 +55,58 @@ public async Task> GetByIdAsync(int id) /// [Authorize(Policy = PolicyNames.Viewer)] - public override Task> EditAsync(Layer entity) - => base.EditAsync(entity); + public async override Task> 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(); + 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(); + + 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); + } + } /// [Authorize(Policy = PolicyNames.Viewer)] diff --git a/src/client/cypress/e2e/editor/chronostratigraphy.cy.js b/src/client/cypress/e2e/editor/chronostratigraphy.cy.js index 8e6ca5649..67ac9c116 100644 --- a/src/client/cypress/e2e/editor/chronostratigraphy.cy.js +++ b/src/client/cypress/e2e/editor/chronostratigraphy.cy.js @@ -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(); diff --git a/src/client/cypress/e2e/editor/layerform.cy.js b/src/client/cypress/e2e/editor/layerform.cy.js index ee29f7a4b..d18b075ed 100644 --- a/src/client/cypress/e2e/editor/layerform.cy.js +++ b/src/client/cypress/e2e/editor/layerform.cy.js @@ -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"]') @@ -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"]') @@ -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 = []; diff --git a/src/client/cypress/e2e/editor/lithologicalDescription.cy.js b/src/client/cypress/e2e/editor/lithologicalDescription.cy.js index bec208c07..f4c3d0e0f 100644 --- a/src/client/cypress/e2e/editor/lithologicalDescription.cy.js +++ b/src/client/cypress/e2e/editor/lithologicalDescription.cy.js @@ -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(); diff --git a/src/client/cypress/e2e/editor/lithostratigraphy.cy.js b/src/client/cypress/e2e/editor/lithostratigraphy.cy.js index 5bffebf40..f06acca71 100644 --- a/src/client/cypress/e2e/editor/lithostratigraphy.cy.js +++ b/src/client/cypress/e2e/editor/lithostratigraphy.cy.js @@ -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(); diff --git a/src/client/cypress/e2e/testHelpers.js b/src/client/cypress/e2e/testHelpers.js index 05e622794..dfec432df 100644 --- a/src/client/cypress/e2e/testHelpers.js +++ b/src/client/cypress/e2e/testHelpers.js @@ -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( diff --git a/src/client/cypress/e2e/viewer/displayLayer.cy.js b/src/client/cypress/e2e/viewer/displayLayer.cy.js index ee545ef8b..8216870b2 100644 --- a/src/client/cypress/e2e/viewer/displayLayer.cy.js +++ b/src/client/cypress/e2e/viewer/displayLayer.cy.js @@ -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() @@ -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() diff --git a/src/client/src/api-lib/actions/profile.js b/src/client/src/api-lib/actions/profile.js index 0a93d1acf..e0c914ece 100644 --- a/src/client/src/api-lib/actions/profile.js +++ b/src/client/src/api-lib/actions/profile.js @@ -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", { diff --git a/src/client/src/api-lib/actions/stratigraphy.js b/src/client/src/api-lib/actions/stratigraphy.js index 7866808b4..0a9a4f7f3 100644 --- a/src/client/src/api-lib/actions/stratigraphy.js +++ b/src/client/src/api-lib/actions/stratigraphy.js @@ -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, - }); -} diff --git a/src/client/src/api-lib/index.js b/src/client/src/api-lib/index.js index 36a974a7d..b9f6c9319 100644 --- a/src/client/src/api-lib/index.js +++ b/src/client/src/api-lib/index.js @@ -81,7 +81,6 @@ import { deleteLayer, gapLayer, getLayers, - patchLayer, } from "./actions/stratigraphy"; import { @@ -89,7 +88,6 @@ import { getProfiles, getProfileLayers, patchProfile, - getLayerAttributes, } from "./actions/profile"; import { loadDomains, patchCodeConfig } from "./actions/domains"; @@ -166,12 +164,10 @@ export { deleteLayer, gapLayer, getLayers, - patchLayer, getProfile, getProfiles, getProfileLayers, patchProfile, - getLayerAttributes, loadDomains, patchCodeConfig, getWms, diff --git a/src/client/src/commons/form/profile/components/profileAttributes/api/index.js b/src/client/src/commons/form/profile/components/profileAttributes/api/index.js deleted file mode 100644 index 2d2556767..000000000 --- a/src/client/src/commons/form/profile/components/profileAttributes/api/index.js +++ /dev/null @@ -1,40 +0,0 @@ -import { - getLayerAttributes, - patchLayer, -} from "../../../../../../api-lib/index"; - -let data = []; -export const getData = async id => { - await getLayerAttributes(id) - .then(response => { - if (response.data.success) { - data = response.data.data; - // Fixes discrepancy between name in client and API. - data["layer_lithology_top_bedrock"] = data["lithology_top_bedrock"]; - delete data["lithology_top_bedrock"]; - } else { - alert(response.data.message); - } - }) - .catch(error => { - console.error(error); - }); - return data; -}; - -let isSendAttribute = false; -export const sendAttribute = async (id, attribute, value) => { - await patchLayer(id, attribute, value) - .then(response => { - if (response.data.success) { - isSendAttribute = true; - } else { - alert(response.data.message); - window.location.reload(); - } - }) - .catch(error => { - console.error(error); - }); - return isSendAttribute; -}; diff --git a/src/client/src/commons/form/profile/components/profileAttributes/profileAttributes.js b/src/client/src/commons/form/profile/components/profileAttributes/profileAttributes.js index c57690193..9dce30709 100644 --- a/src/client/src/commons/form/profile/components/profileAttributes/profileAttributes.js +++ b/src/client/src/commons/form/profile/components/profileAttributes/profileAttributes.js @@ -10,12 +10,15 @@ import { Checkbox } from "semantic-ui-react"; import TranslationText from "../../../translationText"; import _ from "lodash"; import { useTranslation } from "react-i18next"; -import { getData, sendAttribute } from "./api"; import ProfileAttributeList from "./components/profileAttributeList/profileAttributeList"; import { useSelector } from "react-redux"; import { useQueryClient } from "react-query"; import { AlertContext } from "../../../../alert/alertContext"; -import { layerQueryKey } from "../../../../../api/fetchApiV2"; +import { + fetchLayerById, + layerQueryKey, + updateLayer, +} from "../../../../../api/fetchApiV2"; const ProfileAttributes = props => { const { @@ -33,10 +36,7 @@ const ProfileAttributes = props => { })); const [showAll, setShowAll] = useState(false); const [state, setState] = useState({ - isFetching: false, isPatching: false, - allfields: false, - updateAttributeDelay: {}, layer: { id: id?.hasOwnProperty("id") ? id : null, kind: null, @@ -86,14 +86,37 @@ const ProfileAttributes = props => { const mounted = useRef(false); - const load = useCallback(id => { - getData(id).then(data => { - if (mounted.current) { - setState({ - isFetching: false, - layer: data, - }); - } + const mapCodelistToAttribute = (codelists, schema) => { + return codelists.filter(x => x.schema === schema).map(x => x.id); + }; + + const mapResponseToLayer = useCallback(response => { + if (response?.codelists?.length > 0) { + response["uscs_3"] = mapCodelistToAttribute( + response.codelists, + "mcla101", + ); + response["grain_shape"] = mapCodelistToAttribute( + response.codelists, + "mlpr110", + ); + response["grain_granularity"] = mapCodelistToAttribute( + response.codelists, + "mlpr115", + ); + response["organic_component"] = mapCodelistToAttribute( + response.codelists, + "mlpr108", + ); + response["debris"] = mapCodelistToAttribute( + response.codelists, + "mcla107", + ); + response["color"] = mapCodelistToAttribute(response.codelists, "mlpr112"); + } + setState({ + isPatching: false, + layer: response, }); }, []); @@ -101,7 +124,7 @@ const ProfileAttributes = props => { mounted.current = true; if (id && mounted.current) { - load(id); + fetchLayerById(id).then(mapResponseToLayer); setShowAll(false); } else if (id === null) { setState({ state: null }); @@ -109,7 +132,7 @@ const ProfileAttributes = props => { return () => { mounted.current = false; }; - }, [id, reloadAttribute, load]); + }, [id, reloadAttribute, mapResponseToLayer]); const updateChange = (attribute, value, to = true, isNumber = false) => { if (!isEditable) { @@ -120,37 +143,41 @@ const ProfileAttributes = props => { setState(prevState => ({ ...prevState, isPatching: true })); _.set(state.layer, attribute, value); - if (isNumber) { - if (value === null) { - patch(attribute, value); - } else if (/^-?\d*[.,]?\d*$/.test(value)) { - patch(attribute, _.toNumber(value)); - } - } else { - patch(attribute, value); + if (isNumber && /^-?\d*[.,]?\d*$/.test(value)) { + value = _.toNumber(value); } - }; + var updatedLayer = { + ...state.layer, + [attribute]: value, + }; - const patch = (attribute, value) => { - clearTimeout(state.updateAttributeDelay?.[attribute]); + var codelistIds = []; + if (updatedLayer["uscs_3"]) { + codelistIds = codelistIds.concat(updatedLayer["uscs_3"]); + } + if (updatedLayer["grain_shape"]) { + codelistIds = codelistIds.concat(updatedLayer["grain_shape"]); + } + if (updatedLayer["grain_granularity"]) { + codelistIds = codelistIds.concat(updatedLayer["grain_granularity"]); + } + if (updatedLayer["organic_component"]) { + codelistIds = codelistIds.concat(updatedLayer["organic_component"]); + } + if (updatedLayer["debris"]) { + codelistIds = codelistIds.concat(updatedLayer["debris"]); + } + if (updatedLayer["color"]) { + codelistIds = codelistIds.concat(updatedLayer["color"]); + } + updatedLayer["codelistIds"] = codelistIds; - let setDelay = setTimeout(() => { - sendAttribute(state?.layer?.id, attribute, value).then(response => { - if (response) { - onUpdated(attribute); - queryClient.invalidateQueries({ - queryKey: [layerQueryKey, selectedStratigraphyID], - }); - } + updateLayer(updatedLayer).then(response => { + mapResponseToLayer(response); + onUpdated(attribute); + queryClient.invalidateQueries({ + queryKey: [layerQueryKey, selectedStratigraphyID], }); - }, 500); - - Promise.resolve().then(() => { - setState(prevState => ({ - ...prevState, - isPatching: false, - updateAttributeDelay: { [attribute]: setDelay }, - })); }); }; diff --git a/src/client/src/commons/form/profile/data/casingdata.js b/src/client/src/commons/form/profile/data/casingdata.js index 47e53e01b..dcaa32603 100644 --- a/src/client/src/commons/form/profile/data/casingdata.js +++ b/src/client/src/commons/form/profile/data/casingdata.js @@ -30,7 +30,7 @@ export const casingData = { id: 0, type: "Input", label: "casingId", - value: "casing_id", + value: "casing", require: true, isVisible: true, }, @@ -38,7 +38,7 @@ export const casingData = { id: 1, type: "Input", label: "fromdepth", - value: "depth_from", + value: "fromDepth", isVisible: true, require: true, isNumber: true, @@ -47,7 +47,7 @@ export const casingData = { id: 2, type: "Input", label: "todepth", - value: "depth_to", + value: "toDepth", isVisible: true, require: true, isNumber: true, @@ -56,7 +56,7 @@ export const casingData = { id: 3, type: "Dropdown", label: "kindCasingLayer", - value: "casing_kind", + value: "casingKindId", require: true, schema: "casi200", multiple: false, @@ -67,7 +67,7 @@ export const casingData = { id: 4, type: "Dropdown", label: "materialCasingLayer", - value: "casing_material", + value: "casingMaterialId", require: true, schema: "casi201", multiple: false, @@ -78,7 +78,7 @@ export const casingData = { id: 5, type: "Date", label: "dateSpudCasing", - value: "casing_date_spud", + value: "casingDateSpud", isVisible: true, require: true, }, @@ -86,7 +86,7 @@ export const casingData = { id: 6, type: "Date", label: "dateFinishCasing", - value: "casing_date_finish", + value: "casingDateFinish", isVisible: true, require: true, }, @@ -94,7 +94,7 @@ export const casingData = { id: 7, type: "Input", label: "casing_inner_diameter", - value: "casing_inner_diameter", + value: "casingInnerDiameter", require: true, isNumber: true, isVisible: true, @@ -103,7 +103,7 @@ export const casingData = { id: 8, type: "Input", label: "casing_outer_diameter", - value: "casing_outer_diameter", + value: "casingOuterDiameter", require: true, isNumber: true, isVisible: true, diff --git a/src/client/src/commons/form/profile/data/fillingdata.js b/src/client/src/commons/form/profile/data/fillingdata.js index e06d32611..cf27a66b1 100644 --- a/src/client/src/commons/form/profile/data/fillingdata.js +++ b/src/client/src/commons/form/profile/data/fillingdata.js @@ -31,7 +31,7 @@ export const fillingData = { id: 0, type: "Input", label: "fromdepth", - value: "depth_from", + value: "fromDepth", isVisible: true, require: true, isNumber: true, @@ -40,7 +40,7 @@ export const fillingData = { id: 1, type: "Input", label: "todepth", - value: "depth_to", + value: "toDepth", isVisible: true, require: true, isNumber: true, @@ -49,7 +49,7 @@ export const fillingData = { id: 2, type: "Dropdown", label: "kindFilling", - value: "fill_kind", + value: "fillKindId", require: true, schema: "fill100", multiple: false, @@ -60,7 +60,7 @@ export const fillingData = { id: 3, type: "Dropdown", label: "materialFilling", - value: "fill_material", + value: "fillMaterialId", require: true, schema: "fill200", multiple: false, diff --git a/src/client/src/commons/form/profile/data/stratigraphydata.js b/src/client/src/commons/form/profile/data/stratigraphydata.js index 237502d2c..9e6e5c068 100644 --- a/src/client/src/commons/form/profile/data/stratigraphydata.js +++ b/src/client/src/commons/form/profile/data/stratigraphydata.js @@ -19,7 +19,7 @@ export const stratigraphyData = { id: 0, type: "Input", label: "fromdepth", - value: "depth_from", + value: "fromDepth", require: true, isNumber: true, isVisible: true, @@ -28,7 +28,7 @@ export const stratigraphyData = { id: 1, type: "Input", label: "todepth", - value: "depth_to", + value: "toDepth", require: true, isNumber: true, isVisible: true, @@ -37,7 +37,7 @@ export const stratigraphyData = { id: 2, type: "Radio", label: "layer_last", - value: "last", + value: "isLast", to: false, isVisibleValue: "layer_last", }, @@ -45,7 +45,7 @@ export const stratigraphyData = { id: 3, type: "Dropdown", label: "qt_description", - value: "qt_description", + value: "qtDescriptionId", schema: "qt_description", multiple: false, search: false, @@ -56,7 +56,7 @@ export const stratigraphyData = { id: 4, type: "DomainTree", label: "lithology", - value: "lithology", + value: "lithologyId", schema: "custom.lithology_top_bedrock", levels: { 1: "rock", @@ -71,7 +71,7 @@ export const stratigraphyData = { id: 5, type: "Input", label: "original_lithology", - value: "original_lithology", + value: "originalLithology", require: false, isVisibleValue: "original_lithology", }, @@ -79,7 +79,7 @@ export const stratigraphyData = { id: 6, type: "Input", label: "uscs_original", - value: "uscs_original", + value: "originalUscs", require: false, isVisibleValue: "uscs_original", }, @@ -87,7 +87,7 @@ export const stratigraphyData = { id: 7, type: "Dropdown", label: "uscs_determination", - value: "uscs_determination", + value: "uscsDeterminationId", schema: "mcla104", multiple: false, search: true, @@ -97,7 +97,7 @@ export const stratigraphyData = { id: 8, type: "Dropdown", label: "uscs_1", - value: "uscs_1", + value: "uscs1Id", schema: "mcla101", multiple: false, search: false, @@ -107,7 +107,7 @@ export const stratigraphyData = { id: 9, type: "Dropdown", label: "grain_size_1", - value: "grain_size_1", + value: "grainSize1Id", schema: "mlpr109", multiple: false, search: false, @@ -117,7 +117,7 @@ export const stratigraphyData = { id: 10, type: "Dropdown", label: "uscs_2", - value: "uscs_2", + value: "uscs2Id", schema: "mcla101", multiple: false, search: false, @@ -127,7 +127,7 @@ export const stratigraphyData = { id: 11, type: "Dropdown", label: "grain_size_2", - value: "grain_size_2", + value: "grainSize2Id", schema: "mlpr109", multiple: false, search: false, @@ -187,7 +187,7 @@ export const stratigraphyData = { id: 17, type: "Dropdown", label: "layer_lithology_top_bedrock", - value: "layer_lithology_top_bedrock", + value: "lithologyTopBedrockId", schema: "custom.lithology_top_bedrock", multiple: false, search: true, @@ -197,7 +197,7 @@ export const stratigraphyData = { id: 18, type: "Radio", label: "striae", - value: "striae", + value: "isStriae", to: false, isVisibleValue: "striae", }, @@ -215,7 +215,7 @@ export const stratigraphyData = { id: 20, type: "Dropdown", label: "consistance", - value: "consistance", + value: "consistanceId", schema: "mlpr103", multiple: false, search: true, @@ -225,7 +225,7 @@ export const stratigraphyData = { id: 21, type: "Dropdown", label: "plasticity", - value: "plasticity", + value: "plasticityId", schema: "mlpr101", multiple: false, search: false, @@ -235,7 +235,7 @@ export const stratigraphyData = { id: 22, type: "Dropdown", label: "compactness", - value: "compactness", + value: "compactnessId", schema: "mlpr102", multiple: false, search: false, @@ -245,7 +245,7 @@ export const stratigraphyData = { id: 23, type: "Dropdown", label: "cohesion", - value: "cohesion", + value: "cohesionId", schema: "mlpr116", multiple: false, search: false, @@ -255,7 +255,7 @@ export const stratigraphyData = { id: 24, type: "Dropdown", label: "gradation", - value: "gradation", + value: "gradationId", schema: "gradation", multiple: false, search: true, @@ -265,7 +265,7 @@ export const stratigraphyData = { id: 25, type: "Dropdown", label: "humidity", - value: "humidity", + value: "humidityId", schema: "mlpr105", multiple: false, search: false, @@ -275,7 +275,7 @@ export const stratigraphyData = { id: 26, type: "Dropdown", label: "alteration", - value: "alteration", + value: "alterationId", schema: "mlpr106", multiple: false, search: false, diff --git a/src/client/src/commons/form/profile/profile.js b/src/client/src/commons/form/profile/profile.js index ffd03ee10..7b8695556 100644 --- a/src/client/src/commons/form/profile/profile.js +++ b/src/client/src/commons/form/profile/profile.js @@ -34,15 +34,15 @@ const Profile = props => { const onUpdated = attribute => { if ( - attribute === "depth_to" || - attribute === "depth_from" || + attribute === "toDepth" || + attribute === "fromDepth" || attribute === "lithology" || attribute === "newLayer" || - attribute === "casing_kind" || - attribute === "casing_material" || - attribute === "casing_drilling" || - attribute === "fill_material" || - attribute === "fill_kind" + attribute === "casingKind" || + attribute === "casingMaterial" || + attribute === "casingDrilling" || + attribute === "fillMaterial" || + attribute === "fillKind" ) { setReloadLayer(reloadLayer => reloadLayer + 1); } diff --git a/tests/Controllers/LayerControllerTest.cs b/tests/Controllers/LayerControllerTest.cs index 3d94a3f97..05a1d3ec6 100644 --- a/tests/Controllers/LayerControllerTest.cs +++ b/tests/Controllers/LayerControllerTest.cs @@ -89,76 +89,6 @@ public async Task GetLayerById() public async Task EditLayerWithCompleteLayer() { var id = 7_000_089; - var originalLayer = new Layer - { - Alteration = null, - AlterationId = null, - Casing = "invoice overriding", - CasingDateFinish = new DateTime(2021, 5, 29, 21, 00, 00).ToUniversalTime(), - CasingDateSpud = new DateTime(2021, 7, 16, 13, 20, 25).ToUniversalTime(), - CasingInnerDiameter = 10.9742215, - CasingKind = null, - CasingKindId = null, - CasingMaterial = null, - CasingMaterialId = null, - CasingOuterDiameter = 13.89372933, - Cohesion = null, - CohesionId = 21116001, - Compactness = null, - CompactnessId = 21102007, - Consistance = null, - ConsistanceId = 21103004, - CreatedBy = null, - CreatedById = 3, - Created = new DateTime(2021, 8, 3, 6, 15, 55).ToUniversalTime(), - FillKind = null, - FillKindId = 25000302, - FillMaterial = null, - FillMaterialId = 25000306, - FromDepth = 90, - GradationId = 30000016, - GrainSize1 = null, - GrainSize1Id = 21101004, - GrainSize2 = null, - GrainSize2Id = 21103009, - Humidity = null, - HumidityId = 21105001, - Id = 7_000_089, - Instrument = "Metal", - InstrumentKind = null, - InstrumentKindId = 25000209, - InstrumentStatus = null, - InstrumentStatusId = 25000215, - InstrumentCasing = null, - InstrumentCasingId = 6_000_008, - IsLast = true, - IsStriae = true, - IsUndefined = false, - Lithology = null, - LithologyId = 15101055, - LithologyTopBedrock = null, - LithologyTopBedrockId = 15104417, - Lithostratigraphy = null, - LithostratigraphyId = null, - Notes = "Baby grow strategic haptic", - OriginalUscs = "Bedfordshire", - Plasticity = null, - PlasticityId = 21101005, - QtDescription = null, - QtDescriptionId = null, - Stratigraphy = null, - StratigraphyId = 6_000_008, - ToDepth = 100, - Updated = new DateTime(2021, 2, 14, 8, 55, 34).ToUniversalTime(), - UpdatedBy = null, - UpdatedById = 3, - Uscs1 = null, - Uscs1Id = 23101016, - Uscs2 = null, - Uscs2Id = 23101010, - UscsDetermination = null, - UscsDeterminationId = null, - }; var newLayer = new Layer { @@ -182,7 +112,7 @@ public async Task EditLayerWithCompleteLayer() ActionResultAssert.IsOk(response.Result); // Assert Updates and unchanged values - var updatedLayer = context.Layers.Single(c => c.Id == id); + var updatedLayer = ActionResultAssert.IsOkObjectResult(response.Result); Assert.AreEqual(4, updatedLayer.CreatedById); Assert.AreEqual(1, updatedLayer.UpdatedById); @@ -190,6 +120,61 @@ public async Task EditLayerWithCompleteLayer() Assert.AreEqual("Freddy ate more cake than Maria.", updatedLayer.Notes); } + [TestMethod] + public async Task EditLayerCodelists() + { + var id = 7_000_089; + + var layerWithChanges = new Layer + { + Id = id, + CreatedById = 4, + UpdatedById = 4, + Created = new DateTime(2021, 2, 14, 8, 55, 34).ToUniversalTime(), + InstrumentCasingId = 0, + Notes = "Freddy ate more cake than Maria.", + StratigraphyId = 6_000_010, + CodelistIds = new List { 23101017, 23101018, 23101001 }, + }; + + var layerToEdit = context.Layers.Include(l => l.LayerCodelists).Include(c => c.Codelists).Single(c => c.Id == id); + Assert.AreEqual(3, layerToEdit.Codelists.Count); + var codelistIds = layerToEdit.Codelists.Select(c => c.Id).ToList(); + CollectionAssert.Contains(codelistIds, 23101017); + CollectionAssert.Contains(codelistIds, 23101018); + CollectionAssert.Contains(codelistIds, 23101019); + + // Update Layer + var response = await controller.EditAsync(layerWithChanges); + + // Assert Updates and unchanged values + var updatedLayer = ActionResultAssert.IsOkObjectResult(response.Result); + Assert.AreEqual(3, updatedLayer.Codelists.Count); + codelistIds = updatedLayer.Codelists.Select(c => c.Id).ToList(); + CollectionAssert.Contains(codelistIds, 23101017); + CollectionAssert.Contains(codelistIds, 23101018); + CollectionAssert.Contains(codelistIds, 23101001); + + layerWithChanges.CodelistIds = null; + + // Update Layer + response = await controller.EditAsync(layerWithChanges); + + // Assert Updates and unchanged values + updatedLayer = ActionResultAssert.IsOkObjectResult(response.Result); + Assert.AreEqual(0, updatedLayer.Codelists.Count); + + layerWithChanges.CodelistIds = new List { 23101002 }; + + // Update Layer + response = await controller.EditAsync(layerWithChanges); + + // Assert Updates and unchanged values + updatedLayer = ActionResultAssert.IsOkObjectResult(response.Result); + Assert.AreEqual(1, updatedLayer.Codelists.Count); + Assert.AreEqual(23101002, updatedLayer.Codelists.First().Id); + } + [TestMethod] public async Task EditWithInexistentIdReturnsNotFound() {