@geode/opengeodeweb-front 12.1.0-rc.5 → 12.1.0-rc.6

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.
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { getPlaneCssColor } from "@ogw_front/utils/clipping_planes";
3
+ import { pasteCoordinates } from "@ogw_front/utils/coordinates";
3
4
 
4
5
  interface Props {
5
6
  plane: { origin?: number[]; normal: number[]; opacity: number };
@@ -79,6 +80,7 @@ const emit = defineEmits<Emits>();
79
80
  hide-details
80
81
  step="any"
81
82
  class="text-caption"
83
+ @paste="plane.origin && pasteCoordinates($event, plane.origin)"
82
84
  />
83
85
  </v-col>
84
86
  </v-row>
@@ -122,6 +124,7 @@ const emit = defineEmits<Emits>();
122
124
  hide-details
123
125
  step="any"
124
126
  class="text-caption"
127
+ @paste="pasteCoordinates($event, plane.normal)"
125
128
  />
126
129
  </v-col>
127
130
  </v-row>
@@ -140,6 +140,10 @@ function handleItemClick(
140
140
  index: number | undefined,
141
141
  event?: MouseEvent | KeyboardEvent,
142
142
  ): void {
143
+ // A row still loading cannot be shown, hidden or picked yet
144
+ if (item.raw.loading === true) {
145
+ return;
146
+ }
143
147
  if (index !== undefined) {
144
148
  focusedIndex.value = index;
145
149
  }
@@ -220,6 +224,7 @@ const { handleKeyDown } = useTreeKeyboardNav(
220
224
  'is-focused': focusedIndex === index,
221
225
  'is-active': item.isActive,
222
226
  'is-linked': linked !== undefined && item.raw[actualItemProps.value] === linked.id,
227
+ 'is-loading': item.raw.loading === true,
223
228
  },
224
229
  ]"
225
230
  :style="
@@ -235,11 +240,11 @@ const { handleKeyDown } = useTreeKeyboardNav(
235
240
  treeWrapper?.focus();
236
241
  "
237
242
  @contextmenu.prevent.stop="
238
- emit('contextmenu', { event: $event, item: item.raw });
243
+ item.raw.loading !== true && emit('contextmenu', { event: $event, item: item.raw });
239
244
  treeWrapper?.focus();
240
245
  "
241
- @mouseenter="emit('hover:enter', { item })"
242
- @mouseleave="emit('hover:leave', { item })"
246
+ @mouseenter="item.raw.loading !== true && emit('hover:enter', { item })"
247
+ @mouseleave="item.raw.loading !== true && emit('hover:leave', { item })"
243
248
  >
244
249
  <TreeRow
245
250
  :item="item"
@@ -320,6 +325,14 @@ const { handleKeyDown } = useTreeKeyboardNav(
320
325
  box-shadow: inset 0 0 0 2px rgba(var(--v-theme-primary), 0.6);
321
326
  }
322
327
 
328
+ .tree-row-wrapper.is-loading {
329
+ cursor: progress;
330
+ }
331
+
332
+ .tree-row-wrapper.is-loading :deep(.tree-title) {
333
+ opacity: 0.6;
334
+ }
335
+
323
336
  .tree-row-wrapper.is-linked {
324
337
  background-color: color-mix(in srgb, var(--row-link-color) 22%, transparent) !important;
325
338
  box-shadow: inset 0 0 0 2px var(--row-link-color);
@@ -39,6 +39,29 @@ const showEyeButton = computed<boolean>(
39
39
  () => !isHorizonStack.value && item.raw.title !== "HorizonStack3D" && isViewable.value,
40
40
  );
41
41
 
42
+ function isLoading(child: unknown): boolean {
43
+ return (
44
+ typeof child === "object" && child !== null && "loading" in child && child.loading === true
45
+ );
46
+ }
47
+ const loadingChildren = computed<number>(() =>
48
+ Array.isArray(item.raw.children)
49
+ ? item.raw.children.filter((child) => isLoading(child)).length
50
+ : 0,
51
+ );
52
+ // A data, or a group of data, that cannot be shown or hidden yet
53
+ const isRowLoading = computed<boolean>(
54
+ () =>
55
+ isLoading(item.raw) ||
56
+ (Array.isArray(item.raw.children) &&
57
+ loadingChildren.value > 0 &&
58
+ loadingChildren.value === item.raw.children.length),
59
+ );
60
+ // A folded group shows that some of its data are still loading
61
+ const showGroupSpinner = computed<boolean>(
62
+ () => !item.isOpen && loadingChildren.value > 0 && !isRowLoading.value,
63
+ );
64
+
42
65
  function handleRowClick(event: MouseEvent): void {
43
66
  if (isHorizonStack.value) {
44
67
  if (!item.isLeaf) {
@@ -71,8 +94,15 @@ function handleRowClick(event: MouseEvent): void {
71
94
  <div v-else class="icon-placeholder" />
72
95
 
73
96
  <template v-if="selection.selectable">
97
+ <div
98
+ v-if="isRowLoading"
99
+ data-testid="loadingObjectSpinner"
100
+ class="loading-spinner d-flex align-center justify-center flex-shrink-0"
101
+ >
102
+ <v-progress-circular indeterminate size="14" width="2" color="primary" />
103
+ </div>
74
104
  <v-btn
75
- v-if="isHorizonStack && item.isLeaf"
105
+ v-else-if="isHorizonStack && item.isLeaf"
76
106
  icon="ph-stack"
77
107
  variant="text"
78
108
  density="compact"
@@ -120,6 +150,16 @@ function handleRowClick(event: MouseEvent): void {
120
150
  </slot>
121
151
  </div>
122
152
 
153
+ <v-progress-circular
154
+ v-if="showGroupSpinner"
155
+ data-testid="loadingGroupSpinner"
156
+ indeterminate
157
+ size="12"
158
+ width="2"
159
+ color="primary"
160
+ class="flex-shrink-0 ms-2"
161
+ />
162
+
123
163
  <div class="ms-auto d-flex align-center">
124
164
  <slot name="append" :item="item.raw" />
125
165
  </div>
@@ -138,4 +178,10 @@ function handleRowClick(event: MouseEvent): void {
138
178
  .tree-title {
139
179
  min-height: 24px;
140
180
  }
181
+
182
+ /* Same footprint as the eye button it stands in for */
183
+ .loading-spinner {
184
+ width: 28px;
185
+ height: 28px;
186
+ }
141
187
  </style>
@@ -218,7 +218,7 @@ function onVerticalResizeStart(event: MouseEvent, index: number): void {
218
218
 
219
219
  <template>
220
220
  <div
221
- v-if="treeviewStore.items.length > 0"
221
+ v-if="treeviewStore.items.length > 0 || treeviewStore.pendingImports.length > 0"
222
222
  class="treeview-layout d-flex"
223
223
  @contextmenu.prevent
224
224
  @mousedown.stop
@@ -8,7 +8,11 @@ import {
8
8
  mapId,
9
9
  nextBasemapMaps,
10
10
  } from "@ogw_front/utils/basemap_tree";
11
- import { type TreeMenuPayload, compareSelections } from "@ogw_front/utils/treeview";
11
+ import {
12
+ type TreeMenuPayload,
13
+ compareSelections,
14
+ withPendingImports,
15
+ } from "@ogw_front/utils/treeview";
12
16
  import CommonTreeView from "@ogw_front/components/Viewer/ObjectTree/Base/CommonTreeView.vue";
13
17
  import type { DisplayItem } from "@ogw_front/composables/virtual_tree";
14
18
  import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
@@ -40,6 +44,7 @@ interface TreeGroupItem extends Partial<GeodeObjectTyped>, Partial<ViewerObjectT
40
44
  id: string;
41
45
  title?: string;
42
46
  children?: TreeGroupItem[];
47
+ loading?: boolean;
43
48
  }
44
49
 
45
50
  const mainView = computed<TreeGroupItem>(() => treeviewStore.opened_views[0]);
@@ -57,7 +62,9 @@ const {
57
62
  toggleSort,
58
63
  customFilter,
59
64
  applySearchFilter,
60
- } = useTreeFilter(() => treeviewStore.items, { recursiveSort: true });
65
+ } = useTreeFilter(() => withPendingImports(treeviewStore.items, treeviewStore.pendingImports), {
66
+ recursiveSort: true,
67
+ });
61
68
 
62
69
  // The basemap category comes first, out of the data sort and filters
63
70
  const displayedItems = computed(() => {
@@ -123,6 +130,9 @@ watch(
123
130
 
124
131
  function showMenu(event: MouseEvent, item: TreeGroupItem): void {
125
132
  const actualItem = item.raw || item;
133
+ if (actualItem.loading) {
134
+ return;
135
+ }
126
136
  if (isBasemapId(actualItem.id)) {
127
137
  emit("show-menu", { event, itemId: actualItem.id, context_type: "basemap" });
128
138
  return;
@@ -268,7 +278,7 @@ function expandAll(): void {
268
278
  </template>
269
279
 
270
280
  <template #append="{ item }">
271
- <template v-if="item.geode_object_type !== 'HorizonStack3D'">
281
+ <template v-if="item.geode_object_type !== 'HorizonStack3D' && !item.loading">
272
282
  <v-btn
273
283
  v-if="item.viewer_object_type"
274
284
  data-testid="focusObjectButton"
@@ -31,7 +31,15 @@ interface OpenedView extends Partial<GeodeObjectTyped> {
31
31
  color?: string;
32
32
  }
33
33
 
34
- interface TreeviewChild extends TreeNode, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {}
34
+ interface TreeviewChild extends TreeNode, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {
35
+ // Still being loaded in the viewer: shown with a spinner and not interactive yet
36
+ loading?: boolean;
37
+ }
38
+
39
+ // A file being imported: shown in its type group while the back-end converts it, before its data exist
40
+ interface PendingImport extends TreeNode, GeodeObjectTyped {
41
+ loading: true;
42
+ }
35
43
 
36
44
  type TreeviewGroup = TreeGroup<TreeviewChild>;
37
45
 
@@ -102,6 +110,8 @@ export const useTreeviewStore = defineStore("treeview", () => {
102
110
  const panelWidth = ref(PANEL_WIDTH);
103
111
  const additionalPanelWidth = ref(PANEL_WIDTH);
104
112
  const isImporting = ref(false);
113
+ const pendingImports = ref<PendingImport[]>([]);
114
+ let lastPendingImport = 0;
105
115
  const pendingSelectionIds = ref<string[]>([]);
106
116
  const rowHeights = ref<number[]>([]);
107
117
  // Model hovered in the objects tree or on its model tree header: not saved
@@ -195,12 +205,14 @@ export const useTreeviewStore = defineStore("treeview", () => {
195
205
  geode_id: GeodeId,
196
206
  viewer_object_type: ViewerObjectType,
197
207
  ): void {
208
+ // Loading until the import workflow has it in the viewer (see untilLoaded)
198
209
  const child: TreeviewChild = {
199
210
  title: name,
200
211
  id: dataId,
201
212
  geode_id,
202
213
  viewer_object_type,
203
214
  geode_object_type: geodeObjectType,
215
+ loading: true,
204
216
  };
205
217
  let found = false;
206
218
  for (const item of items.value) {
@@ -224,6 +236,47 @@ export const useTreeviewStore = defineStore("treeview", () => {
224
236
  selection.value = [...selection.value, dataId];
225
237
  }
226
238
 
239
+ function removePendingImport(id: string): void {
240
+ pendingImports.value = pendingImports.value.filter((pending) => pending.id !== id);
241
+ // Its type group shown or hidden as a whole may have selected it
242
+ if (selection.value.includes(id)) {
243
+ selection.value = selection.value.filter((selectionId) => selectionId !== id);
244
+ }
245
+ }
246
+
247
+ // The file is listed in the tree, by its name, until its conversion is done
248
+ async function whilePendingImport<Result>(
249
+ geodeObjectType: GeodeObjectType,
250
+ filename: string,
251
+ conversion: Promise<Result>,
252
+ ): Promise<Result> {
253
+ lastPendingImport += 1;
254
+ const id = `pending-import-${lastPendingImport}`;
255
+ const title = filename.split("/").pop() ?? filename;
256
+ pendingImports.value.push({ id, title, geode_object_type: geodeObjectType, loading: true });
257
+ try {
258
+ const result = await conversion;
259
+ return result;
260
+ } finally {
261
+ removePendingImport(id);
262
+ }
263
+ }
264
+
265
+ // Added as loading, a data stops loading once its import is done, or has failed
266
+ async function untilLoaded<Result>(dataId: DataId, importing: Promise<Result>): Promise<Result> {
267
+ try {
268
+ const result = await importing;
269
+ return result;
270
+ } finally {
271
+ const child = items.value
272
+ .flatMap((group) => group.children)
273
+ .find((childItem) => childItem.id === dataId);
274
+ if (child) {
275
+ child.loading = false;
276
+ }
277
+ }
278
+ }
279
+
227
280
  function removeItem(dataId: DataId): void {
228
281
  clearHoveredModel(dataId);
229
282
  for (let index = 0; index < items.value.length; index += 1) {
@@ -314,6 +367,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
314
367
  selection.value = [];
315
368
  activeItems.value = [];
316
369
  pendingSelectionIds.value = [];
370
+ pendingImports.value = [];
317
371
  opened_views.value = defaultOpenedViews();
318
372
  }
319
373
 
@@ -389,10 +443,13 @@ export const useTreeviewStore = defineStore("treeview", () => {
389
443
  panelWidth,
390
444
  additionalPanelWidth,
391
445
  isImporting,
446
+ pendingImports,
392
447
  rowHeights,
393
448
  hoveredModelId,
394
449
  setHoveredModel,
395
450
  addItem,
451
+ whilePendingImport,
452
+ untilLoaded,
396
453
  removeItem,
397
454
  renameItem,
398
455
  displayAdditionalTree,
@@ -0,0 +1,24 @@
1
+ // A number as it is written in a copied coordinate: "-12", "3.5", ".5", "1e-3"
2
+ const NUMBER_PATTERN = /[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/gu;
3
+ const COORDINATE_COUNT = 3;
4
+ const MIN_PASTED_COORDINATES = 2;
5
+
6
+ // The numbers of a pasted text, whatever separates them: "1.5, 2; -3e2" gives [1.5, 2, -300]
7
+ function parseCoordinates(text: string): number[] {
8
+ return (text.match(NUMBER_PATTERN) ?? []).map(Number);
9
+ }
10
+
11
+ // A pasted point ("x y z", "x, y, z", a spreadsheet row...) fills every axis at once. A single
12
+ // Number is left to the browser, which pastes it in the field the user is in.
13
+ function pasteCoordinates(event: ClipboardEvent, target: number[]): void {
14
+ const values = parseCoordinates(event.clipboardData?.getData("text") ?? "");
15
+ if (values.length < MIN_PASTED_COORDINATES) {
16
+ return;
17
+ }
18
+ event.preventDefault();
19
+ for (const [axis, value] of values.slice(0, COORDINATE_COUNT).entries()) {
20
+ target[axis] = value;
21
+ }
22
+ }
23
+
24
+ export { parseCoordinates, pasteCoordinates };
@@ -77,21 +77,21 @@ async function importDataItem(item: NewDataItem): Promise<string> {
77
77
  }
78
78
  // Every item comes through here: from the back-end, which still names its data id `id`, or from a project
79
79
  async function importItem(imported: LegacyDataId<NewDataItem> | NewDataItem): Promise<string> {
80
- const dataId = await importDataItem(fromLegacyDataId(imported));
80
+ const item = fromLegacyDataId(imported);
81
+ const dataId = await useTreeviewStore().untilLoaded(item.data_id, importDataItem(item));
81
82
  return dataId;
82
83
  }
83
84
  // A single file can hold several objects: every one of them is imported, ids are returned in the response order
84
85
  async function importFile(filename: string, geode_object_type: GeodeObjectType): Promise<string[]> {
85
86
  const backStore = useBackStore();
86
87
  const schema = back_schemas.opengeodeweb_back.save_viewable_file;
87
- const params = {
88
+ const params = { geode_object_type, filename };
89
+ // The conversion can be long: the file shows in the tree meanwhile, then is replaced by its objects
90
+ const response = await useTreeviewStore().whilePendingImport(
88
91
  geode_object_type,
89
92
  filename,
90
- };
91
- const response = await backStore.request({
92
- schema,
93
- params,
94
- });
93
+ backStore.request({ schema, params }),
94
+ );
95
95
  // oxlint-disable-next-line no-unsafe-type-assertion -- this is the trusted API boundary; each back-end response item matches NewDataItem, except for its legacy id.
96
96
  const items = response.data as LegacyDataId<NewDataItem>[];
97
97
  const dataIds = await Promise.all(
@@ -1,4 +1,5 @@
1
- import type { ModelIdentified } from "@ogw_front/types/identifiers";
1
+ import type { GeodeObjectTyped, ModelIdentified } from "@ogw_front/types/identifiers";
2
+ import type { TreeGroup, TreeNode } from "@ogw_front/types/tree";
2
3
 
3
4
  function compareSelections<Item>(
4
5
  current: readonly Item[],
@@ -61,7 +62,31 @@ function nextModelTreeColor(usedColors: readonly (string | undefined)[]): string
61
62
  return free ?? MODEL_TREE_COLORS[usedColors.length % MODEL_TREE_COLORS.length] ?? "";
62
63
  }
63
64
 
64
- export { MODEL_TREE_COLORS, compareSelections, nextModelTreeColor };
65
+ // Files being imported are listed in their type group, created for them when no data of that type exists yet
66
+ function withPendingImports<Child extends TreeNode, Pending extends TreeNode & GeodeObjectTyped>(
67
+ groups: readonly TreeGroup<Child>[],
68
+ pendingImports: readonly Pending[],
69
+ ): TreeGroup<Child | Pending>[] {
70
+ const merged: TreeGroup<Child | Pending>[] = groups.map((group) => ({
71
+ ...group,
72
+ children: [...group.children],
73
+ }));
74
+ for (const pending of pendingImports) {
75
+ const group = merged.find((candidate) => candidate.id === pending.geode_object_type);
76
+ if (group) {
77
+ group.children.push(pending);
78
+ } else {
79
+ merged.push({
80
+ id: pending.geode_object_type,
81
+ title: pending.geode_object_type,
82
+ children: [pending],
83
+ });
84
+ }
85
+ }
86
+ return merged;
87
+ }
88
+
89
+ export { MODEL_TREE_COLORS, compareSelections, nextModelTreeColor, withPendingImports };
65
90
  export type {
66
91
  DataMenuPayload,
67
92
  GeodeObjectTypeMenuPayload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "12.1.0-rc.5",
3
+ "version": "12.1.0-rc.6",
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": {