Skip to content

Commit

Permalink
Fix stiae filter (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Nov 27, 2024
2 parents 7f518dc + 9a1aec6 commit 174b7ab
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- The responsive design of the coordinate segment in the detail view was broken.
- When clicking the select all checkbox in the borehole table, only the boreholes on the current page were selected.
- Some filter chips were missing translations or where not displayed correctly.
- Filtering striae for "not specified" returned wrong results.

## v2.1.870 - 2024-09-27

Expand Down
2 changes: 1 addition & 1 deletion src/api-legacy/v1/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ def filterProfileLayers(self, filter={}):
""" % self.getIdx())

if 'striae' in keys and filter['striae'] != -1:
params.append(filter['striae'])
if filter['striae'] == None:
where.append("""
striae_lay IS NULL
""")
else:
params.append(filter['striae'])
where.append("""
striae_lay = %s
""" % self.getIdx())
Expand Down
1 change: 1 addition & 0 deletions src/api-legacy/v1/borehole/editinglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async def execute(
"""

if len(layer_params) > 0:
layer_params = [param for param in layer_params if param is not None]
joins_string = "\n".join(layer_joins) if len(
layer_joins) > 0 else ''
where_string = (
Expand Down
1 change: 1 addition & 0 deletions src/api-legacy/v1/borehole/geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def execute(self, filter={}, user=None):
wr = ''

if len(layer_params) > 0:
layer_params = [param for param in layer_params if param is not None]

joins_string = "\n".join(layer_joins) if len(layer_joins)>0 else ''

Expand Down
132 changes: 131 additions & 1 deletion src/client/cypress/e2e/filters/filter.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { showTableAndWaitForData, verifyPaginationText } from "../helpers/dataGridHelpers";
import { loginAsAdmin } from "../helpers/testHelpers.js";
import { createBorehole, createLithologyLayer, createStratigraphy, loginAsAdmin } from "../helpers/testHelpers.js";

describe("Search filter tests", () => {
it("has search filters", () => {
Expand Down Expand Up @@ -90,6 +90,136 @@ describe("Search filter tests", () => {
verifyPaginationText("1–100 of 329");
});

it("filters boreholes national_interest and striae", () => {
createBorehole({
"extended.original_name": "Borehole 1 with striae: true",
"custom.alternate_name": "striae true / null",
national_interest: false,
})
.as("borehole_id")
.then(boreholeId => {
createStratigraphy(boreholeId, 3000)
.as("stratigraphy_id")
.then(id => {
createLithologyLayer(id, { isStriae: null });
createLithologyLayer(id, { isStriae: true });
});
});

createBorehole({
"extended.original_name": "Borehole 1 with striae: false",
"custom.alternate_name": "striae false / null",
national_interest: false,
})
.as("borehole_id2")
.then(boreholeId2 => {
createStratigraphy(boreholeId2, 3000)
.as("stratigraphy_id")
.then(id => {
createLithologyLayer(id, { isStriae: false });
createLithologyLayer(id, { isStriae: null });
});
});

createBorehole({
"extended.original_name": "Borehole 2 with striae: false",
"custom.alternate_name": "striae false / null",
national_interest: false,
})
.as("borehole_id3")
.then(boreholeId3 => {
createStratigraphy(boreholeId3, 3000)
.as("stratigraphy_id")
.then(id => {
createLithologyLayer(id, { isStriae: false });
});
});

createBorehole({
"extended.original_name": "Borehole 3 with striae: false",
"custom.alternate_name": "striae false, national_interest null",
national_interest: null,
})
.as("borehole_id3")
.then(boreholeId3 => {
createStratigraphy(boreholeId3, 3000)
.as("stratigraphy_id")
.then(id => {
createLithologyLayer(id, { isStriae: false });
});
});

loginAsAdmin();
cy.get('[data-cy="show-filter-button"]').click();
cy.contains("Location").click();
cy.contains("Show all fields").children(".checkbox").click();

cy.get('[data-cy="national_interest-yes"]').click();
cy.wait("@edit_list");

showTableAndWaitForData();
verifyPaginationText("1–100 of 160");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");

cy.get('[data-cy="national_interest-np"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–1 of 1");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");

cy.get('[data-cy="national_interest-no"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–100 of 1469");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");

cy.contains("Lithology").click();
cy.contains("Show all fields").children(".checkbox").click();
cy.get('[data-cy="striae-yes"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–100 of 1401");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");
cy.get('[data-cy="filter-chip-striae"]').should("exist");

cy.get('[data-cy="striae-no"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–100 of 1402");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");
cy.get('[data-cy="filter-chip-striae"]').should("exist");

cy.get('[data-cy="striae-np"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–2 of 2");
cy.get('[data-cy="filter-chip-national_interest"]').should("exist");
cy.get('[data-cy="filter-chip-striae"]').should("exist");

// reset national interest filter
cy.get('[data-cy="filter-chip-national_interest"]')
.should("exist")
.within(() => {
cy.get("svg").click();
});

cy.wait("@edit_list");
cy.get('[data-cy="filter-chip-national_interest"]').should("not.exist");
cy.get('[data-cy="filter-chip-striae"]').should("exist");

cy.get('[data-cy="striae-no"]').click();
cy.wait("@edit_list");
verifyPaginationText("1–100 of 1555");
cy.get('[data-cy="filter-chip-national_interest"]').should("not.exist");
cy.get('[data-cy="filter-chip-striae"]').should("exist");

// reset striae filter
cy.get('[data-cy="filter-chip-striae"]')
.should("exist")
.within(() => {
cy.get("svg").click();
});

cy.get('[data-cy="filter-chip-national_interest"]').should("not.exist");
cy.get('[data-cy="filter-chip-striae"]').should("not.exist");
verifyPaginationText("1–100 of 1630");
});

it("filters boreholes by color and uscs3", () => {
loginAsAdmin();
cy.get('[data-cy="show-filter-button"]').click();
Expand Down
38 changes: 32 additions & 6 deletions src/client/cypress/e2e/helpers/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,42 @@ export const getImportFileFromFixtures = (fileName, encoding, dataSet) => {
};

export const createStratigraphy = (boreholeId, kindId) => {
cy.get("@id_token").then(token => {
return cy.get("@id_token").then(token => {
return cy
.request({
method: "POST",
url: "/api/v2/stratigraphy",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: {
boreholeId: boreholeId,
kindId: kindId,
},
auth: bearerAuth(token),
})
.then(res => {
return cy.wrap(res.body.id);
});
});
};

export const createLithologyLayer = (stratigraphyId, layer) => {
return cy.get("@id_token").then(token => {
return cy.request({
method: "POST",
url: "/api/v2/stratigraphy",
body: {
boreholeId: boreholeId,
kindId: kindId,
},
url: "/api/v2/layer",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: {
stratigraphyId: stratigraphyId,
...layer,
},
auth: bearerAuth(token),
});
});
Expand Down
8 changes: 3 additions & 5 deletions src/client/cypress/e2e/stratigraphy/chronostratigraphy.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ describe("Tests for the chronostratigraphy editor.", () => {
// Add new borehole with some lithology layers
createBorehole({ "extended.original_name": "INTEADAL" })
.as("borehole_id")
.then(id => createStratigraphy(id, 3000))
.then(response => {
expect(response).to.have.property("status", 200);

.then(id => createStratigraphy(id, 3000).as("stratigraphy_id"))
.then(stratigraphyId => {
const layers = {
layer: [
{
Expand Down Expand Up @@ -61,7 +59,7 @@ describe("Tests for the chronostratigraphy editor.", () => {
"Content-Type": "application/json",
},
body: {
stratigraphyId: response.body.id,
stratigraphyId: stratigraphyId,
...layer,
},
auth: bearerAuth(token),
Expand Down
8 changes: 3 additions & 5 deletions src/client/cypress/e2e/stratigraphy/lithostratigraphy.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ describe("Tests for the lithostratigraphy editor.", () => {
// Add new borehole with some lithology layers
createBorehole({ "extended.original_name": "INTEADAL" })
.as("borehole_id")
.then(id => createStratigraphy(id, 3000))
.then(response => {
expect(response).to.have.property("status", 200);

.then(id => createStratigraphy(id, 3000).as("stratigraphy_id"))
.then(stratigraphyId => {
[
{
lithologyId: 15104758,
Expand Down Expand Up @@ -46,7 +44,7 @@ describe("Tests for the lithostratigraphy editor.", () => {
"Content-Type": "application/json",
},
body: {
stratigraphyId: response.body.id,
stratigraphyId: stratigraphyId,
...layer,
},
auth: bearerAuth(token),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const FilterChips = ({ activeFilters, setFilter }: FilterChipsProps) => {
const { t } = useTranslation();
const { filterPolygon, setFilterPolygon, setFeatureIds, setPolygonSelectionEnabled } = useContext(FilterContext);

const boolFilterKeys = ["national_interest", "groundwater", "striae"];

const onRemoveFilter = (filter: Filter) => {
if (typeof filter.value === "boolean") {
if (boolFilterKeys.includes(filter.key)) {
setFilter(filter.key, -1);
} else if (typeof filter.value === "number") {
setFilter(filter.key, null);
Expand Down Expand Up @@ -46,7 +48,7 @@ const FilterChips = ({ activeFilters, setFilter }: FilterChipsProps) => {
<Tooltip key={index} title={filterLabel.length > 15 && filterLabel}>
<Chip
sx={{ marginRight: "10px", marginBottom: "10px" }}
data-cy="filter-chip"
data-cy={`filter-chip-${filter.key}`}
color="secondary"
label={filterLabel.length < 15 ? filterLabel : filterLabel.substring(0, 15) + "..."}
onDelete={() => onRemoveFilter(filter)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const ListFilter = props => {
<Form.Radio
checked={search.filter?.[item.value] === true}
label={t("yes")}
data-cy={`${item.label}-yes`}
onChange={() => updateChange(item.value, true, item?.to)}
style={{
paddingRight: "10px",
Expand All @@ -107,12 +108,14 @@ const ListFilter = props => {
<Form.Radio
checked={search.filter?.[item.value] === false}
label={t("no")}
data-cy={`${item.label}-no`}
onChange={() => updateChange(item.value, false, item?.to)}
style={{ paddingRight: "10px" }}
/>
<Form.Radio
checked={search.filter?.[item.value] === null}
label={t("np")}
data-cy={`${item.label}-np`}
onChange={() => updateChange(item.value, null, item?.to)}
/>
</>
Expand Down

0 comments on commit 174b7ab

Please sign in to comment.