Skip to content

Commit

Permalink
Assembly and epd usage (#111)
Browse files Browse the repository at this point in the history
*Combined assembly and epd

* Mixed Material usage supported
  • Loading branch information
fabianlinkflink authored Jan 10, 2025
1 parent 927ab8e commit 2a086f3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ firebase.json
.env.sentry-build-plugin
package-lock.json
serviceAccountKey.json
codebase.md
24 changes: 16 additions & 8 deletions src/components/Mapping/MaterialMappingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<!-- Search Bar and Table -->
<div class="relative mt-1 flex-1 px-4 sm:px-6">
<SearchBar
:data="materials"
:data="combinedMaterials"
:filterParam="productFilterParams"
:sortingParam="sortingParameters"
@update:data="handleFilteredData"
Expand All @@ -85,7 +85,7 @@
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { defineComponent, ref, computed } from 'vue'
import { storeToRefs } from 'pinia'
import {
Dialog,
Expand All @@ -101,7 +101,7 @@ import MaterialTable from '@/components/Mapping/MaterialTable.vue'
import SearchBar from '@/components/Misc/SearchBar.vue'
import type { NestedGroup } from '@/models/filters'
import type { Product } from '@/models/material'
import type { Product, Assembly } from '@/models/material'
import { useMaterialStore } from '@/stores/material'
export default defineComponent({
Expand All @@ -121,7 +121,9 @@ export default defineComponent({
const materialStore = useMaterialStore()
const materials = storeToRefs(materialStore).materials
const filteredMaterial = ref<Product[]>([])
const assemblies = storeToRefs(materialStore).assemblies
const filteredMaterial = ref<(Product | Assembly)[]>([])
const { selectedGroup } = storeToRefs(projectStore)
const { mappingModalOpen} = storeToRefs(navStore)
Expand All @@ -141,8 +143,8 @@ export default defineComponent({
displayName: 'Material Type',
},
{
paramName: 'unit',
displayName: 'Unit',
paramName: 'isAssembly',
displayName: 'Assembly',
},
]
const sortingParameters = [
Expand All @@ -161,15 +163,20 @@ export default defineComponent({
]
const searchQuery = ref('')
// If no data selected or available show this instead, this should never happen so can remove from final version
// If no data selected or available show this instead, mostly for debug
const emptyGroup: NestedGroup = {
id: 'empty',
name: 'No group selected',
children: [],
objects: [],
}
const combinedMaterials = computed(() => [
...materials.value,
...assemblies.value,
])
const handleFilteredData = (newData: Product[]) => {
const handleFilteredData = (newData: (Product | Assembly)[]) => {
filteredMaterial.value = newData
}
Expand All @@ -183,6 +190,7 @@ export default defineComponent({
searchQuery,
emptyGroup,
materials,
combinedMaterials,
filteredMaterial,
productFilterParams,
sortingParameters,
Expand Down
3 changes: 1 addition & 2 deletions src/components/Mapping/MaterialTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ import { useMaterialStore } from '@/stores/material'
import type { Product, Assembly } from '@/models/material'
// This component just shows the values of the material list, it does not modify it
// TODO: Move this from props to store?
export default defineComponent({
name: 'MaterialTable',
components: {
Draggable,
},
props: {
data: {
type: Array as () => Product[] | Assembly[],
type: Array as () => (Product | Assembly)[],
required: true,
},
},
Expand Down
30 changes: 26 additions & 4 deletions src/components/Misc/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { getNestedPropertyValue } from '@/utils/material'
import { Source } from '@/models/material'
import { getEnumEntries } from '@/utils/dataUtils'
import { isAssembly } from '@/utils/EPDUtils'
import {
Menu,
Expand Down Expand Up @@ -131,7 +132,7 @@ export default defineComponent({
},
props: {
data: {
//This is set as Product Assembly since its used for that now, can be anything
//This is set as Product Assembly, can be both
type: Array as () => (Product | Assembly)[],
required: true,
},
Expand Down Expand Up @@ -163,7 +164,6 @@ export default defineComponent({
const optionsSet = new Set()
// Manual check for source enum so we set name instead
// TODO: Make dynamic for all enums
if (paramName === 'source') {
return getEnumEntries(Source).map((entry) => ({
label: entry.label,
Expand All @@ -172,6 +172,14 @@ export default defineComponent({
}))
}
// Check for Assembly filtering then we make custom entries
if (paramName === 'isAssembly') {
return [
{ label: 'Assembly', value: 'assembly', selected: selectedFilters.value[paramName]?.includes('assembly') },
{ label: 'Product', value: 'product', selected: selectedFilters.value[paramName]?.includes('product') },
]
}
props.data.forEach((item) => {
const value = getNestedPropertyValue(item, paramName)
if (value !== undefined) {
Expand All @@ -187,11 +195,12 @@ export default defineComponent({
const filteredData = computed(() => {
return props.data.filter((item) => {
// Common filtering logic
// Search logic
const matchesSearch = item.name
.toLowerCase()
.includes(searchQuery.value.toLowerCase());
// Parameter matching logic
const matchesFilters = Object.entries(selectedFilters.value).every(
([key, selectedOptions]) => {
if (selectedOptions.length === 0) return true;
Expand All @@ -200,10 +209,23 @@ export default defineComponent({
return selectedOptions.includes(value);
}
)
return matchesSearch && matchesFilters
let isAssemblyMatch = true
// More custom check for assembly logic
if (selectedFilters.value.isAssembly) {
const itemType = isAssembly(item) ? 'assembly' : 'product'
isAssemblyMatch =
selectedFilters.value.isAssembly.length === 0 ||
selectedFilters.value.isAssembly.includes(itemType)
}
return matchesSearch && matchesFilters && isAssemblyMatch
})
})
const sortedData = computed(() => {
const dataToSort = [...filteredData.value]
if (sorting.value.parameter) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
step.name == navigationStore.activePage
? 'border-green-500 text-gray-900'
: 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700',
'inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium'
'inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium cursor-pointer'
]"
@click="handleNavigation(step)"
>
Expand Down

0 comments on commit 2a086f3

Please sign in to comment.