@geode/opengeodeweb-front 11.2.0-rc.2 → 11.2.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,10 +62,10 @@ function handleRowClick(event: MouseEvent): void {
62
62
 
63
63
  <div class="d-flex align-center flex-shrink-0">
64
64
  <v-icon
65
- v-if="!item.isLeaf"
65
+ v-if="item.isExpandable"
66
66
  :data-testid="item.isOpen ? 'collapseTreeRowButton' : 'expandTreeRowButton'"
67
67
  :icon="item.isOpen ? 'mdi-menu-down' : 'mdi-menu-right'"
68
- class="me-1"
68
+ :class="item.isLeaf ? 'icon-placeholder' : 'me-1'"
69
69
  color="black"
70
70
  @click.stop="$emit('toggle-open', item.raw)"
71
71
  />
@@ -22,6 +22,7 @@ interface CollectionTreeItem {
22
22
  id: string;
23
23
  category?: string;
24
24
  children?: CollectionTreeItem[];
25
+ relation?: string;
25
26
  viewer_id?: number;
26
27
  title?: string;
27
28
  }
@@ -41,6 +42,7 @@ const {
41
42
  localCategories,
42
43
  cache,
43
44
  collectionTypes,
45
+ withRelations,
44
46
  selection: visibleComponents,
45
47
  updateVisibility,
46
48
  } = useModelTree(id);
@@ -109,10 +111,11 @@ const itemsForTreeView = computed<CollectionTreeItem[]>(() => {
109
111
  result.push({
110
112
  ...category,
111
113
  id: categoryId,
112
- children: sortAndFormatItems(
113
- cache.value?.[categoryId],
114
+ children: withRelations(
115
+ categoryId,
116
+ sortAndFormatItems(cache.value?.[categoryId], sortType.value) as CollectionTreeItem[],
114
117
  sortType.value,
115
- ) as unknown as CollectionTreeItem[],
118
+ ),
116
119
  });
117
120
  }
118
121
  return result;
@@ -131,6 +134,10 @@ function isCollectionNode(item: CollectionTreeItem): boolean {
131
134
 
132
135
  function showContextMenu(event: MouseEvent, item: CollectionTreeItem): void {
133
136
  const actualItem = item.raw || item;
137
+ // A boundaries or internals group is not a component type: it has no menu
138
+ if (actualItem.relation !== undefined) {
139
+ return;
140
+ }
134
141
  if (isCollectionNode(actualItem)) {
135
142
  emit("show-menu", {
136
143
  event,
@@ -2,10 +2,12 @@ import type {
2
2
  CollectionComponent,
3
3
  CollectionComponentGroup,
4
4
  } from "@ogw_front/stores/data_helpers/collections";
5
+ import { type FilterableItem, sortAndFormatItems } from "@ogw_front/composables/tree_filter";
5
6
  import type {
6
7
  FormattedComponent,
7
8
  FormattedComponentGroup,
8
9
  } from "@ogw_front/stores/data_helpers/mesh";
10
+ import type { ComponentRelations } from "@ogw_front/stores/data_helpers/relations";
9
11
  import type { ModelId } from "@ogw_front/types/identifiers";
10
12
  import { compareSelections } from "@ogw_front/utils/treeview";
11
13
  import { useDataStore } from "@ogw_front/stores/data";
@@ -15,6 +17,34 @@ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
15
17
  type ModelTreeCategory = FormattedComponentGroup | CollectionComponentGroup;
16
18
  type ModelTreeCache = Record<string, (FormattedComponent | CollectionComponent)[]>;
17
19
 
20
+ interface RelationGroup {
21
+ readonly id: string;
22
+ readonly title: string;
23
+ readonly relation: keyof ComponentRelations;
24
+ readonly children: FilterableItem[];
25
+ }
26
+
27
+ const RELATION_GROUPS: readonly { key: keyof ComponentRelations; label: string }[] = [
28
+ { key: "boundaries", label: "Boundaries" },
29
+ { key: "internals", label: "Internals" },
30
+ ];
31
+
32
+ // The boundaries and internals of a component, one group each, shown under it in the tree
33
+ function relationGroups(
34
+ componentId: string,
35
+ componentRelations: ComponentRelations,
36
+ sortType: string,
37
+ ): RelationGroup[] {
38
+ return RELATION_GROUPS.filter(({ key }) => componentRelations[key].length > 0).map(
39
+ ({ key, label }) => ({
40
+ id: `${componentId}:${key}`,
41
+ title: `${label} (${componentRelations[key].length})`,
42
+ relation: key,
43
+ children: sortAndFormatItems(componentRelations[key], sortType),
44
+ }),
45
+ );
46
+ }
47
+
18
48
  function useModelVisibility(modelId: ModelId): {
19
49
  selection: typeof selection;
20
50
  updateVisibility: typeof updateVisibility;
@@ -39,11 +69,84 @@ function useModelVisibility(modelId: ModelId): {
39
69
  return { selection, updateVisibility };
40
70
  }
41
71
 
72
+ type WithRelationDetails<Component> = Component & { details?: RelationGroup[] };
73
+
74
+ // Components get their relations as details: expanding one lists them without making it a
75
+ // Branch, so its own visibility stays its own. The groups of a component are built once per sort:
76
+ // Recomputing the tree (filter, search, cache update) reuses them instead of rebuilding them all
77
+ function useRelationDetails(): {
78
+ setRelations: (relations: Record<string, ComponentRelations>) => void;
79
+ attach: <Component extends { readonly id: string }>(
80
+ components: readonly Component[],
81
+ sortType: string,
82
+ ) => WithRelationDetails<Component>[];
83
+ } {
84
+ const relations = shallowRef<Readonly<Record<string, ComponentRelations>>>({});
85
+ const groupsByComponent = new Map<string, RelationGroup[]>();
86
+ let groupsSortType: string | undefined = undefined;
87
+
88
+ function setRelations(newRelations: Record<string, ComponentRelations>): void {
89
+ groupsByComponent.clear();
90
+ relations.value = markRaw(newRelations);
91
+ }
92
+
93
+ function groupsOf(
94
+ componentId: string,
95
+ componentRelations: ComponentRelations,
96
+ sortType: string,
97
+ ): RelationGroup[] {
98
+ if (sortType !== groupsSortType) {
99
+ groupsByComponent.clear();
100
+ groupsSortType = sortType;
101
+ }
102
+ let groups = groupsByComponent.get(componentId);
103
+ if (groups === undefined) {
104
+ groups = relationGroups(componentId, componentRelations, sortType);
105
+ groupsByComponent.set(componentId, groups);
106
+ }
107
+ return groups;
108
+ }
109
+
110
+ function attach<Component extends { readonly id: string }>(
111
+ components: readonly Component[],
112
+ sortType: string,
113
+ ): WithRelationDetails<Component>[] {
114
+ return components.map((component) => {
115
+ const componentRelations = relations.value[component.id];
116
+ if (!componentRelations) {
117
+ return component;
118
+ }
119
+ return { ...component, details: groupsOf(component.id, componentRelations, sortType) };
120
+ });
121
+ }
122
+
123
+ return { setRelations, attach };
124
+ }
125
+
126
+ async function fetchModelTreeData(modelId: ModelId): Promise<{
127
+ meshByType: Record<string, FormattedComponent[]>;
128
+ collectionsByType: Record<string, CollectionComponent[]>;
129
+ relations: Record<string, ComponentRelations>;
130
+ }> {
131
+ const dataStore = useDataStore();
132
+ const [meshByType, collectionsByType] = await Promise.all([
133
+ dataStore.fetchAllMeshComponents(modelId),
134
+ dataStore.fetchAllCollectionComponents(modelId),
135
+ ]);
136
+ // Boundaries and internals are mesh components: the ones just read are reused
137
+ const relations = await dataStore.fetchAllComponentRelations(
138
+ modelId,
139
+ Object.values(meshByType).flat(),
140
+ );
141
+ return { meshByType, collectionsByType, relations };
142
+ }
143
+
42
144
  export function useModelTree(modelId: ModelId): {
43
145
  isLoading: ComputedRef<boolean>;
44
146
  localCategories: Ref<ModelTreeCategory[]>;
45
147
  cache: Ref<ModelTreeCache | undefined>;
46
148
  collectionTypes: Ref<Set<string>>;
149
+ withRelations: typeof withRelations;
47
150
  } & ReturnType<typeof useModelVisibility> {
48
151
  const dataStore = useDataStore();
49
152
 
@@ -52,6 +155,7 @@ export function useModelTree(modelId: ModelId): {
52
155
  const cache = ref<ModelTreeCache | undefined>(undefined);
53
156
  const localCategories = ref<ModelTreeCategory[]>([]);
54
157
  const collectionTypes = ref<Set<string>>(new Set());
158
+ const relationDetails = useRelationDetails();
55
159
 
56
160
  // The mesh cache also groups collection components by their type; the collections cache overrides those keys with the real collection -> mesh components hierarchy.
57
161
  watch(
@@ -60,10 +164,8 @@ export function useModelTree(modelId: ModelId): {
60
164
  if (!mesh || !collections) {
61
165
  return;
62
166
  }
63
- const [meshByType, collectionsByType] = await Promise.all([
64
- dataStore.fetchAllMeshComponents(modelId),
65
- dataStore.fetchAllCollectionComponents(modelId),
66
- ]);
167
+ const { meshByType, collectionsByType, relations } = await fetchModelTreeData(modelId);
168
+ relationDetails.setRelations(relations);
67
169
  cache.value = markRaw({ ...meshByType, ...collectionsByType });
68
170
  localCategories.value = [...mesh, ...collections];
69
171
  collectionTypes.value = new Set(Object.keys(collectionsByType));
@@ -73,11 +175,23 @@ export function useModelTree(modelId: ModelId): {
73
175
 
74
176
  const isLoading = computed(() => cache.value === undefined);
75
177
 
178
+ function withRelations<Component extends { readonly id: string }>(
179
+ categoryId: string,
180
+ components: readonly Component[],
181
+ sortType: string,
182
+ ): WithRelationDetails<Component>[] {
183
+ if (collectionTypes.value.has(categoryId)) {
184
+ return [...components];
185
+ }
186
+ return relationDetails.attach(components, sortType);
187
+ }
188
+
76
189
  return {
77
190
  isLoading,
78
191
  localCategories,
79
192
  cache,
80
193
  collectionTypes,
194
+ withRelations,
81
195
  ...useModelVisibility(modelId),
82
196
  };
83
197
  }
@@ -90,7 +90,7 @@ export function useTreeKeyboardNav(
90
90
  currentIndex: number,
91
91
  lastIndex: number,
92
92
  ): number {
93
- if (item && !item.isLeaf && !item.isOpen) {
93
+ if (item && item.isExpandable && !item.isOpen) {
94
94
  toggleOpen(item.raw);
95
95
  return currentIndex;
96
96
  }
@@ -101,7 +101,7 @@ export function useTreeKeyboardNav(
101
101
  item: ReadonlyDisplayItem | undefined,
102
102
  currentIndex: number,
103
103
  ): number {
104
- if (item && !item.isLeaf && item.isOpen) {
104
+ if (item && item.isExpandable && item.isOpen) {
105
105
  toggleOpen(item.raw);
106
106
  return currentIndex;
107
107
  }
@@ -20,6 +20,7 @@ function useVirtualTree(
20
20
  value: "id",
21
21
  title: "title",
22
22
  children: "children",
23
+ details: "details",
23
24
  height: 28,
24
25
  ...props.value.itemProps,
25
26
  }));
@@ -51,6 +52,11 @@ function useVirtualTree(
51
52
  return isTreeItemArray(rawChildren) ? rawChildren : undefined;
52
53
  }
53
54
 
55
+ function getDetailsOf(item: TreeItem): TreeItem[] | undefined {
56
+ const rawDetails = item[actualItemProps.value.details];
57
+ return isTreeItemArray(rawDetails) ? rawDetails : undefined;
58
+ }
59
+
54
60
  function getLeafChildrenIds(item: TreeItem): unknown[] {
55
61
  const children = getChildrenOf(item);
56
62
  if (children) {
@@ -124,7 +130,14 @@ function useVirtualTree(
124
130
  return allIds;
125
131
  }
126
132
 
127
- const flattenContext = { props, actualItemProps, openedSet, activeSet, getChildrenOf };
133
+ const flattenContext = {
134
+ props,
135
+ actualItemProps,
136
+ openedSet,
137
+ activeSet,
138
+ getChildrenOf,
139
+ getDetailsOf,
140
+ };
128
141
  const displayItems = computed(() => flattenTree(flattenContext, props.value.items ?? []));
129
142
 
130
143
  watch(
@@ -13,6 +13,7 @@ interface FlattenContext {
13
13
  openedSet: ComputedRef<Set<unknown>>;
14
14
  activeSet: ComputedRef<Set<unknown>>;
15
15
  getChildrenOf: (item: TreeItem) => TreeItem[] | undefined;
16
+ getDetailsOf: (item: TreeItem) => TreeItem[] | undefined;
16
17
  }
17
18
 
18
19
  function matchesSearch(ctx: FlattenContext, item: TreeItem, id: unknown, search: string): boolean {
@@ -36,11 +37,25 @@ function createDisplayItem(ctx: FlattenContext, item: TreeItem, depth: number):
36
37
  isOpen: ctx.openedSet.value.has(id),
37
38
  isActive: ctx.activeSet.value.has(id),
38
39
  isLeaf: true,
40
+ isExpandable: false,
39
41
  };
40
42
  }
41
43
 
42
44
  type FlattenChildren = (children: readonly TreeItem[]) => DisplayItem[];
43
45
 
46
+ // An expandable row, followed by the rows under it only when it is open
47
+ function expandableRow(
48
+ entry: DisplayItem,
49
+ isLeaf: boolean,
50
+ rowsUnder: () => readonly DisplayItem[],
51
+ ): DisplayItem[] {
52
+ const row = { ...entry, isLeaf, isExpandable: true };
53
+ if (!row.isOpen) {
54
+ return [row];
55
+ }
56
+ return [row, ...rowsUnder()];
57
+ }
58
+
44
59
  // A branch is kept when it matches or when one of its descendants does
45
60
  function flattenSearchedBranch(
46
61
  entry: DisplayItem,
@@ -50,11 +65,7 @@ function flattenSearchedBranch(
50
65
  if (subtree.length === 0 && !matches) {
51
66
  return [];
52
67
  }
53
- const branch = { ...entry, isLeaf: false };
54
- if (!branch.isOpen) {
55
- return [branch];
56
- }
57
- return [branch, ...subtree];
68
+ return expandableRow(entry, false, () => subtree);
58
69
  }
59
70
 
60
71
  function flattenOpenBranch(
@@ -62,11 +73,19 @@ function flattenOpenBranch(
62
73
  children: readonly TreeItem[],
63
74
  flattenChildren: FlattenChildren,
64
75
  ): DisplayItem[] {
65
- const branch = { ...entry, isLeaf: false };
66
- if (!branch.isOpen) {
67
- return [branch];
76
+ return expandableRow(entry, false, () => flattenChildren(children));
77
+ }
78
+
79
+ // Details hang under a leaf that stays a leaf: selecting or clicking it only targets the item itself
80
+ function flattenLeafDetails(
81
+ entry: DisplayItem,
82
+ details: readonly TreeItem[],
83
+ flattenChildren: FlattenChildren,
84
+ ): DisplayItem[] {
85
+ if (details.length === 0) {
86
+ return [entry];
68
87
  }
69
- return [branch, ...flattenChildren(children)];
88
+ return expandableRow(entry, true, () => flattenChildren(details));
70
89
  }
71
90
 
72
91
  function flattenNode(
@@ -81,7 +100,11 @@ function flattenNode(
81
100
  const searching = search !== undefined && search !== "";
82
101
 
83
102
  if (children.length === 0) {
84
- if (searching && !matchesSearch(ctx, item, entry.id, search)) {
103
+ // Details are hidden while searching: the search only filters the tree itself
104
+ if (!searching) {
105
+ return flattenLeafDetails(entry, ctx.getDetailsOf(item) ?? [], flattenChildren);
106
+ }
107
+ if (!matchesSearch(ctx, item, entry.id, search)) {
85
108
  return [];
86
109
  }
87
110
  return [entry];
@@ -9,6 +9,8 @@ interface ItemPropsConfig {
9
9
  value: string;
10
10
  title: string;
11
11
  children: string;
12
+ // Sub-tree shown under an item without making it a branch: it stays a leaf for selection and clicks
13
+ details: string;
12
14
  height: number;
13
15
  [key: string]: unknown;
14
16
  }
@@ -37,6 +39,8 @@ interface DisplayItem {
37
39
  isOpen: boolean;
38
40
  isActive: boolean;
39
41
  isLeaf: boolean;
42
+ // A leaf can still be expanded when it carries details
43
+ isExpandable: boolean;
40
44
  }
41
45
 
42
46
  type EmitFn = (event: string, ...args: readonly unknown[]) => void;
@@ -127,7 +127,7 @@ export const useDataStore = defineStore("data", () => {
127
127
  formatedCollectionComponents,
128
128
  refFormatedCollectionComponents,
129
129
  } = useDataCollections();
130
- const { getComponentRelations } = useDataRelations();
130
+ const { getComponentRelations, fetchAllComponentRelations } = useDataRelations();
131
131
  // Ids the viewer holds a pipeline for: an item is stored before it is registered, and non viewable items never are
132
132
  const registeredIds = reactive(new Set<string>());
133
133
  async function item(dataId: DataId): Promise<DataItem> {
@@ -450,6 +450,7 @@ export const useDataStore = defineStore("data", () => {
450
450
  formatedCollectionComponents,
451
451
  refFormatedCollectionComponents,
452
452
  getComponentRelations,
453
+ fetchAllComponentRelations,
453
454
  };
454
455
  });
455
456
 
@@ -18,8 +18,33 @@ interface ModelComponentRelationRecord extends DataIdentified {
18
18
  type: string;
19
19
  }
20
20
 
21
+ const RELATION_KEYS: Readonly<Record<string, keyof ComponentRelations>> = {
22
+ boundary: "boundaries",
23
+ internal: "internals",
24
+ };
25
+
26
+ type MutableComponentRelations = { [Key in keyof ComponentRelations]: FormattedComponent[] };
27
+
28
+ function groupRelationsByParent(
29
+ relations: readonly ModelComponentRelationRecord[],
30
+ components: readonly FormattedComponent[],
31
+ ): Record<string, ComponentRelations> {
32
+ const componentsById = new Map(components.map((component) => [component.id, component]));
33
+ const byParent: Record<string, MutableComponentRelations> = {};
34
+ for (const relation of relations) {
35
+ const key = RELATION_KEYS[relation.type];
36
+ const child = componentsById.get(relation.child);
37
+ if (key !== undefined && child !== undefined) {
38
+ byParent[relation.parent] ??= { boundaries: [], internals: [] };
39
+ byParent[relation.parent]?.[key].push(child);
40
+ }
41
+ }
42
+ return byParent;
43
+ }
44
+
21
45
  export function useDataRelations(): {
22
46
  getComponentRelations: typeof getComponentRelations;
47
+ fetchAllComponentRelations: typeof fetchAllComponentRelations;
23
48
  } {
24
49
  const model_components_db = getTable<ModelComponentRecord>("model_components");
25
50
  const model_components_relation_db = getTable<ModelComponentRelationRecord>(
@@ -53,7 +78,17 @@ export function useDataRelations(): {
53
78
  return { boundaries, internals };
54
79
  }
55
80
 
56
- return { getComponentRelations };
81
+ // The boundaries and internals of every component of the model, among the given components:
82
+ // The caller already holds them, so only the relations are read
83
+ async function fetchAllComponentRelations(
84
+ modelId: ModelId,
85
+ components: readonly FormattedComponent[],
86
+ ): Promise<Record<string, ComponentRelations>> {
87
+ const relations = await model_components_relation_db.where("data_id").equals(modelId).toArray();
88
+ return groupRelationsByParent(relations, components);
89
+ }
90
+
91
+ return { getComponentRelations, fetchAllComponentRelations };
57
92
  }
58
93
 
59
94
  export type { ComponentRelations, ModelComponentRelationRecord };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "11.2.0-rc.2",
3
+ "version": "11.2.0-rc.3",
4
4
  "description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
5
5
  "homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
6
6
  "bugs": {