@geode/opengeodeweb-front 12.1.0-rc.5 → 12.1.0-rc.7
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.
- package/app/components/ClippingPlaneCard.vue +3 -0
- package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +16 -3
- package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +47 -1
- package/app/components/Viewer/ObjectTree/Layout.vue +1 -1
- package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +13 -3
- package/app/stores/feedback.ts +5 -2
- package/app/stores/treeview.ts +58 -1
- package/app/utils/coordinates.ts +24 -0
- package/app/utils/import_workflow.ts +7 -7
- package/app/utils/treeview.ts +27 -2
- package/internal/utils/api_fetch.ts +9 -56
- package/internal/utils/error_feedback.ts +106 -0
- package/internal/utils/upload_file.ts +4 -32
- package/internal/utils/viewer_call.ts +11 -38
- package/package.json +1 -1
|
@@ -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 {
|
|
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, {
|
|
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"
|
package/app/stores/feedback.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
2
2
|
|
|
3
3
|
const MILLISECONDS_IN_SECOND = 1000;
|
|
4
4
|
const DEFAULT_FEEDBACKS_TIMEOUT_SECONDS = 10;
|
|
5
|
+
const DEFAULT_ERROR_NAME = "Error";
|
|
6
|
+
const DEFAULT_ERROR_DESCRIPTION = "An unexpected error occurred";
|
|
5
7
|
|
|
6
8
|
type FeedbackType = "error" | "success" | "warning";
|
|
7
9
|
|
|
@@ -34,8 +36,9 @@ export const useFeedbackStore = defineStore("feedback", {
|
|
|
34
36
|
type: "error",
|
|
35
37
|
code,
|
|
36
38
|
route,
|
|
37
|
-
name,
|
|
38
|
-
description
|
|
39
|
+
name: name === "" ? DEFAULT_ERROR_NAME : name,
|
|
40
|
+
// The snackbar only shows the description: never leave it empty
|
|
41
|
+
description: [description, name].find((text) => text !== "") ?? DEFAULT_ERROR_DESCRIPTION,
|
|
39
42
|
});
|
|
40
43
|
setTimeout(() => {
|
|
41
44
|
this.delete_feedback(feedbackId);
|
package/app/stores/treeview.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
package/app/utils/treeview.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JsonRpcSchema, RequestHandlersWithValidation } from "@ogw_shared/utils/types.js";
|
|
2
2
|
import { endRequestLog, startRequestLog } from "@ogw_front/utils/log";
|
|
3
|
-
import
|
|
3
|
+
import { reportError, reportTimeout } from "./error_feedback.js";
|
|
4
4
|
import { consola } from "consola";
|
|
5
5
|
import { fetchSchema } from "@ogw_shared/utils/fetch_schema";
|
|
6
6
|
import { useFeedbackStore } from "@ogw_front/stores/feedback";
|
|
@@ -20,45 +20,6 @@ interface ApiFetchParams {
|
|
|
20
20
|
headers?: Record<string, string>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
// Loosely-typed shapes for the dynamic error/response values reported by fetchSchema.
|
|
24
|
-
interface FetchErrorLike {
|
|
25
|
-
code?: number;
|
|
26
|
-
message?: string;
|
|
27
|
-
stack?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type FetchErrorResponseLike = { status?: number } & Partial<
|
|
31
|
-
Pick<ErrorResponse, "name" | "description">
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
-
return typeof value === "object" && value !== null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function toFetchErrorLike(error: unknown): FetchErrorLike {
|
|
39
|
-
if (!isRecord(error)) {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
code: typeof error.code === "number" ? error.code : undefined,
|
|
44
|
-
message: typeof error.message === "string" ? error.message : undefined,
|
|
45
|
-
stack: typeof error.stack === "string" ? error.stack : undefined,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function toFetchErrorResponseLike(response: unknown): FetchErrorResponseLike {
|
|
50
|
-
if (!isRecord(response)) {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
// Ofetch puts the parsed body (an ErrorResponse for Flask microservices) in `_data`
|
|
54
|
-
const body = isRecord(response._data) ? response._data : response;
|
|
55
|
-
return {
|
|
56
|
-
status: typeof response.status === "number" ? response.status : undefined,
|
|
57
|
-
name: typeof body.name === "string" ? body.name : undefined,
|
|
58
|
-
description: typeof body.description === "string" ? body.description : undefined,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
23
|
// oxlint-disable-next-line max-lines-per-function
|
|
63
24
|
async function api_fetch(
|
|
64
25
|
microservice: Microservice,
|
|
@@ -76,7 +37,7 @@ async function api_fetch(
|
|
|
76
37
|
microservice.start_request();
|
|
77
38
|
|
|
78
39
|
const requestStartingTime = startRequestLog(microservice, schema);
|
|
79
|
-
const
|
|
40
|
+
const request = fetchSchema(
|
|
80
41
|
{
|
|
81
42
|
schema,
|
|
82
43
|
params,
|
|
@@ -87,14 +48,8 @@ async function api_fetch(
|
|
|
87
48
|
{
|
|
88
49
|
async request_error_function(error: unknown) {
|
|
89
50
|
microservice.stop_request();
|
|
90
|
-
const typedError = toFetchErrorLike(error);
|
|
91
51
|
if (skip_feedback_error !== true) {
|
|
92
|
-
|
|
93
|
-
typedError.code ?? 0,
|
|
94
|
-
schema.$id,
|
|
95
|
-
typedError.message ?? "",
|
|
96
|
-
typedError.stack ?? "",
|
|
97
|
-
);
|
|
52
|
+
reportError(schema.$id, error);
|
|
98
53
|
}
|
|
99
54
|
if (request_error_function) {
|
|
100
55
|
await request_error_function(error);
|
|
@@ -109,14 +64,8 @@ async function api_fetch(
|
|
|
109
64
|
},
|
|
110
65
|
async response_error_function(response: unknown) {
|
|
111
66
|
microservice.stop_request();
|
|
112
|
-
const typedResponse = toFetchErrorResponseLike(response);
|
|
113
67
|
if (skip_feedback_error !== true) {
|
|
114
|
-
|
|
115
|
-
typedResponse.status ?? 0,
|
|
116
|
-
schema.$id,
|
|
117
|
-
typedResponse.name ?? "",
|
|
118
|
-
typedResponse.description ?? "",
|
|
119
|
-
);
|
|
68
|
+
reportError(schema.$id, response);
|
|
120
69
|
}
|
|
121
70
|
if (response_error_function) {
|
|
122
71
|
await response_error_function(response);
|
|
@@ -128,8 +77,12 @@ async function api_fetch(
|
|
|
128
77
|
},
|
|
129
78
|
},
|
|
130
79
|
);
|
|
80
|
+
if (skip_feedback_error === true) {
|
|
81
|
+
return request;
|
|
82
|
+
}
|
|
83
|
+
const result = await reportTimeout(schema.$id, request);
|
|
131
84
|
return result;
|
|
132
85
|
}
|
|
133
86
|
|
|
134
87
|
export { api_fetch };
|
|
135
|
-
export type {
|
|
88
|
+
export type { Microservice };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ErrorResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
|
|
2
|
+
import { TimeoutError } from "p-timeout";
|
|
3
|
+
import { useFeedbackStore } from "@ogw_front/stores/feedback";
|
|
4
|
+
|
|
5
|
+
const UNKNOWN_CODE = 0;
|
|
6
|
+
const DEFAULT_NAME = "Error";
|
|
7
|
+
const DEFAULT_DESCRIPTION = "An unexpected error occurred";
|
|
8
|
+
|
|
9
|
+
// Wslink sends a Python exception as its repr, e.g. ValueError('No BRep object found')
|
|
10
|
+
const PYTHON_REPR = /^(?<name>[A-Za-z_][\w.]*)\((?<args>.*)\)$/su;
|
|
11
|
+
const QUOTED_STRING = /^(?<quote>['"])(?<content>.*)\k<quote>$/su;
|
|
12
|
+
|
|
13
|
+
type Fields = Record<string, unknown>;
|
|
14
|
+
|
|
15
|
+
function isRecord(value: unknown): value is Fields {
|
|
16
|
+
return typeof value === "object" && value !== null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function stringField(record: Fields, key: string): string | undefined {
|
|
20
|
+
const value = record[key];
|
|
21
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function numberField(record: Fields, key: string): number | undefined {
|
|
25
|
+
const value = record[key];
|
|
26
|
+
return typeof value === "number" ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parsePythonException(repr: string | undefined): Partial<ErrorResponse> {
|
|
30
|
+
if (repr === undefined) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
const match = PYTHON_REPR.exec(repr.trim());
|
|
34
|
+
if (!match?.groups) {
|
|
35
|
+
return { description: repr };
|
|
36
|
+
}
|
|
37
|
+
const { name } = match.groups;
|
|
38
|
+
const args = match.groups.args?.trim() ?? "";
|
|
39
|
+
const quoted = QUOTED_STRING.exec(args);
|
|
40
|
+
return { name, description: quoted?.groups?.content ?? (args === "" ? undefined : args) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Turn whatever a microservice call failed with into one { code, name, description }:
|
|
45
|
+
* - an ofetch response, whose parsed body (`_data`) is an ErrorResponse (Flask back, Nuxt server routes)
|
|
46
|
+
* - an ErrorResponse body itself
|
|
47
|
+
* - a wslink error { code, message, data: { exception, trace } } (viewer)
|
|
48
|
+
* - any thrown Error (network failure, timeout...)
|
|
49
|
+
*/
|
|
50
|
+
function toErrorFeedback(value: unknown): ErrorResponse {
|
|
51
|
+
if (!isRecord(value)) {
|
|
52
|
+
return {
|
|
53
|
+
code: UNKNOWN_CODE,
|
|
54
|
+
name: DEFAULT_NAME,
|
|
55
|
+
description: typeof value === "string" && value !== "" ? value : DEFAULT_DESCRIPTION,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Ofetch puts the parsed response body in `_data`
|
|
59
|
+
let body = value;
|
|
60
|
+
if (isRecord(value._data)) {
|
|
61
|
+
body = value._data;
|
|
62
|
+
}
|
|
63
|
+
let exception: Partial<ErrorResponse> = {};
|
|
64
|
+
if (isRecord(body.data)) {
|
|
65
|
+
exception = parsePythonException(stringField(body.data, "exception"));
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
code:
|
|
69
|
+
numberField(value, "status") ??
|
|
70
|
+
numberField(body, "code") ??
|
|
71
|
+
numberField(value, "statusCode") ??
|
|
72
|
+
UNKNOWN_CODE,
|
|
73
|
+
name:
|
|
74
|
+
stringField(body, "name") ??
|
|
75
|
+
exception.name ??
|
|
76
|
+
stringField(value, "statusText") ??
|
|
77
|
+
stringField(value, "name") ??
|
|
78
|
+
DEFAULT_NAME,
|
|
79
|
+
description:
|
|
80
|
+
stringField(body, "description") ??
|
|
81
|
+
exception.description ??
|
|
82
|
+
stringField(body, "message") ??
|
|
83
|
+
stringField(value, "message") ??
|
|
84
|
+
DEFAULT_DESCRIPTION,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The single entry point to show a microservice error to the user
|
|
89
|
+
function reportError(route: string, value: unknown): void {
|
|
90
|
+
const { code, name, description } = toErrorFeedback(value);
|
|
91
|
+
useFeedbackStore().add_error(code, route, name, description);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// A timeout rejects without going through the request handlers: report it as well
|
|
95
|
+
async function reportTimeout<Result>(route: string, request: Promise<Result>): Promise<Result> {
|
|
96
|
+
try {
|
|
97
|
+
return await request;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof TimeoutError) {
|
|
100
|
+
reportError(route, error);
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { reportError, reportTimeout, toErrorFeedback };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { FetchErrorLike, Microservice } from "./api_fetch.js";
|
|
2
1
|
import type { JsonRpcSchema, RequestHandlers } from "@ogw_shared/utils/types.js";
|
|
3
2
|
import { CHUNK_SIZE_BYTES } from "@ogw_shared/utils/file.js";
|
|
3
|
+
import type { Microservice } from "./api_fetch.js";
|
|
4
4
|
import { consola } from "consola";
|
|
5
5
|
import { fetchRaw } from "@ogw_shared/utils/fetch_raw.js";
|
|
6
|
+
import { reportError } from "./error_feedback.js";
|
|
6
7
|
import { uploadPath } from "@ogw_front/utils/upload_path";
|
|
7
|
-
import { useFeedbackStore } from "@ogw_front/stores/feedback.js";
|
|
8
8
|
|
|
9
9
|
interface UploadFileParams {
|
|
10
10
|
// Always forwarded to fetchRaw via schema.methods, which is only ever set on
|
|
@@ -14,28 +14,12 @@ interface UploadFileParams {
|
|
|
14
14
|
params?: Record<string, string>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// Loosely-typed shapes for the dynamic error/response values reported by fetchRaw.
|
|
18
|
-
interface FetchErrorResponseLike {
|
|
19
|
-
status?: number;
|
|
20
|
-
name?: string;
|
|
21
|
-
description?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isFetchErrorLike(value: unknown): value is FetchErrorLike {
|
|
25
|
-
return typeof value === "object" && value !== null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isFetchErrorResponseLike(value: unknown): value is FetchErrorResponseLike {
|
|
29
|
-
return typeof value === "object" && value !== null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
17
|
async function upload_file(
|
|
33
18
|
microservice: Microservice,
|
|
34
19
|
{ schema, file, params = {} }: UploadFileParams,
|
|
35
20
|
{ request_error_function, response_function, response_error_function }: RequestHandlers = {},
|
|
36
21
|
): Promise<unknown> {
|
|
37
22
|
consola.debug("[UPLOAD_FILE] Uploading file", { schema, file });
|
|
38
|
-
const feedbackStore = useFeedbackStore();
|
|
39
23
|
|
|
40
24
|
if (!(file instanceof File)) {
|
|
41
25
|
throw new TypeError("file must be an instance of File");
|
|
@@ -47,13 +31,7 @@ async function upload_file(
|
|
|
47
31
|
|
|
48
32
|
function onRequestError(error: unknown): void {
|
|
49
33
|
microservice.stop_request();
|
|
50
|
-
|
|
51
|
-
feedbackStore.add_error(
|
|
52
|
-
typedError.code ?? 0,
|
|
53
|
-
route,
|
|
54
|
-
typedError.message ?? "",
|
|
55
|
-
typedError.stack ?? "",
|
|
56
|
-
);
|
|
34
|
+
reportError(route, error);
|
|
57
35
|
if (request_error_function) {
|
|
58
36
|
void request_error_function(error);
|
|
59
37
|
}
|
|
@@ -61,13 +39,7 @@ async function upload_file(
|
|
|
61
39
|
|
|
62
40
|
function onResponseError(response: unknown): void {
|
|
63
41
|
microservice.stop_request();
|
|
64
|
-
|
|
65
|
-
feedbackStore.add_error(
|
|
66
|
-
typedResponse.status ?? 0,
|
|
67
|
-
route,
|
|
68
|
-
typedResponse.name ?? "",
|
|
69
|
-
typedResponse.description ?? "",
|
|
70
|
-
);
|
|
42
|
+
reportError(route, response);
|
|
71
43
|
if (response_error_function) {
|
|
72
44
|
void response_error_function(response);
|
|
73
45
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonRpcSchema, RequestHandlersWithValidation } from "@ogw_shared/utils/types.js";
|
|
2
2
|
import { endRequestLog, startRequestLog } from "@ogw_front/utils/log";
|
|
3
|
+
import { reportError, reportTimeout } from "./error_feedback.js";
|
|
3
4
|
import type { Microservice } from "./api_fetch.js";
|
|
4
5
|
import type { RpcClient } from "@ogw_shared/utils/call_raw.js";
|
|
5
6
|
import { callSchema } from "@ogw_shared/utils/call_schema";
|
|
@@ -15,22 +16,6 @@ interface ViewerCallParams {
|
|
|
15
16
|
timeout?: number;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Loosely-typed shape for the dynamic error/response values reported by callSchema.
|
|
19
|
-
interface RpcErrorLike {
|
|
20
|
-
code?: number;
|
|
21
|
-
message?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function toRpcErrorLike(value: unknown): RpcErrorLike {
|
|
25
|
-
if (typeof value !== "object" || value === null) {
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
code: "code" in value && typeof value.code === "number" ? value.code : undefined,
|
|
30
|
-
message: "message" in value && typeof value.message === "string" ? value.message : undefined,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
19
|
async function viewer_call(
|
|
35
20
|
microservice: ViewerMicroservice,
|
|
36
21
|
{ schema, params = {}, timeout }: ViewerCallParams,
|
|
@@ -45,7 +30,7 @@ async function viewer_call(
|
|
|
45
30
|
microservice.start_request();
|
|
46
31
|
|
|
47
32
|
const requestStartingTime = startRequestLog(microservice, schema);
|
|
48
|
-
const
|
|
33
|
+
const request = callSchema(
|
|
49
34
|
{
|
|
50
35
|
schema,
|
|
51
36
|
params,
|
|
@@ -53,37 +38,24 @@ async function viewer_call(
|
|
|
53
38
|
timeout,
|
|
54
39
|
},
|
|
55
40
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const typedError = toRpcErrorLike(error);
|
|
59
|
-
feedbackStore.add_error(
|
|
60
|
-
typedError.code ?? 0,
|
|
61
|
-
schema.$id,
|
|
62
|
-
typedError.message ?? "",
|
|
63
|
-
typedError.message ?? "",
|
|
64
|
-
);
|
|
41
|
+
// CallRaw runs both error handlers on the same rejection: stop the request and report it once, in the response one.
|
|
42
|
+
async request_error_function(error: unknown) {
|
|
65
43
|
if (request_error_function) {
|
|
66
|
-
|
|
44
|
+
await request_error_function(error);
|
|
67
45
|
}
|
|
68
46
|
},
|
|
69
|
-
response_function(data: unknown) {
|
|
47
|
+
async response_function(data: unknown) {
|
|
70
48
|
endRequestLog(microservice, schema, requestStartingTime);
|
|
71
49
|
microservice.stop_request();
|
|
72
50
|
if (response_function) {
|
|
73
|
-
response_function(data);
|
|
51
|
+
await response_function(data);
|
|
74
52
|
}
|
|
75
53
|
},
|
|
76
|
-
response_error_function(response: unknown) {
|
|
54
|
+
async response_error_function(response: unknown) {
|
|
77
55
|
microservice.stop_request();
|
|
78
|
-
|
|
79
|
-
feedbackStore.add_error(
|
|
80
|
-
typedResponse.code ?? 0,
|
|
81
|
-
schema.$id,
|
|
82
|
-
typedResponse.message ?? "",
|
|
83
|
-
typedResponse.message ?? "",
|
|
84
|
-
);
|
|
56
|
+
reportError(schema.$id, response);
|
|
85
57
|
if (response_error_function) {
|
|
86
|
-
|
|
58
|
+
await response_error_function(response);
|
|
87
59
|
}
|
|
88
60
|
},
|
|
89
61
|
validation_error_function({ code, name, error }) {
|
|
@@ -92,6 +64,7 @@ async function viewer_call(
|
|
|
92
64
|
},
|
|
93
65
|
},
|
|
94
66
|
);
|
|
67
|
+
const result = await reportTimeout(schema.$id, request);
|
|
95
68
|
return result;
|
|
96
69
|
}
|
|
97
70
|
|
package/package.json
CHANGED