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

Improving prime Datatable #862

Merged
merged 19 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f686d1e
Modification of the number of items per row
BenjaminCharmes Aug 30, 2024
57f2f96
Add a dynamic datatable using prime for Samples, Collections, Invento…
BenjaminCharmes Aug 30, 2024
b90e1b7
Add UI button to datatable selections for adding items to collections
BenjaminCharmes Sep 11, 2024
230f689
Allow creation of a new collection based on the selection
BenjaminCharmes Sep 12, 2024
bad0711
Fix deleteFromCollectionList deleting the wrong collection in the store
BenjaminCharmes Sep 12, 2024
ea4fb35
PrimeDataTable becomes the default version and lots of cleanup
BenjaminCharmes Sep 13, 2024
b7d94a3
wrapping of item names
BenjaminCharmes Sep 13, 2024
4494e44
Move QR code scanner inside Dynamic DataTable
BenjaminCharmes Sep 13, 2024
1ce390d
Cleaning up
BenjaminCharmes Sep 13, 2024
9d3e814
Re-add old components to run cypress e2e tests on /old routes
BenjaminCharmes Sep 16, 2024
57cdaf0
Update e2e cypress tests to work with new datatable
BenjaminCharmes Sep 17, 2024
051a4a7
Update cypress e2e tests to run on the new DataTable and remove /old …
BenjaminCharmes Sep 18, 2024
1671fdc
Update cypress e2e tests to run on the new DataTable and remove /old …
BenjaminCharmes Sep 18, 2024
9a81e18
Rename components with old names
BenjaminCharmes Sep 19, 2024
71e18c6
Fix cypress e2e equipment
BenjaminCharmes Sep 19, 2024
2cadd93
Remove bug in datatable and datatable-button
BenjaminCharmes Sep 20, 2024
02dd616
Fix filter in datatable
BenjaminCharmes Sep 20, 2024
ef5ddfa
Filter symbol green when filter is on
BenjaminCharmes Sep 23, 2024
ab1b98e
Fix double-add to a collection
BenjaminCharmes Sep 23, 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
2 changes: 2 additions & 0 deletions pydatalab/pydatalab/routes/v0_1/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def add_items_to_collection(collection_id):
"relation": None,
"type": "collections",
"immutable_id": ObjectId(collection["_id"]),
"item_id": None,
"refcode": None,
ml-evs marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down
12 changes: 7 additions & 5 deletions pydatalab/pydatalab/routes/v0_1/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def get_starting_materials():
"date": 1,
"chemform": 1,
"name": 1,
"type": 1,
"chemical_purity": 1,
"supplier": 1,
"location": 1,
Expand Down Expand Up @@ -300,7 +301,8 @@ def search_items():
nresults = request.args.get("nresults", default=100, type=int)
types = request.args.get("types", default=None)
if isinstance(types, str):
types = types.split(",") # should figure out how to parse as list automatically
# should figure out how to parse as list automatically
types = types.split(",")

match_obj = {
"$text": {"$search": query},
Expand Down Expand Up @@ -428,10 +430,10 @@ def _create_sample(
raise RuntimeError("Invalid type")
model = ITEM_MODELS[type_]

## the following code was used previously to explicitely check schema properties.
## it doesn't seem to be necessary now, with extra = "ignore" turned on in the pydantic models,
## and it breaks in instances where the models use aliases (e.g., in the starting_material model)
## so we are taking it out now, but leaving this comment in case it needs to be reverted.
# the following code was used previously to explicitely check schema properties.
# it doesn't seem to be necessary now, with extra = "ignore" turned on in the pydantic models,
# and it breaks in instances where the models use aliases (e.g., in the starting_material model)
# so we are taking it out now, but leaving this comment in case it needs to be reverted.
# schema = model.schema()
# new_sample = {k: sample_dict[k] for k in schema["properties"] if k in sample_dict}
new_sample = sample_dict
Expand Down
1 change: 1 addition & 0 deletions webapp/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
baseUrl: "http://localhost:8080",
apiUrl: "http://localhost:5001",
experimentalMemoryManagement: true,
numTestsKeptInMemory: 0,
defaultCommandTimeout: 10000,
},
component: {
Expand Down
19 changes: 8 additions & 11 deletions webapp/cypress/e2e/batchSampleFeature.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ describe("Batch sample creation", () => {
cy.verifySample("testB", "this sample has a name");
cy.verifySample("testC");

cy.deleteSample("testA");
cy.deleteSample("testB");
cy.deleteSample("testC");
cy.deleteSamples(["testA", "testB", "testC"]);
});

it("adds two valid samples", () => {
Expand Down Expand Up @@ -154,6 +152,7 @@ describe("Batch sample creation", () => {
});

it("modifies some data in the first sample", () => {
cy.get('[data-testid="search-input"]').type("baseA");
cy.findByText("baseA").click();
cy.findByLabelText("Description").type("this is a description of baseA.");
cy.findByText("Add a block").click();
Expand All @@ -166,6 +165,7 @@ describe("Batch sample creation", () => {
});

it("modifies some data in the second sample", () => {
cy.get('[data-testid="search-input"]').type("baseB");
cy.findByText("baseB").click();
cy.findByLabelText("Description").type("this is a description of baseB.");
cy.findByText("Add a block").click();
Expand Down Expand Up @@ -437,9 +437,7 @@ describe("Batch sample creation", () => {
cy.verifySample("test_2", "testing 1,2");
cy.verifySample("test_3", "testing 1,2,3");

cy.deleteSample("test_1");
cy.deleteSample("test_2");
cy.deleteSample("test_3");
cy.deleteSamples(["test_1", "test_2", "test_3"]);
});

it("uses the template id, name, and date", () => {
Expand All @@ -462,9 +460,7 @@ describe("Batch sample creation", () => {
cy.verifySample("test_6", "this is the test sample #6", "1980-02-01T05:35");
cy.verifySample("test_7", "this is the test sample #7", "1980-02-01T05:35");

cy.deleteSample("test_5");
cy.deleteSample("test_6");
cy.deleteSample("test_7");
cy.deleteSamples(["test_5", "test_6", "test_7"]);
});

it("uses the template id, name, date, copyFrom, and components", () => {
Expand Down Expand Up @@ -522,6 +518,7 @@ describe("Batch sample creation", () => {
cy.get("[data-testid=batch-modal-container]").contains("Close").click();

function checkCreatedSample(item_id) {
cy.get('[data-testid="search-input"]').type(item_id);
cy.contains(item_id).click();
cy.contains("this is a description of baseB.");
cy.get("#synthesis-information table").contains("component3");
Expand Down Expand Up @@ -652,8 +649,7 @@ describe("Batch sample creation", () => {
cy.verifySample("test2", "name2");
checkCreatedSample("test1");
checkCreatedSample("test2");
cy.deleteSample("test1");
cy.deleteSample("test2");
cy.deleteSamples(["test1", "test2"]);
});

it("checks errors on the row", () => {
Expand Down Expand Up @@ -832,6 +828,7 @@ describe("Batch cell creation", () => {
cy.verifySample("cell_3", "this is the test cell #3", "1980-02-01T23:59");

function checkCreatedCell(item_id) {
cy.get('[data-testid="search-input"]').type(item_id);
cy.contains(item_id).click();
cy.get("#pos-electrode-table").contains("comp1");
cy.get("#pos-electrode-table").contains("tagged");
Expand Down
15 changes: 11 additions & 4 deletions webapp/cypress/e2e/editPage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Edit Page", () => {

it("Adds a valid sample", () => {
cy.createSample("editable_sample", "This is a sample name", "1990-01-07T00:00");
cy.get("tr>td").eq(7).contains(0); // 0 blocks are present
cy.get("tr>td").eq(8).contains(0); // 0 blocks are present
});

it("Add some more samples, to use as components", () => {
Expand All @@ -44,19 +44,21 @@ describe("Edit Page", () => {
});

it("Checks editing the sample edit page", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.findByLabelText("Name").should("have.value", "This is a sample name");
cy.findByLabelText("Chemical formula").type("NaCoO2", { force: true });

cy.findByText("Unsaved changes");
cy.get(".fa-save").click();
cy.contains("Unsaved changes").should("not.exist");
cy.contains("Home").click();
cy.findByText("Home").click();

cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample");
cy.findByText("This is a sample name");
cy.findByText("1990-01-07");
cy.get("tbody tr:nth-of-type(3)").contains("NaCoO2"); // sorta check the formula
cy.findByText("NaCoO2"); // sorta check the formula
});

it("adds a chemical formula to component1", () => {
Expand All @@ -69,6 +71,7 @@ describe("Edit Page", () => {
});

it("adds some synthesis information", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.get("#synthesis-information .vs__search").first().type("component1");
cy.get(".vs__dropdown-menu").contains(".badge", "component1").click();
Expand Down Expand Up @@ -122,6 +125,7 @@ describe("Edit Page", () => {
});

it("deletes synthesis components and re-adds them", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.get("#synthesis-information tbody > tr:nth-of-type(1) .close").click();
cy.get("#synthesis-information tbody > tr").should("have.length", 2);
Expand Down Expand Up @@ -160,6 +164,7 @@ describe("Edit Page", () => {
});

it("tries to add a non-numeric value into quantity", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.get("#synthesis-information tbody > tr:nth-of-type(1) td:nth-of-type(2) input").type(
"100.001",
Expand Down Expand Up @@ -196,6 +201,7 @@ describe("Edit Page", () => {
});

it("Add some blocks to the sample and checks unsaved warning behavior", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.findByLabelText("Name").should("have.value", "This is a sample name");

Expand Down Expand Up @@ -237,6 +243,7 @@ describe("Edit Page", () => {
cy.contains("Unsaved changes").should("not.exist");

cy.findByText("Home").click();
cy.get("[data-testid=sample-table] tr:nth-of-type(3) > td:nth-of-type(8)").contains(2); // 2 blocks are present
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.get("[data-testid=sample-table] tr:nth-of-type(1) > td:nth-of-type(9)").contains(2); // 2 blocks are present
});
});
21 changes: 18 additions & 3 deletions webapp/cypress/e2e/equipment.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ describe("Equipment table page", () => {

it("Attempts to Add an item with the same name", () => {
cy.findByText("Add an item").click();
cy.findByLabelText("ID:").type("test_e3");
cy.get('[data-testid="create-equipment-form"]').within(() => {
cy.findByText("Add equipment").should("exist");
cy.findByLabelText("ID:").type("test_e3");
});

cy.contains("already in use").should("exist");
cy.get(".form-error a").contains("test_e3");
Expand All @@ -82,7 +85,19 @@ describe("Equipment table page", () => {
});

it("Deletes an item", function () {
cy.get("tr#test_e2 button.close").click();
cy.get("[data-testid=equipment-table]")
.contains(new RegExp("^" + "test_e2" + "$", "g"))
.parents("tr")
.find("input[type='checkbox']")
.click();

cy.get("[data-testid=delete-selected-button]").click();

cy.on("window:confirm", (text) => {
expect(text).to.contains("test_e2");
return true;
});

cy.contains("test_e2").should("not.exist");

cy.request({ url: `${API_URL}/get-item-data/test_e2`, failOnStatusCode: false }).then(
Expand Down Expand Up @@ -113,7 +128,7 @@ describe("Equipment table page", () => {

describe("Equipment edit page", () => {
beforeEach(() => {
cy.visit("/equipment/");
cy.visit("/equipment");
});

it("Checks the equipment edit page", () => {
Expand Down
32 changes: 22 additions & 10 deletions webapp/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,28 @@ Cypress.Commands.add("verifySample", (item_id, name = null, date = null) => {
});
});

Cypress.Commands.add("deleteSample", (item_id) => {
cy.log("search for and delete: " + item_id);
cy.get("[data-testid=sample-table]")
.contains(new RegExp("^" + item_id + "$", "g"))
.parents("tr")
.find("button.close")
.click();
Cypress.Commands.add("deleteSamples", (items_id) => {
cy.log("search for and delete: " + items_id);
items_id.forEach((item_id) => {
cy.get("[data-testid=sample-table]")
.contains(new RegExp("^" + item_id + "$", "g"))
.parents("tr")
.find("input[type='checkbox']")
.click();
});

cy.get("[data-testid=sample-table]")
.contains(new RegExp("^" + item_id + "$", "g"))
.should("not.exist");
cy.get("[data-testid=delete-selected-button]").click();

cy.on("window:confirm", (text) => {
expect(text).to.contains(items_id);
return true;
});

items_id.forEach((item_id) => {
cy.get("[data-testid=sample-table]")
.contains(new RegExp("^" + item_id + "$", "g"))
.should("not.exist");
});
});

Cypress.Commands.add("deleteSampleViaAPI", (item_id) => {
Expand All @@ -103,6 +114,7 @@ Cypress.Commands.add("searchAndSelectItem", (search_text, selector, clickPlus =

Cypress.Commands.add("createEquipment", (item_id, name = null, date = null) => {
cy.findByText("Add an item").click();

cy.get('[data-testid="create-equipment-form"]').within(() => {
cy.findByText("Add equipment").should("exist");
cy.findByLabelText("ID:").type(item_id);
Expand Down
17 changes: 14 additions & 3 deletions webapp/src/components/AddToCollectionModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<form class="modal-enclosure" data-testid="create-equipment-form" @submit.prevent="submitForm">
<form class="modal-enclosure" data-testid="add-to-collection-form" @submit.prevent="submitForm">
<Modal :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)">
<template #header> Add to collections </template>
<template #body>
Expand Down Expand Up @@ -38,7 +38,12 @@ import Modal from "@/components/Modal.vue";
import FormattedItemName from "@/components/FormattedItemName";
import CollectionSelect from "@/components/CollectionSelect.vue";

import { addItemsToCollection } from "@/server_fetch_utils";
import {
addItemsToCollection,
getSampleList,
getStartingMaterialList,
getEquipmentList,
} from "@/server_fetch_utils";

export default {
name: "AddToCollectionsModal",
Expand Down Expand Up @@ -70,7 +75,13 @@ export default {
await addItemsToCollection(collectionId, refcodes);
}
this.$emit("itemsUpdated");

if (this.itemsSelected.some((item) => item.type === "samples")) {
getSampleList();
} else if (this.itemsSelected.some((item) => item.type === "startingMaterials")) {
getStartingMaterialList();
} else if (this.itemsSelected.some((item) => item.type === "equipment")) {
getEquipmentList();
}
console.log("Items added successfully.");
this.$emit("update:modelValue", false);
} catch (error) {
Expand Down
3 changes: 0 additions & 3 deletions webapp/src/components/CollectionInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@
<CollectionRelationshipVisualization :collection_id="collection_id" />
</div>
</div>
<FancyCollectionSampleTable :collection_id="collection_id" />
</div>
</template>

<script>
import { createComputedSetterForCollectionField } from "@/field_utils.js";
import FancyCollectionSampleTable from "@/components/FancyCollectionSampleTable";
import TinyMceInline from "@/components/TinyMceInline";
import Creators from "@/components/Creators";
import CollectionRelationshipVisualization from "@/components/CollectionRelationshipVisualization";

export default {
components: {
TinyMceInline,
FancyCollectionSampleTable,
Creators,
CollectionRelationshipVisualization,
},
Expand Down
Loading