diff --git a/app/stores/data.js b/app/stores/data.js index 5d221794..c0970b41 100644 --- a/app/stores/data.js +++ b/app/stores/data.js @@ -34,27 +34,32 @@ export const useDataStore = defineStore("data", () => { async function formatedMeshComponents(id) { const items = await database.model_components.where({ id }).toArray() - const distinctTypes = [...new Set(items.map((item) => item.type))] - - const formated_mesh_components = await Promise.all( - distinctTypes.map(async (type) => { - const meshComponents = await database.model_components - .where({ id, type }) - .toArray() - - return { - id: type, - title: type, - children: meshComponents.map((meshComponent) => ({ - id: meshComponent.geode_id, - title: meshComponent.name, - category: meshComponent.type, - })), - } - }), - ) + const componentTitles = { + Corner: "Corners", + Line: "Lines", + Surface: "Surfaces", + Block: "Blocks", + } - return formated_mesh_components + const componentsByType = items.reduce((acc, item) => { + if (componentTitles[item.type]) { + if (!acc[item.type]) acc[item.type] = [] + acc[item.type].push(item) + } + return acc + }, {}) + + return Object.keys(componentTitles) + .filter((type) => componentsByType[type]) + .map((type) => ({ + id: type, + title: componentTitles[type], + children: componentsByType[type].map((meshComponent) => ({ + id: meshComponent.geode_id, + title: meshComponent.name, + category: meshComponent.type, + })), + })) } async function meshComponentType(id, geode_id) { @@ -109,15 +114,19 @@ export const useDataStore = defineStore("data", () => { await database.model_components.where({ id }).delete() } - async function fetchMeshComponents(id) { + async function fetchModelComponents(id) { const geodeStore = useGeodeStore() return await geodeStore.request( - back_model_schemas.mesh_components, + back_model_schemas.model_components, { id }, { response_function: async (response) => { - const { mesh_components } = response - await addModelComponents(mesh_components) + const { mesh_components, collection_components } = response + const allComponents = [ + ...mesh_components, + ...collection_components, + ].map((component) => ({ ...component, id })) + await addModelComponents(allComponents) }, }, ) @@ -178,7 +187,7 @@ export const useDataStore = defineStore("data", () => { addItem, deleteItem, updateItem, - fetchMeshComponents, + fetchModelComponents, getCornersGeodeIds, getLinesGeodeIds, getSurfacesGeodeIds, diff --git a/app/utils/file_import_workflow.js b/app/utils/file_import_workflow.js index c1e52dc9..c7cc40c8 100644 --- a/app/utils/file_import_workflow.js +++ b/app/utils/file_import_workflow.js @@ -50,7 +50,7 @@ async function importItem(item) { await dataStyleStore.addDataStyle(item.id, item.geode_object_type) if (item.viewer_type === "model") { - await dataStore.fetchMeshComponents(item.id) + await dataStore.fetchModelComponents(item.id) } await dataStyleStore.applyDefaultStyle(item.id) diff --git a/internal/database/tables/model_components.js b/internal/database/tables/model_components.js index 4bf4601f..cfb9041c 100644 --- a/internal/database/tables/model_components.js +++ b/internal/database/tables/model_components.js @@ -1,4 +1,4 @@ export const modelComponentsTable = { name: "model_components", - schema: "[id+geode_id], [id+type], viewer_id, type, name, created_at", + schema: "[id+geode_id], [id+type], viewer_id, name", } diff --git a/tests/integration/microservices/back/requirements.txt b/tests/integration/microservices/back/requirements.txt index c4caed69..bd3a3ef5 100644 --- a/tests/integration/microservices/back/requirements.txt +++ b/tests/integration/microservices/back/requirements.txt @@ -5,4 +5,3 @@ # pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in # -opengeodeweb-back==6.*,>=6.1.3 diff --git a/tests/integration/microservices/viewer/requirements.txt b/tests/integration/microservices/viewer/requirements.txt index 5922c2c7..4d097394 100644 --- a/tests/integration/microservices/viewer/requirements.txt +++ b/tests/integration/microservices/viewer/requirements.txt @@ -5,4 +5,3 @@ # pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in # -opengeodeweb-viewer==1.*,>=1.15.3