From 605164aed9e4bd9afe4b67342f0fc9a0b602c9de Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 5 Nov 2026 17:25:42 +0100 Subject: [PATCH 01/62] fix(types): define geode_id once as GeodeId and GeodeIdentified geode_id was redeclared as an inline `string` in 10 interfaces. It is the id OpenGeode gives to an object, so the same data loaded twice shares it. Define the GeodeId alias and the GeodeIdentified mixin in app/types/identifiers.ts and extend it instead (Readonly/Partial for the readonly and optional variants). Co-Authored-By: Claude Sonnet 5.5 --- .../Viewer/ObjectTree/Base/ItemLabel.vue | 4 ++-- app/composables/tree_filter.ts | 6 +++--- app/stores/data.ts | 15 ++++++++------- app/stores/data_helpers/mesh.ts | 7 +++---- app/stores/treeview.ts | 6 +++--- app/types/identifiers.ts | 8 ++++++++ internal/stores/data_style/model/selection.ts | 4 ++-- .../data_style/model/visibility_dispatch.ts | 4 ++-- internal/stores/hybrid_viewer/highlight.ts | 5 +++-- 9 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 app/types/identifiers.ts diff --git a/app/components/Viewer/ObjectTree/Base/ItemLabel.vue b/app/components/Viewer/ObjectTree/Base/ItemLabel.vue index b27dbc6c9..060624620 100644 --- a/app/components/Viewer/ObjectTree/Base/ItemLabel.vue +++ b/app/components/Viewer/ObjectTree/Base/ItemLabel.vue @@ -2,6 +2,7 @@ import { formatCrs, formatCrsCode } from "@ogw_front/utils/crs"; import ComponentRelations from "@ogw_front/components/Viewer/ObjectTree/Base/ComponentRelations.vue"; import type { DisplayItem } from "@ogw_front/composables/virtual_tree"; +import type { GeodeIdentified } from "@ogw_front/types/identifiers"; import { middleTruncate } from "@ogw_front/utils/string"; import { useClipboard } from "@vueuse/core"; import { useCrsStore } from "@ogw_front/stores/crs"; @@ -33,9 +34,8 @@ const labelContainer = useTemplateRef("label-container"); const { width: containerWidth } = useElementSize(labelContainer); // The item prop can be either a DisplayItem wrapper (with a `.raw` domain object) or the domain object itself when this component is used outside CommonTreeView's slot machinery; the domain object always carries an id/title at runtime. -interface LabeledItem { +interface LabeledItem extends Partial { id: string; - geode_id?: string; title?: string; is_active?: boolean; category?: string; diff --git a/app/composables/tree_filter.ts b/app/composables/tree_filter.ts index 45ccba2e8..997e4736f 100644 --- a/app/composables/tree_filter.ts +++ b/app/composables/tree_filter.ts @@ -1,14 +1,14 @@ import type { ComputedRef, Ref } from "vue"; +import type { GeodeIdentified } from "@ogw_front/types/identifiers"; // Same shape as Vue's MaybeRefOrGetter, kept as a local alias for readability at call sites. type ReadonlyMaybeRefOrGetter = Value | Ref | (() => Value); // This composable filters/sorts different flavors of "category with children" trees (treeview groups, model component/collection groups, ...); this shape captures just the fields it reads/writes, generically, across all of them. -interface FilterableItem { +interface FilterableItem extends Readonly> { readonly id: unknown; readonly title?: string; - // Present on geode objects (data and model components), absent on group nodes. - readonly geode_id?: string; + // Geode objects (data and model components) carry a geode_id, group nodes do not. readonly children?: readonly FilterableItem[]; } diff --git a/app/stores/data.ts b/app/stores/data.ts index ca1738946..fa8c6365c 100644 --- a/app/stores/data.ts +++ b/app/stores/data.ts @@ -6,6 +6,7 @@ import { useObservable } from "@vueuse/rxjs"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports +import type { GeodeId, GeodeIdentified } from "@ogw_front/types/identifiers"; import { type ModelComponentRecord, useDataMesh } from "./data_helpers/mesh.js"; import { database } from "@ogw_internal/database/database.js"; import { liveObservable } from "@ogw_front/utils/live_observable"; @@ -13,9 +14,8 @@ import { useDataCollections } from "./data_helpers/collections.js"; import { useDataRelations } from "./data_helpers/relations.js"; import { useViewerStore } from "@ogw_front/stores/viewer"; -interface DataItem { +interface DataItem extends GeodeIdentified { id: string; - geode_id: string; name: string; viewer_type: string; geode_object_type: string; @@ -29,8 +29,7 @@ interface DataItem { // What the CRS features read of a data: light to copy on each change type CrsItem = Pick; -interface ModelComponentInput { - geode_id: string; +interface ModelComponentInput extends GeodeIdentified { type: string; viewer_id: string | number; name: string; @@ -40,9 +39,8 @@ interface ModelComponentInput { items?: string[]; } -interface NewDataItem { +interface NewDataItem extends GeodeIdentified { id: string; - geode_id: string; name?: string; viewer_type: string; geode_object_type: string; @@ -189,7 +187,10 @@ export const useDataStore = defineStore("data", () => { const items = refAllItems(); return computed(() => items.value.filter((data_item) => isRegistered(data_item.id))); } - async function meshComponentType(modelId: string, geode_id: string): Promise { + async function meshComponentType( + modelId: string, + geode_id: GeodeId, + ): Promise { const component = await model_components_db .where("[id+geode_id]") .equals([modelId, geode_id]) diff --git a/app/stores/data_helpers/mesh.ts b/app/stores/data_helpers/mesh.ts index 4401d0344..15241fe25 100644 --- a/app/stores/data_helpers/mesh.ts +++ b/app/stores/data_helpers/mesh.ts @@ -1,20 +1,19 @@ +import type { GeodeIdentified } from "@ogw_front/types/identifiers"; import type { Table } from "dexie"; import { database } from "@ogw_internal/database/database.js"; import { liveObservable } from "@ogw_front/utils/live_observable"; import { useObservable } from "@vueuse/rxjs"; -interface ModelComponentRecord { +interface ModelComponentRecord extends GeodeIdentified { id: string; - geode_id: string; type: string; viewer_id: string | number; name: string; is_active: boolean; } -interface FormattedComponent { +interface FormattedComponent extends Readonly { readonly id: string; - readonly geode_id: string; readonly title: string; readonly category: string; readonly viewer_id: number; diff --git a/app/stores/treeview.ts b/app/stores/treeview.ts index 275840852..21a7f82d1 100644 --- a/app/stores/treeview.ts +++ b/app/stores/treeview.ts @@ -4,6 +4,7 @@ import { consola } from "consola"; // oxlint-disable eslint/sort-imports, eslint/max-lines import { defineStore } from "pinia"; +import type { GeodeId, GeodeIdentified } from "@ogw_front/types/identifiers"; import type { Table } from "dexie"; import { ref, watch } from "vue"; import { database } from "@ogw_internal/database/database"; @@ -19,10 +20,9 @@ interface OpenedView { geode_object_type?: string; } -interface TreeviewChild { +interface TreeviewChild extends GeodeIdentified { title: string; id: string; - geode_id: string; viewer_type: string; geode_object_type: string; } @@ -169,7 +169,7 @@ export const useTreeviewStore = defineStore("treeview", () => { geodeObjectType: string, name: string, id: string, - geode_id: string, + geode_id: GeodeId, viewer_type: string, ): void { const child: TreeviewChild = { diff --git a/app/types/identifiers.ts b/app/types/identifiers.ts new file mode 100644 index 000000000..6a4ef87bf --- /dev/null +++ b/app/types/identifiers.ts @@ -0,0 +1,8 @@ +// Id given by OpenGeode to an object (a uuid): the same data loaded twice has the same geode_id +type GeodeId = string; + +interface GeodeIdentified { + geode_id: GeodeId; +} + +export type { GeodeId, GeodeIdentified }; diff --git a/internal/stores/data_style/model/selection.ts b/internal/stores/data_style/model/selection.ts index 477d94639..63d391871 100644 --- a/internal/stores/data_style/model/selection.ts +++ b/internal/stores/data_style/model/selection.ts @@ -1,12 +1,12 @@ +import type { GeodeIdentified } from "@ogw_front/types/identifiers"; import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import type { Table } from "dexie"; import { database } from "@ogw_internal/database/database"; import type { useDataStyleState } from "@ogw_internal/stores/data_style/state"; -interface ModelComponentRecord { +interface ModelComponentRecord extends GeodeIdentified { id: string; - geode_id: string; type: string; } diff --git a/internal/stores/data_style/model/visibility_dispatch.ts b/internal/stores/data_style/model/visibility_dispatch.ts index 369075775..5e938c8c8 100644 --- a/internal/stores/data_style/model/visibility_dispatch.ts +++ b/internal/stores/data_style/model/visibility_dispatch.ts @@ -1,3 +1,4 @@ +import type { GeodeIdentified } from "@ogw_front/types/identifiers"; import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles"; import { useDataStore } from "@ogw_front/stores/data"; @@ -5,8 +6,7 @@ import { useDataStore } from "@ogw_front/stores/data"; // oxlint-disable-next-line no-explicit-any type ComponentStyleFunctions = Record<"Surface" | "Line" | "Block" | "Corner", any>; -interface ModelComponent { - geode_id: string; +interface ModelComponent extends GeodeIdentified { type: string; } diff --git a/internal/stores/hybrid_viewer/highlight.ts b/internal/stores/hybrid_viewer/highlight.ts index c18bb7664..df40d46a3 100644 --- a/internal/stores/hybrid_viewer/highlight.ts +++ b/internal/stores/hybrid_viewer/highlight.ts @@ -1,3 +1,4 @@ +import type { GeodeId, GeodeIdentified } from "@ogw_front/types/identifiers"; import { HOVER_DEBOUNCE_MS, HOVER_TIMEOUT_MS } from "./constants"; import type { HoverComponentInfo, HoverData } from "./vtk_types"; import viewer_schemas, { @@ -17,7 +18,7 @@ async function lookupModelName(modelId: string): Promise { async function lookupComponentInfo( modelId: string, - geodeId: string | undefined, + geodeId: GeodeId | undefined, ): Promise { const modelComponentsTable = database.model_components; if (geodeId === undefined || !modelComponentsTable) { @@ -26,7 +27,7 @@ async function lookupComponentInfo( const components = modelComponentsTable.where("[id+geode_id]"); const query = components.equals([modelId, geodeId] as IndexableType); const component = (await query.first()) as - | { name?: string; geode_id?: string; type?: string } + | (Partial & { name?: string; type?: string }) | undefined; if (!component) { return undefined; From 5ec41b778016c63a80d44e703400a51e0d3f55be Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 6 Nov 2026 18:59:42 +0100 Subject: [PATCH 02/62] fix(types): define the data id of the data rows once as DataIdentified A data loaded twice shares its geode_id, only the data id makes it unique, so `id` was ambiguous next to `geode_id`. Define DataId and the DataIdentified mixin in app/types/identifiers.ts and name `data_id` the data id of the rows keyed by a data id: DataItem, NewDataItem, ModelComponentRecord, ModelComponentRelationRecord, ObjectStyle, the metadata of the context menu and the structural types that read them. The Dexie indexes of the data, model_components, model_components_relation and data_style tables follow (the database is deleted at every start, so it needs no migration). The back-end, the viewer and the projects saved before this still name it `id`, so temporary adapters accept both (app/utils/legacy_data_id.ts): - importItem converts the items it gets from the back-end or a project - the data and data_style stores convert legacy rows on importStores Requests keep sending `id`. Remove the adapters once the python schemas use data_id. This also reads data_id where the code read the `id` of an untyped record: the mesh style loop (which threw on the unknown key) and the info card of the context menu, with a test for each. Co-Authored-By: Claude Sonnet 5.5 --- app/components/ClippingPlanes.vue | 10 +-- app/components/FactorFilterPanel.vue | 6 +- app/components/ThresholdFilter.vue | 4 +- app/components/TimeSeriesTargetSelector.vue | 2 +- .../Viewer/ContextMenu/InfoCard.vue | 22 +++--- app/composables/clipping_planes_widget.ts | 7 +- app/composables/clipping_slices.ts | 3 +- .../project_manager_helpers/types.ts | 11 ++- app/composables/use_overlapping_picker.ts | 2 +- app/stores/basemap_helpers/georeferenced.ts | 2 +- app/stores/crs.ts | 2 +- app/stores/data.ts | 76 ++++++++++++------- app/stores/data_helpers/collections.ts | 6 +- app/stores/data_helpers/mesh.ts | 13 ++-- app/stores/data_helpers/relations.ts | 4 +- app/stores/data_style.ts | 12 ++- app/stores/menu.ts | 3 +- app/types/identifiers.ts | 9 ++- app/utils/clipping_planes_scene.ts | 5 +- app/utils/crs.ts | 5 +- app/utils/import_workflow.ts | 32 +++++--- app/utils/legacy_data_id.ts | 16 ++++ app/utils/slice.ts | 9 ++- internal/database/tables/data.ts | 2 +- internal/database/tables/data_style.ts | 2 +- internal/database/tables/model_components.ts | 2 +- .../tables/model_components_relation.ts | 2 +- internal/stores/data_style/mesh/index.ts | 2 +- internal/stores/data_style/model/selection.ts | 7 +- internal/stores/data_style/state.ts | 4 +- internal/stores/data_style/state_shared.ts | 4 +- internal/stores/data_style/types.ts | 4 +- internal/stores/hybrid_viewer/highlight.ts | 2 +- .../ComponentRelations.nuxt.test.ts | 2 +- .../components/FactorFilterPanel.nuxt.test.ts | 6 +- tests/unit/components/InfoCard.nuxt.test.ts | 10 +-- tests/unit/components/ItemLabel.nuxt.test.ts | 14 ++-- .../TimeSeriesTargetSelector.nuxt.test.ts | 4 +- .../composables/project_manager.nuxt.test.ts | 4 +- tests/unit/plugins/project_load.nuxt.test.ts | 15 ++-- tests/unit/stores/basemap.nuxt.test.ts | 16 ++-- tests/unit/stores/basemap_detail.nuxt.test.ts | 2 +- tests/unit/stores/crs.nuxt.test.ts | 30 ++++---- tests/unit/stores/data.nuxt.test.ts | 16 ++-- .../data_collection_components.nuxt.test.ts | 6 +- .../stores/data_registered_items.nuxt.test.ts | 6 +- tests/unit/stores/mesh_style.nuxt.test.ts | 18 +++++ tests/unit/utils/import_workflow.nuxt.test.ts | 2 +- tests/unit/utils/legacy_data_id.nuxt.test.ts | 76 +++++++++++++++++++ 49 files changed, 340 insertions(+), 179 deletions(-) create mode 100644 app/utils/legacy_data_id.ts create mode 100644 tests/unit/stores/mesh_style.nuxt.test.ts create mode 100644 tests/unit/utils/legacy_data_id.nuxt.test.ts diff --git a/app/components/ClippingPlanes.vue b/app/components/ClippingPlanes.vue index 87a5af405..b214d9d85 100644 --- a/app/components/ClippingPlanes.vue +++ b/app/components/ClippingPlanes.vue @@ -38,14 +38,14 @@ const planes = ref([createPlane(undefined, [1, 0, 0])]); const allItems = dataStore.refRegisteredItems(); const targetIds = computed(() => { if (targetAllVisible.value) { - return allItems.value.map((item) => item.id); + return allItems.value.map((item) => item.data_id); } return selectedDatasetIds.value; }); const availableDatasets = computed<{ title: string; value: string }[]>(() => allItems.value.map((item) => ({ - title: item.name || item.id, - value: item.id, + title: item.name || item.data_id, + value: item.data_id, })), ); const widgetContainer = useTemplateRef("widgetContainer"); @@ -70,7 +70,7 @@ const { }); function getUntargetedIds(): string[] { - return allItems.value.map((item) => item.id).filter((id) => !targetIds.value.includes(id)); + return allItems.value.map((item) => item.data_id).filter((id) => !targetIds.value.includes(id)); } const { @@ -144,7 +144,7 @@ async function resetClippingPlanes(): Promise { } async function removeClippingPlanes(): Promise { - const allIds = allItems.value.map((item) => item.id); + const allIds = allItems.value.map((item) => item.data_id); await hybridViewerStore.setClippingPlanes(allIds, []); await removeSlices(allIds); } diff --git a/app/components/FactorFilterPanel.vue b/app/components/FactorFilterPanel.vue index d4420f75c..8ec6d162c 100644 --- a/app/components/FactorFilterPanel.vue +++ b/app/components/FactorFilterPanel.vue @@ -46,8 +46,8 @@ const factor = ref(factorRange.defaultValue); const allItems = dataStore.refRegisteredItems(); const availableDatasets = computed<{ title: string; value: string }[]>(() => allItems.value.map((item) => ({ - title: item.name || item.id, - value: item.id, + title: item.name || item.data_id, + value: item.data_id, })), ); @@ -55,7 +55,7 @@ let appliedFactor: number | undefined = undefined; async function applyFactor(): Promise { appliedFactor = factor.value; - const allIds = allItems.value.map((item) => item.id); + const allIds = allItems.value.map((item) => item.data_id); if (allIds.length === 0) { return; } diff --git a/app/components/ThresholdFilter.vue b/app/components/ThresholdFilter.vue index 741dde0b8..0f1bc9c7e 100644 --- a/app/components/ThresholdFilter.vue +++ b/app/components/ThresholdFilter.vue @@ -32,8 +32,8 @@ const cards = useTemplateRef("cards"); const allItems = dataStore.refAllItems(); const availableDatasets = computed<{ title: string; value: string }[]>(() => allItems.value.map((item) => ({ - title: item.name || item.id, - value: item.id, + title: item.name || item.data_id, + value: item.data_id, })), ); diff --git a/app/components/TimeSeriesTargetSelector.vue b/app/components/TimeSeriesTargetSelector.vue index ffe150c1e..9b66bf7e2 100644 --- a/app/components/TimeSeriesTargetSelector.vue +++ b/app/components/TimeSeriesTargetSelector.vue @@ -33,7 +33,7 @@ async function get_targets(): Promise { ]); targets.value = items .filter((item) => allowed_objects.includes(item.geode_object_type)) - .map(({ id, name, geode_object_type }) => ({ id, name, geode_object_type })); + .map(({ data_id, name, geode_object_type }) => ({ id: data_id, name, geode_object_type })); loading.value = false; } diff --git a/app/components/Viewer/ContextMenu/InfoCard.vue b/app/components/Viewer/ContextMenu/InfoCard.vue index d4f9751c8..29fa6987c 100644 --- a/app/components/Viewer/ContextMenu/InfoCard.vue +++ b/app/components/Viewer/ContextMenu/InfoCard.vue @@ -60,7 +60,7 @@ watch( return; } - const modelId = asString(newMeta.modelId) ?? asString(newMeta.id); + const modelId = asString(newMeta.modelId) ?? asString(newMeta.data_id); if (newMeta.pickedComponentId && modelId) { const components = await dataStore.getAllMeshComponents(modelId); const comp = components.find( @@ -128,13 +128,15 @@ function formatId(id: string | undefined): string { return `${id.slice(0, ID_SLICE_START)}...${id.slice(id.length - ID_SLICE_END_OFFSET)}`; } -const formattedId = computed(() => formatId(metaData.id)); +const formattedId = computed(() => formatId(metaData.data_id)); const crsStore = useCrsStore(); // A model component shares the model CRS: the CRS row is only shown for a data -const isData = computed(() => metaData.id !== undefined && metaData.modelId === undefined); +const isData = computed( + () => metaData.data_id !== undefined && metaData.modelId === undefined, +); // The menu metadata is a snapshot taken when it opened: read the item live so a CRS edit shows at once -const liveItem = useLiveDataItem(() => (isData.value ? metaData.id : undefined)); +const liveItem = useLiveDataItem(() => (isData.value ? metaData.data_id : undefined)); const liveCrs = computed(() => liveItem.value?.crs ?? metaData.crs); @@ -164,17 +166,17 @@ const liveCrs = computed(() => liveItem.value?.crs ?? metaData.crs); {{ metaData.geode_object_type }} - {{ isCopied(metaData.id) ? "COPIED!" : formattedId }} + {{ isCopied(metaData.data_id) ? "COPIED!" : formattedId }} @@ -195,7 +197,7 @@ const liveCrs = computed(() => liveItem.value?.crs ?? metaData.crs); size="x-small" color="white" class="ml-1" - @click.stop="crsStore.requestCrsEdit(metaData.id)" + @click.stop="crsStore.requestCrsEdit(metaData.data_id)" /> diff --git a/app/composables/clipping_planes_widget.ts b/app/composables/clipping_planes_widget.ts index f7de54a84..9ac8eb948 100644 --- a/app/composables/clipping_planes_widget.ts +++ b/app/composables/clipping_planes_widget.ts @@ -14,20 +14,17 @@ import { type vtkWidgetManager as WidgetManagerInstance, newInstance as vtkWidgetManager, } from "@kitware/vtk.js/Widgets/Core/WidgetManager"; +import type { DataIdentified } from "@ogw_front/types/identifiers"; import type { vtkGenericRenderWindow as GenericRenderWindowInstance } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; import type { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import type { vtkCamera } from "@kitware/vtk.js/Rendering/Core/Camera"; import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; -interface DataItemLike { - id: string; -} - interface ClippingPlanesWidgetParams { planes: Ref; targetAllVisible: Ref; selectedDatasetIds: Ref; - allItems: Ref; + allItems: Ref; hybridViewerStore: ReturnType; debouncedApply: (...args: readonly unknown[]) => void; } diff --git a/app/composables/clipping_slices.ts b/app/composables/clipping_slices.ts index 88d055ac8..f3915afbe 100644 --- a/app/composables/clipping_slices.ts +++ b/app/composables/clipping_slices.ts @@ -4,6 +4,7 @@ import { type SliceAxis, areAllGrids, } from "@ogw_front/utils/slice"; +import type { DataIdentified } from "@ogw_front/types/identifiers"; import type { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; interface Slice { @@ -31,7 +32,7 @@ interface SliceSyncParams { } interface ClippingSlicesParams { - allItems: ComputedRef<{ id: string; geode_object_type: string }[]>; + allItems: ComputedRef<(DataIdentified & { geode_object_type: string })[]>; targetIds: ComputedRef; getUntargetedIds: () => string[]; newItemId: () => number; diff --git a/app/composables/project_manager_helpers/types.ts b/app/composables/project_manager_helpers/types.ts index 79bd17971..513d224b7 100644 --- a/app/composables/project_manager_helpers/types.ts +++ b/app/composables/project_manager_helpers/types.ts @@ -3,13 +3,18 @@ import type { BasemapSnapshot } from "@ogw_front/stores/basemap"; import type { CRSList } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; import type { CameraSnapshot } from "@ogw_internal/stores/hybrid_viewer/camera"; import type { DataStyleSnapshot } from "@ogw_front/stores/data_style"; +import type { LegacyDataId } from "@ogw_front/utils/legacy_data_id"; import type { ModelComponentRecord } from "@ogw_front/stores/data_helpers/mesh.js"; import type { TreeviewSnapshot } from "@ogw_front/stores/treeview"; +// Projects saved before data_id existed hold the data id of their rows as `id` interface ProjectDataSnapshot { - items: NewDataItem[]; - modelComponents: ModelComponentRecord[]; - modelComponentsRelations: ModelComponentRelationRecord[]; + items: (LegacyDataId | NewDataItem)[]; + modelComponents: (LegacyDataId | ModelComponentRecord)[]; + modelComponentsRelations: ( + | LegacyDataId + | ModelComponentRelationRecord + )[]; } interface ProjectSnapshot { diff --git a/app/composables/use_overlapping_picker.ts b/app/composables/use_overlapping_picker.ts index bd54c0af1..ea08753e2 100644 --- a/app/composables/use_overlapping_picker.ts +++ b/app/composables/use_overlapping_picker.ts @@ -106,7 +106,7 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn { } async function getViewableIds(): Promise { - const activeIds = new Set(dataItems.value.map((i: DataItem) => i.id)); + const activeIds = new Set(dataItems.value.map((i: DataItem) => i.data_id)); const visibleStyleIds = Object.keys(dataStyleStore.styles).filter( (styleId) => activeIds.has(styleId) && dataStyleStore.objectVisibility(styleId) === true, ); diff --git a/app/stores/basemap_helpers/georeferenced.ts b/app/stores/basemap_helpers/georeferenced.ts index a32c4c76f..f329ad457 100644 --- a/app/stores/basemap_helpers/georeferenced.ts +++ b/app/stores/basemap_helpers/georeferenced.ts @@ -22,7 +22,7 @@ function useGeoreferenced(): Georeferenced { function georeferencedIds(): string[] { return crsStore.crsItems .filter((item) => sameCrs(item.crs, crsStore.projectCrs)) - .map((item) => item.id); + .map((item) => item.data_id); } const available = computed( diff --git a/app/stores/crs.ts b/app/stores/crs.ts index 955406fe5..d4909a53b 100644 --- a/app/stores/crs.ts +++ b/app/stores/crs.ts @@ -46,7 +46,7 @@ export const useCrsStore = defineStore("crs", () => { const mismatched = new Map(); for (const item of crsItems.value) { if (project !== undefined && !sameCrs(item.crs, project)) { - mismatched.set(item.id, item.crs); + mismatched.set(item.data_id, item.crs); } } return mismatched; diff --git a/app/stores/data.ts b/app/stores/data.ts index fa8c6365c..81cc2aaca 100644 --- a/app/stores/data.ts +++ b/app/stores/data.ts @@ -6,7 +6,13 @@ import { useObservable } from "@vueuse/rxjs"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports -import type { GeodeId, GeodeIdentified } from "@ogw_front/types/identifiers"; +import type { + DataId, + DataIdentified, + GeodeId, + GeodeIdentified, +} from "@ogw_front/types/identifiers"; +import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { type ModelComponentRecord, useDataMesh } from "./data_helpers/mesh.js"; import { database } from "@ogw_internal/database/database.js"; import { liveObservable } from "@ogw_front/utils/live_observable"; @@ -14,8 +20,7 @@ import { useDataCollections } from "./data_helpers/collections.js"; import { useDataRelations } from "./data_helpers/relations.js"; import { useViewerStore } from "@ogw_front/stores/viewer"; -interface DataItem extends GeodeIdentified { - id: string; +interface DataItem extends DataIdentified, GeodeIdentified { name: string; viewer_type: string; geode_object_type: string; @@ -27,7 +32,7 @@ interface DataItem extends GeodeIdentified { } // What the CRS features read of a data: light to copy on each change -type CrsItem = Pick; +type CrsItem = Pick; interface ModelComponentInput extends GeodeIdentified { type: string; @@ -39,8 +44,7 @@ interface ModelComponentInput extends GeodeIdentified { items?: string[]; } -interface NewDataItem extends GeodeIdentified { - id: string; +interface NewDataItem extends DataIdentified, GeodeIdentified { name?: string; viewer_type: string; geode_object_type: string; @@ -54,8 +58,7 @@ interface NewDataItem extends GeodeIdentified { nb_vertices?: number; } -interface ModelComponentRelationRecord { - id: string; +interface ModelComponentRelationRecord extends DataIdentified { parent: string; child: string; type: string; @@ -65,7 +68,7 @@ interface ViewableItemLike { is_viewable?: boolean; binary_light_viewable?: string; geode_object_type?: string; - id?: string; + data_id?: DataId; title?: string; } @@ -86,7 +89,7 @@ function checkItemViewable(item: ViewableItemLike | undefined | null): boolean { } if ( item.geode_object_type === "HorizonStack3D" || - item.id === "HorizonStack3D" || + item.data_id === "HorizonStack3D" || item.title === "HorizonStack3D" ) { return false; @@ -163,7 +166,12 @@ export const useDataStore = defineStore("data", () => { return useObservable( liveObservable(async () => { const items = await data_db.toArray(); - return items.map(({ id, name, crs, created_at }) => ({ id, name, crs, created_at })); + return items.map(({ data_id, name, crs, created_at }) => ({ + data_id, + name, + crs, + created_at, + })); }), { initialValue: [] as CrsItem[] }, ); @@ -185,14 +193,14 @@ export const useDataStore = defineStore("data", () => { } function refRegisteredItems(): ComputedRef { const items = refAllItems(); - return computed(() => items.value.filter((data_item) => isRegistered(data_item.id))); + return computed(() => items.value.filter((data_item) => isRegistered(data_item.data_id))); } async function meshComponentType( modelId: string, geode_id: GeodeId, ): Promise { const component = await model_components_db - .where("[id+geode_id]") + .where("[data_id+geode_id]") .equals([modelId, geode_id]) .first(); return component?.type; @@ -227,9 +235,9 @@ export const useDataStore = defineStore("data", () => { // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts. async function addItem(new_item: NewDataItem): Promise { const itemData: DataItem = { - id: new_item.id, + data_id: new_item.data_id, geode_id: new_item.geode_id, - name: new_item.name ?? new_item.id, + name: new_item.name ?? new_item.data_id, viewer_type: new_item.viewer_type, geode_object_type: new_item.geode_object_type, visible: true, @@ -254,7 +262,7 @@ export const useDataStore = defineStore("data", () => { function addModelComponents(components: readonly ModelComponentInput[]): void { for (const component of components) { allComponents.push({ - id: new_item.id, + data_id: new_item.data_id, geode_id: component.geode_id, type: component.type, viewer_id: component.viewer_id, @@ -283,7 +291,7 @@ export const useDataStore = defineStore("data", () => { ): void { for (const child of components) { relations.push({ - id: new_item.id, + data_id: new_item.data_id, parent, child, type, @@ -317,7 +325,7 @@ export const useDataStore = defineStore("data", () => { const component = await model_components_db .where("viewer_id") .equals(Number(viewer_id)) - .and((model_component: ModelComponentRecord) => model_component.id === modelId) + .and((model_component: ModelComponentRecord) => model_component.data_id === modelId) .first(); return component; } @@ -328,13 +336,13 @@ export const useDataStore = defineStore("data", () => { const components = await model_components_db .where("viewer_id") .anyOf(viewer_ids) - .and((model_component: ModelComponentRecord) => model_component.id === modelId) + .and((model_component: ModelComponentRecord) => model_component.data_id === modelId) .toArray(); return components; } async function deleteModelComponents(modelId: string): Promise { - await model_components_db.where("id").equals(modelId).delete(); - await model_components_relation_db.where("id").equals(modelId).delete(); + await model_components_db.where("data_id").equals(modelId).delete(); + await model_components_relation_db.where("data_id").equals(modelId).delete(); } async function deleteItem(id: string): Promise { @@ -347,7 +355,7 @@ export const useDataStore = defineStore("data", () => { } async function getAllModelComponentsViewerIds(modelId: string): Promise { - const components = await model_components_db.where("id").equals(modelId).toArray(); + const components = await model_components_db.where("data_id").equals(modelId).toArray(); return components.map((component: ModelComponentRecord) => Math.trunc(Number(component.viewer_id)), ); @@ -357,7 +365,7 @@ export const useDataStore = defineStore("data", () => { meshComponentGeodeIds: readonly string[], ): Promise { const components = await model_components_db - .where("[id+geode_id]") + .where("[data_id+geode_id]") .anyOf(meshComponentGeodeIds.map((geode_id) => [modelId, geode_id])) .toArray(); return components.map((component: ModelComponentRecord) => @@ -389,12 +397,26 @@ export const useDataStore = defineStore("data", () => { // Dexie's bulkPut expects mutable arrays, so this snapshot parameter can't deeply satisfy // The prefer-readonly-parameter-types rule; same pattern as app/utils/import_workflow.ts. async function importStores(snapshot: { - readonly modelComponents: readonly ModelComponentRecord[]; - readonly modelComponentsRelations: readonly ModelComponentRelationRecord[]; + readonly modelComponents: readonly ( + | LegacyDataId + | ModelComponentRecord + )[]; + readonly modelComponentsRelations: readonly ( + | LegacyDataId + | ModelComponentRelationRecord + )[]; }): Promise { await clear(); - await model_components_db.bulkPut(snapshot.modelComponents); - await model_components_relation_db.bulkPut(snapshot.modelComponentsRelations); + await model_components_db.bulkPut( + snapshot.modelComponents.map((component) => + fromLegacyDataId(component), + ), + ); + await model_components_relation_db.bulkPut( + snapshot.modelComponentsRelations.map((relation) => + fromLegacyDataId(relation), + ), + ); } return { refAllItems, diff --git a/app/stores/data_helpers/collections.ts b/app/stores/data_helpers/collections.ts index 26bfacf1a..5f93695ee 100644 --- a/app/stores/data_helpers/collections.ts +++ b/app/stores/data_helpers/collections.ts @@ -39,7 +39,7 @@ export function useDataCollections(): { async function hasCollectionComponents(modelId: string): Promise { const count = await model_components_db - .where("id") + .where("data_id") .equals(modelId) .and((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type)) .count(); @@ -47,7 +47,7 @@ export function useDataCollections(): { } async function getAllCollectionComponents(modelId: string): Promise { - const items = await model_components_db.where("id").equals(modelId).toArray(); + const items = await model_components_db.where("data_id").equals(modelId).toArray(); return items .filter((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type)) .map((component: ModelComponentRecord) => ({ @@ -64,7 +64,7 @@ export function useDataCollections(): { modelId: string, ): Promise> { const components = await getAllCollectionComponents(modelId); - const relations = await model_components_relation_db.where("id").equals(modelId).toArray(); + const relations = await model_components_relation_db.where("data_id").equals(modelId).toArray(); const allMeshComponents = await getAllMeshComponents(modelId); const meshComponentsById: Record = {}; for (const meshComponent of allMeshComponents) { diff --git a/app/stores/data_helpers/mesh.ts b/app/stores/data_helpers/mesh.ts index 15241fe25..a0a69bc44 100644 --- a/app/stores/data_helpers/mesh.ts +++ b/app/stores/data_helpers/mesh.ts @@ -1,11 +1,10 @@ -import type { GeodeIdentified } from "@ogw_front/types/identifiers"; +import type { DataIdentified, GeodeIdentified } from "@ogw_front/types/identifiers"; import type { Table } from "dexie"; import { database } from "@ogw_internal/database/database.js"; import { liveObservable } from "@ogw_front/utils/live_observable"; import { useObservable } from "@vueuse/rxjs"; -interface ModelComponentRecord extends GeodeIdentified { - id: string; +interface ModelComponentRecord extends DataIdentified, GeodeIdentified { type: string; viewer_id: string | number; name: string; @@ -57,7 +56,7 @@ function useDataMesh(): { >; async function formatedMeshComponents(modelId: string): Promise { - const items = await model_components_db.where("id").equals(modelId).toArray(); + const items = await model_components_db.where("data_id").equals(modelId).toArray(); const componentTitles: Record = { Corner: "Corners", Line: "Lines", @@ -101,14 +100,14 @@ function useDataMesh(): { type: string, ): Promise { const components = await model_components_db - .where("[id+type]") + .where("[data_id+type]") .equals([modelId, type]) .toArray(); return components.map((item: ModelComponentRecord) => toFormattedComponent(item)); } async function getAllMeshComponents(modelId: string): Promise { - const items = await model_components_db.where("id").equals(modelId).toArray(); + const items = await model_components_db.where("data_id").equals(modelId).toArray(); return items.map((item: ModelComponentRecord) => toFormattedComponent(item)); } @@ -126,7 +125,7 @@ function useDataMesh(): { async function getMeshComponentGeodeIds(modelId: string, type: string): Promise { const components = await model_components_db - .where("[id+type]") + .where("[data_id+type]") .equals([modelId, type]) .toArray(); return components.map((component: ModelComponentRecord) => component.geode_id); diff --git a/app/stores/data_helpers/relations.ts b/app/stores/data_helpers/relations.ts index c5648961d..e7b09575f 100644 --- a/app/stores/data_helpers/relations.ts +++ b/app/stores/data_helpers/relations.ts @@ -34,7 +34,7 @@ export function useDataRelations(): { const keys = relations .filter((relation) => relation.type === type) .map((relation) => [modelId, relation.child]); - const components = await model_components_db.where("[id+geode_id]").anyOf(keys).toArray(); + const components = await model_components_db.where("[data_id+geode_id]").anyOf(keys).toArray(); return components.map((component) => toFormattedComponent(component)); } @@ -43,7 +43,7 @@ export function useDataRelations(): { componentId: string, ): Promise { const relations = await model_components_relation_db - .where("[id+parent+child]") + .where("[data_id+parent+child]") .between([modelId, componentId, Dexie.minKey], [modelId, componentId, Dexie.maxKey]) .toArray(); const [boundaries, internals] = await Promise.all([ diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts index c9461d3ad..f6fa31681 100644 --- a/app/stores/data_style.ts +++ b/app/stores/data_style.ts @@ -1,3 +1,4 @@ +import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import type { ModelComponentStyle, ModelComponentTypeStyle, @@ -15,7 +16,8 @@ import { useModelStyle } from "@ogw_internal/stores/data_style/model/index"; import { useSceneStyle } from "@ogw_internal/stores/data_style/scene"; interface DataStyleSnapshot { - readonly styles: Record; + // Projects saved before data_id existed hold their styles with an `id` + readonly styles: Record | ObjectStyle>; readonly componentStyles: Record; readonly modelComponentTypeStyles: Record; readonly sceneStyle?: SceneStyle; @@ -59,7 +61,7 @@ export const useDataStyleStore = defineStore("dataStyle", () => { async function addDataStyle(id: string, geode_object: string): Promise { const defaultStyle = getDefaultStyle(geode_object); await data_style_db.put( - structuredClone({ id, ...(isRecord(defaultStyle) ? defaultStyle : {}) }), + structuredClone({ data_id: id, ...(isRecord(defaultStyle) ? defaultStyle : {}) }), ); } @@ -116,8 +118,10 @@ export const useDataStyleStore = defineStore("dataStyle", () => { const style_promises = Object.entries(stylesSnapshot).map( // oxlint-disable-next-line prefer-readonly-parameter-types -- same external ObjectStyle limitation as above. - async ([id, style]: readonly [string, ObjectStyle]) => { - const key = await data_style_db.put(structuredClone({ ...style, id })); + async ([id, style]: readonly [string, LegacyDataId | ObjectStyle]) => { + const key = await data_style_db.put( + structuredClone({ ...fromLegacyDataId(style), data_id: id }), + ); return key; }, ); diff --git a/app/stores/menu.ts b/app/stores/menu.ts index f1ee2a8d4..7e0983872 100644 --- a/app/stores/menu.ts +++ b/app/stores/menu.ts @@ -1,6 +1,7 @@ import { type MenuItems, menusData } from "./menu_helpers/menus_data.js"; +import type { DataIdentified } from "@ogw_front/types/identifiers"; -interface MenuMetaData { +interface MenuMetaData extends Partial { viewer_type?: string; geode_object_type?: string; targetIds?: string[]; diff --git a/app/types/identifiers.ts b/app/types/identifiers.ts index 6a4ef87bf..96ab807bf 100644 --- a/app/types/identifiers.ts +++ b/app/types/identifiers.ts @@ -1,8 +1,15 @@ // Id given by OpenGeode to an object (a uuid): the same data loaded twice has the same geode_id type GeodeId = string; +// Id of a data loaded in the app, unique even when the same data is loaded twice (see GeodeId) +type DataId = string; + interface GeodeIdentified { geode_id: GeodeId; } -export type { GeodeId, GeodeIdentified }; +interface DataIdentified { + data_id: DataId; +} + +export type { DataId, DataIdentified, GeodeId, GeodeIdentified }; diff --git a/app/utils/clipping_planes_scene.ts b/app/utils/clipping_planes_scene.ts index 41ccfc529..8326dfb15 100644 --- a/app/utils/clipping_planes_scene.ts +++ b/app/utils/clipping_planes_scene.ts @@ -1,4 +1,5 @@ import type { Bounds } from "@kitware/vtk.js/types"; +import type { DataIdentified } from "@ogw_front/types/identifiers"; import type vtkActor from "@kitware/vtk.js/Rendering/Core/Actor"; import type { vtkCamera } from "@kitware/vtk.js/Rendering/Core/Camera"; @@ -65,13 +66,13 @@ interface MainCameraOptions { function resolveActiveActors( targetAllVisible: boolean, - allItems: readonly { readonly id: string }[], + allItems: readonly Readonly[], selectedDatasetIds: readonly string[], hybridDb: Record, ): vtkActor[] { let targetIds: readonly string[] = selectedDatasetIds; if (targetAllVisible) { - targetIds = allItems.map((item: { id: string }) => item.id); + targetIds = allItems.map((item: Readonly) => item.data_id); } const targeted = targetIds .map((id) => hybridDb[id]?.actor) diff --git a/app/utils/crs.ts b/app/utils/crs.ts index 2682a3abf..3b9088cf2 100644 --- a/app/utils/crs.ts +++ b/app/utils/crs.ts @@ -1,5 +1,6 @@ import type { CrsItem, NewDataItem } from "@ogw_front/stores/data"; import type { CRSList } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; +import type { LegacyDataId } from "@ogw_front/utils/legacy_data_id"; function formatCrs(crs: CRSList | undefined): string { return crs ? `${crs.authority}:${crs.code} — ${crs.name}` : "None"; @@ -27,7 +28,9 @@ function sameCrsState(left: CRSList | undefined, right: CRSList | undefined): bo // The CRS of the oldest georeferenced data: the project CRS of a project saved before it was stored function oldestCrs( - items: readonly Pick[] | readonly NewDataItem[], + items: + | readonly Pick[] + | readonly (LegacyDataId | NewDataItem)[], ): CRSList | undefined { return items .filter((item) => item.crs !== undefined) diff --git a/app/utils/import_workflow.ts b/app/utils/import_workflow.ts index 7b87e6189..17b7a66b2 100644 --- a/app/utils/import_workflow.ts +++ b/app/utils/import_workflow.ts @@ -4,6 +4,7 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schem import { consola } from "consola"; // Local imports +import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { type NewDataItem, useDataStore } from "@ogw_front/stores/data"; import { useBackStore } from "@ogw_front/stores/back"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; @@ -18,7 +19,7 @@ interface FileToImport { // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't // Satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts). -async function importItem(item: NewDataItem): Promise { +async function importDataItem(item: NewDataItem): Promise { const dataStore = useDataStore(); const dataStyleStore = useDataStyleStore(); const hybridViewerStore = useHybridViewerStore(); @@ -32,7 +33,7 @@ async function importItem(item: NewDataItem): Promise { if (!(await dataStore.isItemViewable(item))) { return undefined; } - return dataStore.registerObject(item.id, item.name ?? item.id); + return dataStore.registerObject(item.data_id, item.name ?? item.data_id); }); let addDataComponentsTask: Promise = Promise.resolve(undefined); let addDataRelationsTask: Promise = Promise.resolve(undefined); @@ -42,22 +43,22 @@ async function importItem(item: NewDataItem): Promise { } treeviewStore.addItem( item.geode_object_type, - item.name ?? item.id, - item.id, + item.name ?? item.data_id, + item.data_id, item.geode_id, item.viewer_type, ); - const addDataStyleTask = dataStyleStore.addDataStyle(item.id, item.geode_object_type); + const addDataStyleTask = dataStyleStore.addDataStyle(item.data_id, item.geode_object_type); const addViewerTask = addDataTask.then(async () => { if (!(await dataStore.isItemViewable(item))) { return undefined; } - return hybridViewerStore.addItem(item.id); + return hybridViewerStore.addItem(item.data_id); }); const applyStyleTask = Promise.all([registerTask, addDataComponentsTask, addDataStyleTask]).then( async () => { if (await dataStore.isItemViewable(item)) { - return dataStyleStore.applyDefaultStyle(item.id); + return dataStyleStore.applyDefaultStyle(item.data_id); } return undefined; }, @@ -70,7 +71,12 @@ async function importItem(item: NewDataItem): Promise { addViewerTask, applyStyleTask, ]); - return item.id; + return item.data_id; +} +// Every item comes through here: from the back-end, which still names its data id `id`, or from a project +async function importItem(imported: LegacyDataId | NewDataItem): Promise { + const id = await importDataItem(fromLegacyDataId(imported)); + return id; } async function importFile(filename: string, geode_object_type: string): Promise { const backStore = useBackStore(); @@ -83,8 +89,8 @@ async function importFile(filename: string, geode_object_type: string): Promise< schema, params, }); - // oxlint-disable-next-line no-unsafe-type-assertion -- this is the trusted API boundary; the back-end response shape matches NewDataItem. - return importItem(response as NewDataItem); + // oxlint-disable-next-line no-unsafe-type-assertion -- this is the trusted API boundary; the back-end response shape matches NewDataItem, except for its legacy id. + return importItem(response as LegacyDataId); } async function importWorkflow(files: readonly FileToImport[]): Promise { @@ -133,11 +139,13 @@ async function importWorkflow(files: readonly FileToImport[]): Promise } // NewDataItem has mutable array fields (mesh_components, collection_components), so a readonly array of it can't satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts). -async function importWorkflowFromSnapshot(items: readonly NewDataItem[]): Promise { +async function importWorkflowFromSnapshot( + items: readonly (LegacyDataId | NewDataItem)[], +): Promise { consola.debug("[importWorkflowFromSnapshot] start", { count: items?.length }); const hybridViewerStore = useHybridViewerStore(); const chunk_size = 5; - const chunks: NewDataItem[][] = []; + const chunks: (LegacyDataId | NewDataItem)[][] = []; for (let i = 0; i < items.length; i += chunk_size) { chunks.push(items.slice(i, i + chunk_size)); } diff --git a/app/utils/legacy_data_id.ts b/app/utils/legacy_data_id.ts new file mode 100644 index 000000000..a4ab3cd0c --- /dev/null +++ b/app/utils/legacy_data_id.ts @@ -0,0 +1,16 @@ +import type { DataId, DataIdentified } from "@ogw_front/types/identifiers"; + +// Temporary: the back-end, the viewer and the projects saved before data_id existed still name the data id `id` +type LegacyDataId = Omit & { id: DataId }; + +function fromLegacyDataId(row: LegacyDataId | Row): Row { + if ("data_id" in row) { + return row; + } + const { id, ...rest } = row; + // oxlint-disable-next-line no-unsafe-type-assertion -- the other fields of a legacy row are the other fields of Row. + return { ...rest, data_id: id } as unknown as Row; +} + +export type { LegacyDataId }; +export { fromLegacyDataId }; diff --git a/app/utils/slice.ts b/app/utils/slice.ts index ff11d3498..df3315c63 100644 --- a/app/utils/slice.ts +++ b/app/utils/slice.ts @@ -1,3 +1,5 @@ +import type { DataIdentified } from "@ogw_front/types/identifiers"; + const GRID_TYPES = new Set([ "RegularGrid2D", "LightRegularGrid2D", @@ -12,8 +14,11 @@ const SLICE_AXES = [ ] as const satisfies readonly { title: string; value: SliceAxis; next: SliceAxis }[]; const DEFAULT_SLICE_AXIS: SliceAxis = 2; -function areAllGrids(items: { id: string; geode_object_type: string }[], ids: string[]): boolean { - const targetedItems = items.filter((item) => ids.includes(item.id)); +function areAllGrids( + items: (DataIdentified & { geode_object_type: string })[], + ids: string[], +): boolean { + const targetedItems = items.filter((item) => ids.includes(item.data_id)); return ( targetedItems.length > 0 && targetedItems.every((item) => GRID_TYPES.has(item.geode_object_type)) diff --git a/internal/database/tables/data.ts b/internal/database/tables/data.ts index e21d5c7bd..855031e32 100644 --- a/internal/database/tables/data.ts +++ b/internal/database/tables/data.ts @@ -3,5 +3,5 @@ import type { TableDefinition } from "./table_definition"; export const dataTable: TableDefinition = { name: "data", schema: - "id, geode_id, name, viewer_type, geode_object_type, visible, created_at, binary_light_viewable", + "data_id, geode_id, name, viewer_type, geode_object_type, visible, created_at, binary_light_viewable", }; diff --git a/internal/database/tables/data_style.ts b/internal/database/tables/data_style.ts index 8ab9c3296..b67366e6a 100644 --- a/internal/database/tables/data_style.ts +++ b/internal/database/tables/data_style.ts @@ -2,5 +2,5 @@ import type { TableDefinition } from "./table_definition"; export const dataStyleTable: TableDefinition = { name: "data_style", - schema: "id", + schema: "data_id", }; diff --git a/internal/database/tables/model_components.ts b/internal/database/tables/model_components.ts index 0c964d829..83e96de1a 100644 --- a/internal/database/tables/model_components.ts +++ b/internal/database/tables/model_components.ts @@ -2,5 +2,5 @@ import type { TableDefinition } from "./table_definition"; export const modelComponentsTable: TableDefinition = { name: "model_components", - schema: "[id+geode_id], id, [id+type], viewer_id, name, is_active", + schema: "[data_id+geode_id], data_id, [data_id+type], viewer_id, name, is_active", }; diff --git a/internal/database/tables/model_components_relation.ts b/internal/database/tables/model_components_relation.ts index f2fdd343d..76972f55e 100644 --- a/internal/database/tables/model_components_relation.ts +++ b/internal/database/tables/model_components_relation.ts @@ -2,5 +2,5 @@ import type { TableDefinition } from "./table_definition"; export const modelComponentsRelationTable: TableDefinition = { name: "model_components_relation", - schema: "[id+parent+child], id, type", + schema: "[data_id+parent+child], data_id, type", }; diff --git a/internal/stores/data_style/mesh/index.ts b/internal/stores/data_style/mesh/index.ts index 16d9768a7..41958ab9e 100644 --- a/internal/stores/data_style/mesh/index.ts +++ b/internal/stores/data_style/mesh/index.ts @@ -127,7 +127,7 @@ export function useMeshStyle(): { key === "surfaces" || key === "blocks" || key === "attributes" || - key === "id" + key === "data_id" ) { // These keys are either handled elsewhere or not applicable to mesh objects continue; diff --git a/internal/stores/data_style/model/selection.ts b/internal/stores/data_style/model/selection.ts index 63d391871..6fadc4a45 100644 --- a/internal/stores/data_style/model/selection.ts +++ b/internal/stores/data_style/model/selection.ts @@ -1,12 +1,11 @@ -import type { GeodeIdentified } from "@ogw_front/types/identifiers"; +import type { DataIdentified, GeodeIdentified } from "@ogw_front/types/identifiers"; import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import type { Table } from "dexie"; import { database } from "@ogw_internal/database/database"; import type { useDataStyleState } from "@ogw_internal/stores/data_style/state"; -interface ModelComponentRecord extends GeodeIdentified { - id: string; +interface ModelComponentRecord extends DataIdentified, GeodeIdentified { type: string; } @@ -118,7 +117,7 @@ function useModelSelection( void (async (): Promise => { try { - allComponents.value = await model_components_db.where("id").equals(modelId).toArray(); + allComponents.value = await model_components_db.where("data_id").equals(modelId).toArray(); } catch { allComponents.value = []; } diff --git a/internal/stores/data_style/state.ts b/internal/stores/data_style/state.ts index 04894fe83..6f27f6deb 100644 --- a/internal/stores/data_style/state.ts +++ b/internal/stores/data_style/state.ts @@ -52,7 +52,7 @@ export function useDataStyleState(): DataStyleStateApi { function getStyle(objectId: string): ObjectStyle { const style = styles.value[objectId]; if (style === undefined) { - return { id: objectId }; + return { data_id: objectId }; } return { ...toRaw(style) }; } @@ -62,7 +62,7 @@ export function useDataStyleState(): DataStyleStateApi { const currentStyle = getStyle(objectId); merge(currentStyle, styleValues); const savedId = await dataStyleTable.put( - structuredClone({ ...toRaw(currentStyle), id: objectId }), + structuredClone({ ...toRaw(currentStyle), data_id: objectId }), ); return savedId; } diff --git a/internal/stores/data_style/state_shared.ts b/internal/stores/data_style/state_shared.ts index 4108a6ad0..e9828bf3f 100644 --- a/internal/stores/data_style/state_shared.ts +++ b/internal/stores/data_style/state_shared.ts @@ -64,7 +64,7 @@ function getSharedState(): SharedState { const objectStyles = await dataStyleTable.toArray(); const stylesByObjectId: Record = {}; for (const objectStyle of objectStyles) { - stylesByObjectId[objectStyle.id] = objectStyle; + stylesByObjectId[objectStyle.data_id] = objectStyle; } return stylesByObjectId; }); @@ -176,7 +176,7 @@ function getSharedState(): SharedState { } function updateStyleCache(objectId: string, styleValues: StyleValues): void { - styles.value[objectId] ??= { id: objectId }; + styles.value[objectId] ??= { data_id: objectId }; merge(styles.value[objectId], styleValues); } diff --git a/internal/stores/data_style/types.ts b/internal/stores/data_style/types.ts index 032057f46..7fb674601 100644 --- a/internal/stores/data_style/types.ts +++ b/internal/stores/data_style/types.ts @@ -1,9 +1,9 @@ +import type { DataIdentified } from "@ogw_front/types/identifiers"; import type { RGBAColor } from "@ogw_front/utils/default_styles/constants"; type StyleValues = Record; -interface ObjectStyle { - id: string; +interface ObjectStyle extends DataIdentified { visibility?: boolean; color?: unknown; points?: StyleValues; diff --git a/internal/stores/hybrid_viewer/highlight.ts b/internal/stores/hybrid_viewer/highlight.ts index df40d46a3..6c361d1bc 100644 --- a/internal/stores/hybrid_viewer/highlight.ts +++ b/internal/stores/hybrid_viewer/highlight.ts @@ -24,7 +24,7 @@ async function lookupComponentInfo( if (geodeId === undefined || !modelComponentsTable) { return undefined; } - const components = modelComponentsTable.where("[id+geode_id]"); + const components = modelComponentsTable.where("[data_id+geode_id]"); const query = components.equals([modelId, geodeId] as IndexableType); const component = (await query.first()) as | (Partial & { name?: string; type?: string }) diff --git a/tests/unit/components/ComponentRelations.nuxt.test.ts b/tests/unit/components/ComponentRelations.nuxt.test.ts index 5d2ec2fd6..4fc507c60 100644 --- a/tests/unit/components/ComponentRelations.nuxt.test.ts +++ b/tests/unit/components/ComponentRelations.nuxt.test.ts @@ -28,7 +28,7 @@ describe("component relations", () => { const dataStore = useDataStore(); await dataStore.clear(); const model = { - id: MODEL_ID, + data_id: MODEL_ID, geode_id: MODEL_ID, viewer_type: "model", geode_object_type: "Section", diff --git a/tests/unit/components/FactorFilterPanel.nuxt.test.ts b/tests/unit/components/FactorFilterPanel.nuxt.test.ts index eb9c62628..c6969d2cc 100644 --- a/tests/unit/components/FactorFilterPanel.nuxt.test.ts +++ b/tests/unit/components/FactorFilterPanel.nuxt.test.ts @@ -19,9 +19,9 @@ const TIMEOUT = 5000; type SetFactor = (ids: string[], factor: number) => Promise; vi.mock(import("@ogw_front/stores/data") as Promise, () => ({ - useDataStore: (): { refRegisteredItems: () => Ref<{ id: string; name: string }[]> } => ({ - refRegisteredItems: (): Ref<{ id: string; name: string }[]> => - ref([{ id: DATA_ID, name: "model" }]), + useDataStore: (): { refRegisteredItems: () => Ref<{ data_id: string; name: string }[]> } => ({ + refRegisteredItems: (): Ref<{ data_id: string; name: string }[]> => + ref([{ data_id: DATA_ID, name: "model" }]), }), })); vi.mock(import("@ogw_front/stores/hybrid_viewer") as Promise, () => ({ diff --git a/tests/unit/components/InfoCard.nuxt.test.ts b/tests/unit/components/InfoCard.nuxt.test.ts index 0532520c1..ee224e3bb 100644 --- a/tests/unit/components/InfoCard.nuxt.test.ts +++ b/tests/unit/components/InfoCard.nuxt.test.ts @@ -24,7 +24,7 @@ describe("info card crs", () => { crsStore.enableCrsEdit(); const wrapper = await mountSuspended(InfoCard, { global: { plugins: [vuetify, pinia] }, - props: { show: true, metaData: { id: "data-1", name: "cube", crs: LAMBERT } }, + props: { show: true, metaData: { data_id: "data-1", name: "cube", crs: LAMBERT } }, }); // The card is narrow: the code alone, the full name is in the tooltip expect(wrapper.get('[data-testid="infoCrsValue"]').text()).toBe("EPSG:2154"); @@ -38,7 +38,7 @@ describe("info card crs", () => { test("hides the edit button when the host app cannot edit", async () => { const wrapper = await mountSuspended(InfoCard, { global: { plugins: [vuetify, pinia] }, - props: { show: true, metaData: { id: "data-2", name: "cube" } }, + props: { show: true, metaData: { data_id: "data-2", name: "cube" } }, }); expect(wrapper.get('[data-testid="infoCrsValue"]').text()).toBe("None"); expect(wrapper.find('[data-testid="infoEditCrsBtn"]').exists()).toBe(false); @@ -47,7 +47,7 @@ describe("info card crs", () => { test("has no crs row for a model component", async () => { const wrapper = await mountSuspended(InfoCard, { global: { plugins: [vuetify, pinia] }, - props: { show: true, metaData: { id: "comp-1", modelId: "model-1", name: "Block" } }, + props: { show: true, metaData: { modelId: "model-1", name: "Block" } }, }); expect(wrapper.find('[data-testid="infoCrsValue"]').exists()).toBe(false); }); @@ -55,11 +55,11 @@ describe("info card crs", () => { test("shows the crs stored after an edit, not the one captured when the menu opened", async () => { const dataStore = useDataStore(); dataStore.refItem = mockAs( - vi.fn<() => unknown>().mockReturnValue(ref({ id: "data-3", crs: UTM })), + vi.fn<() => unknown>().mockReturnValue(ref({ data_id: "data-3", crs: UTM })), ); const wrapper = await mountSuspended(InfoCard, { global: { plugins: [vuetify, pinia] }, - props: { show: true, metaData: { id: "data-3", name: "cube", crs: LAMBERT } }, + props: { show: true, metaData: { data_id: "data-3", name: "cube", crs: LAMBERT } }, }); expect(wrapper.get('[data-testid="infoCrsValue"]').text()).toBe("EPSG:32631"); }); diff --git a/tests/unit/components/ItemLabel.nuxt.test.ts b/tests/unit/components/ItemLabel.nuxt.test.ts index 202a5215e..39c5546ef 100644 --- a/tests/unit/components/ItemLabel.nuxt.test.ts +++ b/tests/unit/components/ItemLabel.nuxt.test.ts @@ -61,7 +61,7 @@ describe("item label tooltip", () => { const LAMBERT = { authority: "EPSG", code: "2154", name: "RGF93 v1 / Lambert-93" }; const dataStore = useDataStore(); dataStore.refItem = mockAs( - vi.fn<() => unknown>().mockReturnValue(ref({ id: DATA_ID, crs: LAMBERT })), + vi.fn<() => unknown>().mockReturnValue(ref({ data_id: DATA_ID, crs: LAMBERT })), ); const crsStore = useCrsStore(); crsStore.enableCrsEdit(); @@ -80,7 +80,7 @@ describe("item label tooltip", () => { test("does not read the stored item while the tooltip is closed", async () => { const dataStore = useDataStore(); - const refItem = vi.fn<() => unknown>().mockReturnValue(ref({ id: DATA_ID })); + const refItem = vi.fn<() => unknown>().mockReturnValue(ref({ data_id: DATA_ID })); dataStore.refItem = mockAs(refItem); await mountSuspended(ItemLabel, { global: { plugins: [vuetify, pinia], stubs: { VTooltip: VTooltipStub } }, @@ -105,8 +105,8 @@ describe("item label tooltip", () => { const LAMBERT = { authority: "EPSG", code: "2154", name: "RGF93 v1 / Lambert-93" }; const OTHER_ID = "b".repeat(DATA_ID_LENGTH); const items: Record = { - [DATA_ID]: { id: DATA_ID }, - [OTHER_ID]: { id: OTHER_ID, crs: LAMBERT }, + [DATA_ID]: { data_id: DATA_ID }, + [OTHER_ID]: { data_id: OTHER_ID, crs: LAMBERT }, }; const dataStore = useDataStore(); dataStore.refItem = mockAs( @@ -136,9 +136,9 @@ describe("item label crs mismatch", () => { const dataStore = useDataStore(); dataStore.refCrsItems = mockAs(() => ref([ - { id: "a", created_at: "1", crs: LAMBERT }, - { id: "b", created_at: "2", crs: UTM }, - { id: "local", created_at: "3" }, + { data_id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "b", created_at: "2", crs: UTM }, + { data_id: "local", created_at: "3" }, ]), ); useCrsStore(); diff --git a/tests/unit/components/TimeSeriesTargetSelector.nuxt.test.ts b/tests/unit/components/TimeSeriesTargetSelector.nuxt.test.ts index b36cfa606..18086fdfb 100644 --- a/tests/unit/components/TimeSeriesTargetSelector.nuxt.test.ts +++ b/tests/unit/components/TimeSeriesTargetSelector.nuxt.test.ts @@ -21,8 +21,8 @@ describe("time series target selector", () => { const dataStore = useDataStore(pinia); dataStore.allItems = mockAs( vi.fn().mockResolvedValue([ - { id: "brep_id", name: "cube", geode_object_type: "BRep" }, - { id: "points_id", name: "points", geode_object_type: "PointSet3D" }, + { data_id: "brep_id", name: "cube", geode_object_type: "BRep" }, + { data_id: "points_id", name: "points", geode_object_type: "PointSet3D" }, ]), ); const wrapper = await mountSuspended(TimeSeriesTargetSelector, { diff --git a/tests/unit/composables/project_manager.nuxt.test.ts b/tests/unit/composables/project_manager.nuxt.test.ts index 09179509a..e7d61e618 100644 --- a/tests/unit/composables/project_manager.nuxt.test.ts +++ b/tests/unit/composables/project_manager.nuxt.test.ts @@ -39,7 +39,7 @@ const snapshotMock = { data: { items: [ { - id: "abc123", + data_id: "abc123", geode_id: "11111111-1111-1111-1111-111111111111", viewer_type: "mesh", geode_object_type: "PointSet2D", @@ -370,7 +370,7 @@ describe("projectManager composable (compact)", () => { Reflect.deleteProperty(snapshotMock, "crs"); data.items = mockAs([ { ...savedItems[0], crs: utm, created_at: "2026-01-02T00:00:00.000Z" }, - { ...savedItems[0], id: "older", crs: lambert, created_at: "2026-01-01T00:00:00.000Z" }, + { ...savedItems[0], data_id: "older", crs: lambert, created_at: "2026-01-01T00:00:00.000Z" }, ]); try { await importProject(file); diff --git a/tests/unit/plugins/project_load.nuxt.test.ts b/tests/unit/plugins/project_load.nuxt.test.ts index 053d4f059..16b3ed72e 100644 --- a/tests/unit/plugins/project_load.nuxt.test.ts +++ b/tests/unit/plugins/project_load.nuxt.test.ts @@ -4,8 +4,6 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; import type { StoreGeneric } from "pinia"; -import type { ModelComponentRecord } from "@ogw_front/stores/data_helpers/mesh.js"; -import type { ModelComponentRelationRecord } from "@ogw_front/stores/data.js"; import { useAppStore } from "@ogw_front/stores/app"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; @@ -80,10 +78,9 @@ describe("project import", () => { // Flagging for review rather than silently changing behavior during the TS migration. vi.spyOn(stores.dataBase, "importStores").mockImplementation( async ( - snapshot: { - readonly modelComponents: readonly ModelComponentRecord[]; - readonly modelComponentsRelations: readonly ModelComponentRelationRecord[]; - } & { items?: Record[] }, + snapshot: Parameters[0] & { + items?: Record[]; + }, ) => { const { items } = snapshot; await Promise.all( @@ -104,7 +101,7 @@ describe("project import", () => { data: { items: [ { - id: "abc123", + data_id: "abc123", viewer_type: "mesh", geode_object_type: "PointSet2D", native_file: "native.ext", @@ -135,10 +132,10 @@ describe("project import", () => { const item = await database.data?.get("abc123"); expect(item).toBeDefined(); - expect(item?.id).toBe("abc123"); + expect(item?.data_id).toBe("abc123"); const style = await database.data_style?.get("abc123"); expect(style).toBeDefined(); - expect(style?.id).toBe("abc123"); + expect(style?.data_id).toBe("abc123"); }); }); diff --git a/tests/unit/stores/basemap.nuxt.test.ts b/tests/unit/stores/basemap.nuxt.test.ts index dbad51fb8..3bc59cdc3 100644 --- a/tests/unit/stores/basemap.nuxt.test.ts +++ b/tests/unit/stores/basemap.nuxt.test.ts @@ -47,9 +47,9 @@ function buildResponse(id: string): Record { function georeferenced(): DataItem[] { return mockAs([ - { id: "a", created_at: "1", crs: LAMBERT }, - { id: "b", created_at: "2" }, - { id: "c", created_at: "3", crs: LAMBERT }, + { data_id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "b", created_at: "2" }, + { data_id: "c", created_at: "3", crs: LAMBERT }, ]); } @@ -252,13 +252,13 @@ describe("basemap store", () => { expect(backRequest).toHaveBeenCalledTimes(ONCE); items.value = [ ...georeferenced(), - mockAs({ id: "d", created_at: "4", crs: LAMBERT }), + mockAs({ data_id: "d", created_at: "4", crs: LAMBERT }), ]; await nextTick(); vi.advanceTimersByTime(HALF_DELAY); items.value = [ ...georeferenced(), - mockAs({ id: "e", created_at: "5", crs: LAMBERT }), + mockAs({ data_id: "e", created_at: "5", crs: LAMBERT }), ]; await nextTick(); await vi.advanceTimersByTimeAsync(REBUILD_DELAY); @@ -271,7 +271,7 @@ describe("basemap store", () => { const store = setup(); await store.setMaps(["satellite"]); expect(store.available).toBe(true); - items.value = mockAs([{ id: "a", created_at: "1" }]); + items.value = mockAs([{ data_id: "a", created_at: "1" }]); await nextTick(); await vi.advanceTimersByTimeAsync(REBUILD_DELAY); // The viewer lets the mesh go before the back deletes its files @@ -505,8 +505,8 @@ describe("basemap store", () => { test("data in another crs than the project stays out of the basemap", async () => { const store = setup(); items.value = mockAs([ - { id: "a", created_at: "1", crs: LAMBERT }, - { id: "c", created_at: "3", crs: { authority: "EPSG", code: "32631", name: "UTM" } }, + { data_id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "c", created_at: "3", crs: { authority: "EPSG", code: "32631", name: "UTM" } }, ]); await nextTick(); await store.setMaps(["satellite"]); diff --git a/tests/unit/stores/basemap_detail.nuxt.test.ts b/tests/unit/stores/basemap_detail.nuxt.test.ts index 17fbed8fa..a782d7219 100644 --- a/tests/unit/stores/basemap_detail.nuxt.test.ts +++ b/tests/unit/stores/basemap_detail.nuxt.test.ts @@ -201,7 +201,7 @@ describe("basemap detail store", () => { const viewerStore = useViewerStore(); viewerStore.request = mockAs(viewerRequest); const dataStore = useDataStore(); - const items = ref(mockAs([{ id: FIRST_DATA, created_at: "1", crs: LAMBERT }])); + const items = ref(mockAs([{ data_id: FIRST_DATA, created_at: "1", crs: LAMBERT }])); dataStore.refCrsItems = mockAs(() => items); dataStore.registerObject = mockAs( vi.fn().mockResolvedValue({}), diff --git a/tests/unit/stores/crs.nuxt.test.ts b/tests/unit/stores/crs.nuxt.test.ts index 9ee6dfce3..d8d1bb3b0 100644 --- a/tests/unit/stores/crs.nuxt.test.ts +++ b/tests/unit/stores/crs.nuxt.test.ts @@ -92,21 +92,21 @@ describe("project crs", () => { test("follows when every georeferenced data is in one crs", async () => { const data = mockItems([]); const crsStore = useCrsStore(); - data.value = mockAs([{ id: "a", created_at: "1", crs: LAMBERT }]); + data.value = mockAs([{ data_id: "a", created_at: "1", crs: LAMBERT }]); await nextTick(); expect(crsStore.projectCrs).toStrictEqual(LAMBERT); // One data converted alone: mixed, the project keeps its crs data.value = mockAs([ - { id: "a", created_at: "1", crs: UTM }, - { id: "b", created_at: "2", crs: LAMBERT }, - { id: "local", created_at: "3" }, + { data_id: "a", created_at: "1", crs: UTM }, + { data_id: "b", created_at: "2", crs: LAMBERT }, + { data_id: "local", created_at: "3" }, ]); await nextTick(); expect(crsStore.projectCrs).toStrictEqual(LAMBERT); data.value = mockAs([ - { id: "a", created_at: "1", crs: UTM }, - { id: "b", created_at: "2", crs: UTM }, - { id: "local", created_at: "3" }, + { data_id: "a", created_at: "1", crs: UTM }, + { data_id: "b", created_at: "2", crs: UTM }, + { data_id: "local", created_at: "3" }, ]); await nextTick(); expect(crsStore.projectCrs).toStrictEqual(UTM); @@ -115,8 +115,8 @@ describe("project crs", () => { test("an imported project crs is kept while the data are mixed", async () => { mockItems( mockAs([ - { id: "a", created_at: "1", crs: LAMBERT }, - { id: "b", created_at: "2", crs: UTM }, + { data_id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "b", created_at: "2", crs: UTM }, ]), ); const crsStore = useCrsStore(); @@ -128,9 +128,9 @@ describe("project crs", () => { test("lists the data in another crs than the project", () => { mockItems( mockAs([ - { id: "a", created_at: "1", crs: LAMBERT }, - { id: "b", created_at: "2", crs: UTM }, - { id: "local", created_at: "3" }, + { data_id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "b", created_at: "2", crs: UTM }, + { data_id: "local", created_at: "3" }, ]), ); const crsStore = useCrsStore(); @@ -142,7 +142,7 @@ describe("project crs", () => { }); test("is exported and imported with the project", () => { - mockItems(mockAs([{ id: "a", created_at: "1", crs: LAMBERT }])); + mockItems(mockAs([{ data_id: "a", created_at: "1", crs: LAMBERT }])); const crsStore = useCrsStore(); crsStore.setProjectCrs(UTM); expect(crsStore.exportStores()).toStrictEqual({ projectCrs: UTM }); @@ -155,8 +155,8 @@ describe("project crs", () => { test("a project saved without it takes the crs of its oldest georeferenced data", () => { mockItems( mockAs([ - { id: "b", created_at: "2", crs: UTM }, - { id: "a", created_at: "1", crs: LAMBERT }, + { data_id: "b", created_at: "2", crs: UTM }, + { data_id: "a", created_at: "1", crs: LAMBERT }, ]), ); const crsStore = useCrsStore(); diff --git a/tests/unit/stores/data.nuxt.test.ts b/tests/unit/stores/data.nuxt.test.ts index 46d4494bf..1cd571e29 100644 --- a/tests/unit/stores/data.nuxt.test.ts +++ b/tests/unit/stores/data.nuxt.test.ts @@ -26,7 +26,7 @@ describe("useDataStore - collections", () => { const dataId = "a".repeat(DATA_ID_LENGTH); const geodeId = "01a08187-2c4c-7e64-85c5-52c3439f0626"; await dataStore.addItem({ - id: dataId, + data_id: dataId, geode_id: geodeId, name: "cube", viewer_type: "model", @@ -41,7 +41,7 @@ describe("useDataStore - collections", () => { const dataId = "b".repeat(DATA_ID_LENGTH); const crs = { authority: "EPSG", code: "2154", name: "RGF93 v1 / Lambert-93" }; await dataStore.addItem({ - id: dataId, + data_id: dataId, geode_id: "01a08187-2c4c-7e64-85c5-52c3439f0627", name: "points", viewer_type: "mesh", @@ -63,7 +63,7 @@ describe("useDataStore - collections", () => { }; const line1 = { ...component("line1", "Line", 2), boundaries: ["corner"] }; const model = { - id: modelId, + data_id: modelId, geode_id: modelId, viewer_type: "model", geode_object_type: "Section", @@ -79,7 +79,7 @@ describe("useDataStore - collections", () => { await dataStore.addComponentRelations(model); const otherModel = { ...model, - id: otherModelId, + data_id: otherModelId, mesh_components: [{ ...surface, boundaries: ["line2"], internals: [] }], }; await dataStore.addComponents(otherModel); @@ -111,23 +111,23 @@ describe("useDataStore - collections", () => { // Standard viewable item (BRep) expect( - dataStore.isItemViewable({ id: "1", title: "BRep 1", geode_object_type: "BRep" }), + dataStore.isItemViewable({ data_id: "1", title: "BRep 1", geode_object_type: "BRep" }), ).toBe(true); // Group node for viewable type - expect(dataStore.isItemViewable({ id: "BRep", title: "BRep" })).toBe(true); + expect(dataStore.isItemViewable({ data_id: "BRep", title: "BRep" })).toBe(true); // HorizonStack3D leaf item expect( dataStore.isItemViewable({ - id: "2", + data_id: "2", title: "HS 1", geode_object_type: "HorizonStack3D", }), ).toBe(false); // HorizonStack3D group node - expect(dataStore.isItemViewable({ id: "HorizonStack3D", title: "HorizonStack3D" })).toBe( + expect(dataStore.isItemViewable({ data_id: "HorizonStack3D", title: "HorizonStack3D" })).toBe( false, ); }); diff --git a/tests/unit/stores/data_collection_components.nuxt.test.ts b/tests/unit/stores/data_collection_components.nuxt.test.ts index 5ca51d108..21306a428 100644 --- a/tests/unit/stores/data_collection_components.nuxt.test.ts +++ b/tests/unit/stores/data_collection_components.nuxt.test.ts @@ -21,7 +21,7 @@ describe("useDataStore - collections", () => { // 1. Add model item await dataStore.addItem({ - id: modelId, + data_id: modelId, geode_id: "00000000-0000-0000-0000-000000000001", name: "Test Model", viewer_type: "model", @@ -30,7 +30,7 @@ describe("useDataStore - collections", () => { // 2. Add mesh components and collection components (including a custom type like "MyCustomCollection") await dataStore.addComponents({ - id: modelId, + data_id: modelId, geode_id: "00000000-0000-0000-0000-000000000001", viewer_type: "model", geode_object_type: "BRep", @@ -66,7 +66,7 @@ describe("useDataStore - collections", () => { // Add component relations await dataStore.addComponentRelations({ - id: modelId, + data_id: modelId, geode_id: "00000000-0000-0000-0000-000000000001", viewer_type: "model", geode_object_type: "BRep", diff --git a/tests/unit/stores/data_registered_items.nuxt.test.ts b/tests/unit/stores/data_registered_items.nuxt.test.ts index 691c15705..c5d7167b1 100644 --- a/tests/unit/stores/data_registered_items.nuxt.test.ts +++ b/tests/unit/stores/data_registered_items.nuxt.test.ts @@ -13,7 +13,7 @@ async function addItems(ids: string[]): Promise { for (const id of ids) { // oxlint-disable-next-line no-await-in-loop await dataStore.addItem({ - id, + data_id: id, geode_id: id, name: id, viewer_type: "mesh", @@ -22,8 +22,8 @@ async function addItems(ids: string[]): Promise { } } -function registeredIds(items: { id: string }[]): string[] { - return items.map((registeredItem) => registeredItem.id); +function registeredIds(items: { data_id: string }[]): string[] { + return items.map((registeredItem) => registeredItem.data_id); } describe("useDataStore - collections", () => { diff --git a/tests/unit/stores/mesh_style.nuxt.test.ts b/tests/unit/stores/mesh_style.nuxt.test.ts new file mode 100644 index 000000000..7636ec0b6 --- /dev/null +++ b/tests/unit/stores/mesh_style.nuxt.test.ts @@ -0,0 +1,18 @@ +import { beforeEach, describe, expect, test } from "vitest"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; +import { useMeshStyle } from "@ogw_internal/stores/data_style/mesh/index"; + +const MESH_ID = "mesh-1"; + +describe("mesh style", () => { + beforeEach(() => { + setupActivePinia(); + }); + + test("applying a style holding only its data_id applies nothing", async () => { + await useDataStyleState().mutateStyle(MESH_ID, {}); + + await expect(useMeshStyle().applyMeshStyle(MESH_ID)).resolves.toStrictEqual([]); + }); +}); diff --git a/tests/unit/utils/import_workflow.nuxt.test.ts b/tests/unit/utils/import_workflow.nuxt.test.ts index 8cc4d3419..334665a67 100644 --- a/tests/unit/utils/import_workflow.nuxt.test.ts +++ b/tests/unit/utils/import_workflow.nuxt.test.ts @@ -132,7 +132,7 @@ describe("import workflow", () => { ]), ).rejects.toThrow("1 file(s) could not be imported"); expect(dataStore.addItem).toHaveBeenCalledWith( - expect.objectContaining({ id: "model.og_brep" }), + expect.objectContaining({ data_id: "model.og_brep" }), ); expect(remoteRender).toHaveBeenCalledWith(); }); diff --git a/tests/unit/utils/legacy_data_id.nuxt.test.ts b/tests/unit/utils/legacy_data_id.nuxt.test.ts new file mode 100644 index 000000000..2e5d03d6d --- /dev/null +++ b/tests/unit/utils/legacy_data_id.nuxt.test.ts @@ -0,0 +1,76 @@ +import { beforeEach, describe, expect, test } from "vitest"; +import type { DataIdentified } from "@ogw_front/types/identifiers"; +import { database } from "@ogw_internal/database/database.js"; +import { fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; + +interface NamedData extends DataIdentified { + name: string; +} + +const DATA_ID = "data-1"; +const GEODE_ID = "00000000-0000-0000-0000-000000000001"; + +describe("legacy data id", () => { + test("a legacy row takes its id as data_id", () => { + expect(fromLegacyDataId({ id: DATA_ID, name: "cube" })).toStrictEqual({ + data_id: DATA_ID, + name: "cube", + }); + }); + + test("a row with a data_id is kept as it is", () => { + const row = { data_id: DATA_ID, name: "cube" }; + expect(fromLegacyDataId(row)).toBe(row); + }); + + describe("stores importing a project saved with the legacy id", () => { + beforeEach(() => { + setupActivePinia(); + }); + + test("the data store stores the components and relations with a data_id", async () => { + const dataStore = useDataStore(); + await dataStore.importStores({ + modelComponents: [ + { + id: DATA_ID, + geode_id: GEODE_ID, + type: "Surface", + viewer_id: 1, + name: "surface", + is_active: true, + }, + ], + modelComponentsRelations: [{ id: DATA_ID, parent: "a", child: "b", type: "boundary" }], + }); + + const components = await database.model_components + ?.where("data_id") + .equals(DATA_ID) + .toArray(); + expect(components).toHaveLength(1); + expect(components?.[0]).not.toHaveProperty("id"); + const relations = await database.model_components_relation + ?.where("data_id") + .equals(DATA_ID) + .toArray(); + expect(relations).toHaveLength(1); + expect(relations?.[0]).not.toHaveProperty("id"); + }); + + test("the data style store stores the styles with a data_id", async () => { + const dataStyleStore = useDataStyleStore(); + await dataStyleStore.importStores({ + styles: { [DATA_ID]: { id: DATA_ID, visibility: true } }, + componentStyles: {}, + modelComponentTypeStyles: {}, + }); + + const style = await database.data_style?.get(DATA_ID); + expect(style).toStrictEqual({ data_id: DATA_ID, visibility: true }); + }); + }); +}); From 3461e37c5e95eb1381db04e7d5bbc586bd5840e6 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 6 Nov 2026 19:01:07 +0100 Subject: [PATCH 03/62] fix(types): define geode_object_type once as GeodeObjectType and GeodeObjectTyped geode_object_type was redeclared as an inline `string` in the data items, the tree, the menu and the pickers. Define the GeodeObjectType alias and the GeodeObjectTyped mixin in app/types/identifiers.ts and extend it (Partial for the optional ones, the alias where the type is `string | undefined` or a parameter). Co-Authored-By: Claude Sonnet 5.5 --- app/components/ObjectSelector.vue | 3 ++- app/components/TimeSeriesTargetSelector.vue | 6 +++--- .../Viewer/ObjectTree/Views/GlobalObjects.vue | 4 ++-- .../Viewer/OverlappingObjectsPicker.vue | 3 ++- app/composables/clipping_slices.ts | 4 ++-- app/composables/use_overlapping_picker.ts | 3 ++- app/stores/crs.ts | 5 +++-- app/stores/data.ts | 10 ++++------ app/stores/menu.ts | 5 ++--- app/stores/treeview.ts | 17 ++++++++++------- app/types/identifiers.ts | 9 ++++++++- app/utils/import_workflow.ts | 6 +++--- app/utils/slice.ts | 4 ++-- 13 files changed, 45 insertions(+), 34 deletions(-) diff --git a/app/components/ObjectSelector.vue b/app/components/ObjectSelector.vue index 15a13ec18..53781e65b 100644 --- a/app/components/ObjectSelector.vue +++ b/app/components/ObjectSelector.vue @@ -5,6 +5,7 @@ import { resolveAllowedObjectsPerFile, } from "@ogw_shared/utils/response_handlers/load.js"; import FetchingData from "@ogw_front/components/FetchingData.vue"; +import type { GeodeObjectType } from "@ogw_front/types/identifiers"; import { geode_objects } from "@ogw_front/assets/geode_objects"; import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; import { useBackStore } from "@ogw_front/stores/back"; @@ -65,7 +66,7 @@ function emitGeodeObjectTypes(geode_object_types: Record): void emit("increment_step"); } -function setGeodeObject(geode_object_type: string | undefined): void { +function setGeodeObject(geode_object_type: GeodeObjectType | undefined): void { if (!geode_object_type) { return; } diff --git a/app/components/TimeSeriesTargetSelector.vue b/app/components/TimeSeriesTargetSelector.vue index 9b66bf7e2..83dffcf01 100644 --- a/app/components/TimeSeriesTargetSelector.vue +++ b/app/components/TimeSeriesTargetSelector.vue @@ -1,20 +1,20 @@