Skip to content

Commit

Permalink
Filter symbol green when filter is on
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes committed Sep 23, 2024
1 parent 02dd616 commit ef5ddfa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
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
8 changes: 4 additions & 4 deletions webapp/src/components/CollectionSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@search="debouncedAsyncSearch"
>
<template #no-options="{ searching }">
<span v-if="searching"> Sorry, no matches found. </span>
<span v-if="searching"> Collection already selected </span>
<span v-else class="empty-search"> Search for a collection... </span>
</template>
<template #option="{ collection_id, title }">
Expand All @@ -20,7 +20,7 @@
enable-modified-click
:max-length="formattedItemNameMaxLength"
/>
<div v-else @click.prevent="handleCreateNewCollection">
<div v-else @click="handleCreateNewCollection">
{{ title }}
</div>
</template>
Expand Down Expand Up @@ -77,7 +77,8 @@ export default {
collectionOrNewCollection() {
if (
this.searchQuery &&
!this.collections.some((item) => item.collection_id === this.searchQuery)
!this.collections.some((item) => item.collection_id === this.searchQuery) &&
!this.value.some((item) => item.collection_id === this.searchQuery)
) {
return [
...this.collections,
Expand Down Expand Up @@ -130,7 +131,6 @@ export default {
},
];
}
await this.debouncedAsyncSearch(this.searchQuery, () => {});
} catch (error) {
console.error("Error:", error);
alert("An error occurred while creating the collection. Please try again.");
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/CollectionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
data() {
return {
collectionColumn: [
{ field: "collection_id", header: "ID", body: "FormattedItemName", filter: true },
{ field: "collection_id", header: "ID", body: "FormattedCollectionName", filter: true },
{ field: "title", header: "Title" },
{ field: "creators", header: "Creators", body: "Creators" },
],
Expand Down
31 changes: 28 additions & 3 deletions webapp/src/components/DynamicDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<DataTable
v-model:filters="filters"
v-model:selection="itemsSelected"
selection-mode="multiple"
:value="data"
:data-testid="computedDataTestId"
selection-mode="multiple"
paginator
:rows="20"
:rows-per-page-options="[10, 20, 50, 100]"
Expand Down Expand Up @@ -47,6 +47,7 @@
:field="column.field"
:header="column.header"
sortable
:class="{ 'filter-active': isFilterActive(column.field) }"
>
<!-- <template v-if="column.field === 'item_id'" #body="slotProps">
<component
Expand Down Expand Up @@ -110,6 +111,7 @@ import AddToCollectionModal from "@/components/AddToCollectionModal";
import { INVENTORY_TABLE_TYPES, EDITABLE_INVENTORY } from "@/resources.js";
import FormattedItemName from "@/components/FormattedItemName";
import FormattedCollectionName from "@/components/FormattedCollectionName";
import ChemicalFormula from "@/components/ChemicalFormula";
import CollectionList from "@/components/CollectionList";
import Creators from "@/components/Creators";
Expand All @@ -132,6 +134,7 @@ export default {
Column,
InputText,
FormattedItemName,
FormattedCollectionName,
ChemicalFormula,
CollectionList,
Creators,
Expand Down Expand Up @@ -193,10 +196,14 @@ export default {
return dataTestIdMap[this.dataType] || "default-table";
},
},
watch: {
itemsSelected(newSelection) {
console.log("Selected items:", newSelection);
},
},
created() {
this.editable_inventory = EDITABLE_INVENTORY;
},
methods: {
goToEditPage(event) {
const { item_id, collection_id } = event.data;
Expand All @@ -210,10 +217,14 @@ export default {
getComponentProps(componentName, data) {
const propsConfig = {
FormattedItemName: {
item_id: data.item_id !== undefined ? "item_id" : "collection_id",
item_id: "item_id",
itemType: "type",
enableModifiedClick: true,
},
FormattedCollectionName: {
collection_id: "collection_id",
enableModifiedClick: true,
},
ChemicalFormula: {
formula: "chemform",
},
Expand Down Expand Up @@ -246,6 +257,13 @@ export default {
return props;
},
isFilterActive(field) {
const filter = this.filters[field];
if (filter && filter.constraints) {
return filter.constraints.some((constraint) => constraint.value);
}
return false;
},
deleteSelectedItems() {
this.itemsSelected = [];
},
Expand Down Expand Up @@ -286,4 +304,11 @@ export default {
.button-right {
gap: 0.5em;
}
.p-datatable-header-cell.filter-active svg {
color: #10b981;
}
.p-datatable-header-cell.filter-active {
color: #047857;
}
</style>

0 comments on commit ef5ddfa

Please sign in to comment.