@comapeo/core-react 6.3.1 → 7.0.0
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/dist/commonjs/hooks/documents.d.ts +143 -108
- package/dist/commonjs/hooks/documents.js +50 -0
- package/dist/commonjs/hooks/projects.d.ts +29 -0
- package/dist/commonjs/hooks/projects.js +19 -0
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.js +3 -1
- package/dist/commonjs/lib/presets.d.ts +2 -0
- package/dist/commonjs/lib/presets.js +25 -0
- package/dist/commonjs/lib/react-query/documents.d.ts +439 -439
- package/dist/commonjs/lib/react-query/projects.d.ts +12 -0
- package/dist/commonjs/lib/react-query/projects.js +14 -0
- package/dist/esm/hooks/documents.d.ts +143 -108
- package/dist/esm/hooks/documents.js +50 -1
- package/dist/esm/hooks/projects.d.ts +29 -0
- package/dist/esm/hooks/projects.js +19 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/presets.d.ts +2 -0
- package/dist/esm/lib/presets.js +22 -0
- package/dist/esm/lib/react-query/documents.d.ts +439 -439
- package/dist/esm/lib/react-query/projects.d.ts +12 -0
- package/dist/esm/lib/react-query/projects.js +13 -0
- package/package.json +7 -5
|
@@ -158,6 +158,18 @@ export declare function leaveProjectMutationOptions({ clientApi, queryClient, }:
|
|
|
158
158
|
networkMode: "always";
|
|
159
159
|
retry: false;
|
|
160
160
|
};
|
|
161
|
+
export declare function importProjectCategoriesMutationOptions({ projectApi, projectId, queryClient, }: {
|
|
162
|
+
projectApi: MapeoProjectApi;
|
|
163
|
+
projectId: string;
|
|
164
|
+
queryClient: QueryClient;
|
|
165
|
+
}): {
|
|
166
|
+
mutationFn: ({ filePath }: {
|
|
167
|
+
filePath: string;
|
|
168
|
+
}) => Promise<void>;
|
|
169
|
+
onSuccess: () => void;
|
|
170
|
+
networkMode: "always";
|
|
171
|
+
retry: false;
|
|
172
|
+
};
|
|
161
173
|
export declare function importProjectConfigMutationOptions({ projectApi, projectId, queryClient, }: {
|
|
162
174
|
projectApi: MapeoProjectApi;
|
|
163
175
|
projectId: string;
|
|
@@ -20,6 +20,7 @@ exports.addServerPeerMutationOptions = addServerPeerMutationOptions;
|
|
|
20
20
|
exports.removeServerPeerMutationOptions = removeServerPeerMutationOptions;
|
|
21
21
|
exports.createProjectMutationOptions = createProjectMutationOptions;
|
|
22
22
|
exports.leaveProjectMutationOptions = leaveProjectMutationOptions;
|
|
23
|
+
exports.importProjectCategoriesMutationOptions = importProjectCategoriesMutationOptions;
|
|
23
24
|
exports.importProjectConfigMutationOptions = importProjectConfigMutationOptions;
|
|
24
25
|
exports.updateProjectSettingsMutationOptions = updateProjectSettingsMutationOptions;
|
|
25
26
|
exports.changeMemberRoleMutationOptions = changeMemberRoleMutationOptions;
|
|
@@ -222,6 +223,19 @@ function leaveProjectMutationOptions({ clientApi, queryClient, }) {
|
|
|
222
223
|
},
|
|
223
224
|
};
|
|
224
225
|
}
|
|
226
|
+
function importProjectCategoriesMutationOptions({ projectApi, projectId, queryClient, }) {
|
|
227
|
+
return {
|
|
228
|
+
...(0, shared_js_1.baseMutationOptions)(),
|
|
229
|
+
mutationFn: ({ filePath }) => {
|
|
230
|
+
return projectApi.$importCategories({ filePath });
|
|
231
|
+
},
|
|
232
|
+
onSuccess: () => {
|
|
233
|
+
queryClient.invalidateQueries({
|
|
234
|
+
queryKey: getProjectByIdQueryKey({ projectId }),
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
225
239
|
function importProjectConfigMutationOptions({ projectApi, projectId, queryClient, }) {
|
|
226
240
|
return {
|
|
227
241
|
...(0, shared_js_1.baseMutationOptions)(),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Preset } from '@comapeo/schema' with { 'resolution-mode': 'import' };
|
|
1
2
|
import type { WriteableDocumentType } from '../lib/types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Retrieve a single document from the database based on the document's document ID.
|
|
@@ -50,28 +51,14 @@ export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ p
|
|
|
50
51
|
links: string[];
|
|
51
52
|
deleted: boolean;
|
|
52
53
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
53
|
-
schemaName: "
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
schemaName: "remoteDetectionAlert";
|
|
55
|
+
detectionDateStart: string;
|
|
56
|
+
detectionDateEnd: string;
|
|
57
|
+
sourceId: string;
|
|
58
|
+
metadata: {
|
|
58
59
|
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
-
manualLocation?: boolean;
|
|
62
|
-
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
63
|
-
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
64
|
-
positionProvider?: {
|
|
65
|
-
gpsAvailable?: boolean;
|
|
66
|
-
passiveAvailable?: boolean;
|
|
67
|
-
locationServicesEnabled: boolean;
|
|
68
|
-
networkAvailable?: boolean;
|
|
69
|
-
};
|
|
70
|
-
} | undefined;
|
|
71
|
-
presetRef?: {
|
|
72
|
-
docId: string;
|
|
73
|
-
versionId: string;
|
|
74
|
-
} | undefined;
|
|
61
|
+
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
75
62
|
docId: string;
|
|
76
63
|
versionId: string;
|
|
77
64
|
originalVersionId: string;
|
|
@@ -103,6 +90,36 @@ export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ p
|
|
|
103
90
|
updatedAt: string;
|
|
104
91
|
links: string[];
|
|
105
92
|
deleted: boolean;
|
|
93
|
+
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
94
|
+
schemaName: "observation";
|
|
95
|
+
lat?: number | undefined;
|
|
96
|
+
lon?: number | undefined;
|
|
97
|
+
attachments: import("@comapeo/schema/dist/schema/observation.js").Attachment[];
|
|
98
|
+
tags: {
|
|
99
|
+
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
100
|
+
};
|
|
101
|
+
metadata?: {
|
|
102
|
+
manualLocation?: boolean;
|
|
103
|
+
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
104
|
+
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
105
|
+
positionProvider?: {
|
|
106
|
+
gpsAvailable?: boolean;
|
|
107
|
+
passiveAvailable?: boolean;
|
|
108
|
+
locationServicesEnabled: boolean;
|
|
109
|
+
networkAvailable?: boolean;
|
|
110
|
+
};
|
|
111
|
+
} | undefined;
|
|
112
|
+
presetRef?: {
|
|
113
|
+
docId: string;
|
|
114
|
+
versionId: string;
|
|
115
|
+
} | undefined;
|
|
116
|
+
docId: string;
|
|
117
|
+
versionId: string;
|
|
118
|
+
originalVersionId: string;
|
|
119
|
+
createdAt: string;
|
|
120
|
+
updatedAt: string;
|
|
121
|
+
links: string[];
|
|
122
|
+
deleted: boolean;
|
|
106
123
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
107
124
|
schemaName: "field";
|
|
108
125
|
tagKey: string;
|
|
@@ -124,22 +141,6 @@ export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ p
|
|
|
124
141
|
updatedAt: string;
|
|
125
142
|
links: string[];
|
|
126
143
|
deleted: boolean;
|
|
127
|
-
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
128
|
-
schemaName: "remoteDetectionAlert";
|
|
129
|
-
detectionDateStart: string;
|
|
130
|
-
detectionDateEnd: string;
|
|
131
|
-
sourceId: string;
|
|
132
|
-
metadata: {
|
|
133
|
-
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
134
|
-
};
|
|
135
|
-
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
136
|
-
docId: string;
|
|
137
|
-
versionId: string;
|
|
138
|
-
originalVersionId: string;
|
|
139
|
-
createdAt: string;
|
|
140
|
-
updatedAt: string;
|
|
141
|
-
links: string[];
|
|
142
|
-
deleted: boolean;
|
|
143
144
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields), {
|
|
144
145
|
schemaName: D;
|
|
145
146
|
}>;
|
|
@@ -197,28 +198,14 @@ export declare function useSingleDocByVersionId<D extends WriteableDocumentType>
|
|
|
197
198
|
links: string[];
|
|
198
199
|
deleted: boolean;
|
|
199
200
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
200
|
-
schemaName: "
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
schemaName: "remoteDetectionAlert";
|
|
202
|
+
detectionDateStart: string;
|
|
203
|
+
detectionDateEnd: string;
|
|
204
|
+
sourceId: string;
|
|
205
|
+
metadata: {
|
|
205
206
|
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
206
207
|
};
|
|
207
|
-
|
|
208
|
-
manualLocation?: boolean;
|
|
209
|
-
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
210
|
-
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
211
|
-
positionProvider?: {
|
|
212
|
-
gpsAvailable?: boolean;
|
|
213
|
-
passiveAvailable?: boolean;
|
|
214
|
-
locationServicesEnabled: boolean;
|
|
215
|
-
networkAvailable?: boolean;
|
|
216
|
-
};
|
|
217
|
-
} | undefined;
|
|
218
|
-
presetRef?: {
|
|
219
|
-
docId: string;
|
|
220
|
-
versionId: string;
|
|
221
|
-
} | undefined;
|
|
208
|
+
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
222
209
|
docId: string;
|
|
223
210
|
versionId: string;
|
|
224
211
|
originalVersionId: string;
|
|
@@ -250,6 +237,36 @@ export declare function useSingleDocByVersionId<D extends WriteableDocumentType>
|
|
|
250
237
|
updatedAt: string;
|
|
251
238
|
links: string[];
|
|
252
239
|
deleted: boolean;
|
|
240
|
+
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
241
|
+
schemaName: "observation";
|
|
242
|
+
lat?: number | undefined;
|
|
243
|
+
lon?: number | undefined;
|
|
244
|
+
attachments: import("@comapeo/schema/dist/schema/observation.js").Attachment[];
|
|
245
|
+
tags: {
|
|
246
|
+
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
247
|
+
};
|
|
248
|
+
metadata?: {
|
|
249
|
+
manualLocation?: boolean;
|
|
250
|
+
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
251
|
+
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
252
|
+
positionProvider?: {
|
|
253
|
+
gpsAvailable?: boolean;
|
|
254
|
+
passiveAvailable?: boolean;
|
|
255
|
+
locationServicesEnabled: boolean;
|
|
256
|
+
networkAvailable?: boolean;
|
|
257
|
+
};
|
|
258
|
+
} | undefined;
|
|
259
|
+
presetRef?: {
|
|
260
|
+
docId: string;
|
|
261
|
+
versionId: string;
|
|
262
|
+
} | undefined;
|
|
263
|
+
docId: string;
|
|
264
|
+
versionId: string;
|
|
265
|
+
originalVersionId: string;
|
|
266
|
+
createdAt: string;
|
|
267
|
+
updatedAt: string;
|
|
268
|
+
links: string[];
|
|
269
|
+
deleted: boolean;
|
|
253
270
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
254
271
|
schemaName: "field";
|
|
255
272
|
tagKey: string;
|
|
@@ -271,22 +288,6 @@ export declare function useSingleDocByVersionId<D extends WriteableDocumentType>
|
|
|
271
288
|
updatedAt: string;
|
|
272
289
|
links: string[];
|
|
273
290
|
deleted: boolean;
|
|
274
|
-
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields) | ({
|
|
275
|
-
schemaName: "remoteDetectionAlert";
|
|
276
|
-
detectionDateStart: string;
|
|
277
|
-
detectionDateEnd: string;
|
|
278
|
-
sourceId: string;
|
|
279
|
-
metadata: {
|
|
280
|
-
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
281
|
-
};
|
|
282
|
-
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
283
|
-
docId: string;
|
|
284
|
-
versionId: string;
|
|
285
|
-
originalVersionId: string;
|
|
286
|
-
createdAt: string;
|
|
287
|
-
updatedAt: string;
|
|
288
|
-
links: string[];
|
|
289
|
-
deleted: boolean;
|
|
290
291
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields), {
|
|
291
292
|
schemaName: D;
|
|
292
293
|
}>;
|
|
@@ -355,28 +356,14 @@ export declare function useManyDocs<D extends WriteableDocumentType>({ projectId
|
|
|
355
356
|
links: string[];
|
|
356
357
|
deleted: boolean;
|
|
357
358
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields)[] | ({
|
|
358
|
-
schemaName: "
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
schemaName: "remoteDetectionAlert";
|
|
360
|
+
detectionDateStart: string;
|
|
361
|
+
detectionDateEnd: string;
|
|
362
|
+
sourceId: string;
|
|
363
|
+
metadata: {
|
|
363
364
|
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
364
365
|
};
|
|
365
|
-
|
|
366
|
-
manualLocation?: boolean;
|
|
367
|
-
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
368
|
-
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
369
|
-
positionProvider?: {
|
|
370
|
-
gpsAvailable?: boolean;
|
|
371
|
-
passiveAvailable?: boolean;
|
|
372
|
-
locationServicesEnabled: boolean;
|
|
373
|
-
networkAvailable?: boolean;
|
|
374
|
-
};
|
|
375
|
-
} | undefined;
|
|
376
|
-
presetRef?: {
|
|
377
|
-
docId: string;
|
|
378
|
-
versionId: string;
|
|
379
|
-
} | undefined;
|
|
366
|
+
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
380
367
|
docId: string;
|
|
381
368
|
versionId: string;
|
|
382
369
|
originalVersionId: string;
|
|
@@ -408,6 +395,36 @@ export declare function useManyDocs<D extends WriteableDocumentType>({ projectId
|
|
|
408
395
|
updatedAt: string;
|
|
409
396
|
links: string[];
|
|
410
397
|
deleted: boolean;
|
|
398
|
+
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields)[] | ({
|
|
399
|
+
schemaName: "observation";
|
|
400
|
+
lat?: number | undefined;
|
|
401
|
+
lon?: number | undefined;
|
|
402
|
+
attachments: import("@comapeo/schema/dist/schema/observation.js").Attachment[];
|
|
403
|
+
tags: {
|
|
404
|
+
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
405
|
+
};
|
|
406
|
+
metadata?: {
|
|
407
|
+
manualLocation?: boolean;
|
|
408
|
+
position?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
409
|
+
lastSavedPosition?: import("@comapeo/schema/dist/schema/observation.js").Position;
|
|
410
|
+
positionProvider?: {
|
|
411
|
+
gpsAvailable?: boolean;
|
|
412
|
+
passiveAvailable?: boolean;
|
|
413
|
+
locationServicesEnabled: boolean;
|
|
414
|
+
networkAvailable?: boolean;
|
|
415
|
+
};
|
|
416
|
+
} | undefined;
|
|
417
|
+
presetRef?: {
|
|
418
|
+
docId: string;
|
|
419
|
+
versionId: string;
|
|
420
|
+
} | undefined;
|
|
421
|
+
docId: string;
|
|
422
|
+
versionId: string;
|
|
423
|
+
originalVersionId: string;
|
|
424
|
+
createdAt: string;
|
|
425
|
+
updatedAt: string;
|
|
426
|
+
links: string[];
|
|
427
|
+
deleted: boolean;
|
|
411
428
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields)[] | ({
|
|
412
429
|
schemaName: "field";
|
|
413
430
|
tagKey: string;
|
|
@@ -429,22 +446,6 @@ export declare function useManyDocs<D extends WriteableDocumentType>({ projectId
|
|
|
429
446
|
updatedAt: string;
|
|
430
447
|
links: string[];
|
|
431
448
|
deleted: boolean;
|
|
432
|
-
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields)[] | ({
|
|
433
|
-
schemaName: "remoteDetectionAlert";
|
|
434
|
-
detectionDateStart: string;
|
|
435
|
-
detectionDateEnd: string;
|
|
436
|
-
sourceId: string;
|
|
437
|
-
metadata: {
|
|
438
|
-
[k: string]: boolean | number | string | null | (boolean | number | string | null)[];
|
|
439
|
-
};
|
|
440
|
-
geometry: import("@comapeo/schema/dist/schema/remoteDetectionAlert.js").Geometry;
|
|
441
|
-
docId: string;
|
|
442
|
-
versionId: string;
|
|
443
|
-
originalVersionId: string;
|
|
444
|
-
createdAt: string;
|
|
445
|
-
updatedAt: string;
|
|
446
|
-
links: string[];
|
|
447
|
-
deleted: boolean;
|
|
448
449
|
} & import("@comapeo/core/dist/datatype/index.js").DerivedDocFields)[], Array<{
|
|
449
450
|
schemaName: D;
|
|
450
451
|
}>>;
|
|
@@ -545,3 +546,37 @@ export declare function useDeleteDocument<D extends WriteableDocumentType>({ doc
|
|
|
545
546
|
reset: () => void;
|
|
546
547
|
status: "pending" | "success" | "idle";
|
|
547
548
|
};
|
|
549
|
+
/**
|
|
550
|
+
* Retrieve presets for category selection, ordered by project settings.
|
|
551
|
+
*
|
|
552
|
+
* Returns presets in the order defined by `projectSettings.defaultPresets` for the
|
|
553
|
+
* specified data type. Falls back to alphabetical order (by preset name) if no defaults are configured.
|
|
554
|
+
*
|
|
555
|
+
* @param opts.projectId Project public ID
|
|
556
|
+
* @param opts.dataType Type of data being created ('observation' or 'track')
|
|
557
|
+
* @param opts.lang Language to translate presets into
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```tsx
|
|
561
|
+
* function ObservationCategoryChooser() {
|
|
562
|
+
* const presets = usePresetsSelection({
|
|
563
|
+
* projectId: '...',
|
|
564
|
+
* dataType: 'observation',
|
|
565
|
+
* })
|
|
566
|
+
* }
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* ```tsx
|
|
570
|
+
* function TrackCategoryChooser() {
|
|
571
|
+
* const presets = usePresetsSelection({
|
|
572
|
+
* projectId: '...',
|
|
573
|
+
* dataType: 'track',
|
|
574
|
+
* })
|
|
575
|
+
* }
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
export declare function usePresetsSelection({ projectId, dataType, lang, }: {
|
|
579
|
+
projectId: string;
|
|
580
|
+
dataType: 'observation' | 'track';
|
|
581
|
+
lang?: string;
|
|
582
|
+
}): Array<Preset>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { getPresetsSelection } from '../lib/presets.js';
|
|
2
4
|
import { createDocumentMutationOptions, deleteDocumentMutationOptions, documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, updateDocumentMutationOptions, } from '../lib/react-query/documents.js';
|
|
3
|
-
import { useSingleProject } from './projects.js';
|
|
5
|
+
import { useProjectSettings, useSingleProject } from './projects.js';
|
|
4
6
|
/**
|
|
5
7
|
* Retrieve a single document from the database based on the document's document ID.
|
|
6
8
|
*
|
|
@@ -183,3 +185,50 @@ export function useDeleteDocument({ docType, projectId, }) {
|
|
|
183
185
|
? { error, mutate, mutateAsync, reset, status }
|
|
184
186
|
: { error: null, mutate, mutateAsync, reset, status };
|
|
185
187
|
}
|
|
188
|
+
const dataTypeToGeometry = {
|
|
189
|
+
observation: 'point',
|
|
190
|
+
track: 'line',
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Retrieve presets for category selection, ordered by project settings.
|
|
194
|
+
*
|
|
195
|
+
* Returns presets in the order defined by `projectSettings.defaultPresets` for the
|
|
196
|
+
* specified data type. Falls back to alphabetical order (by preset name) if no defaults are configured.
|
|
197
|
+
*
|
|
198
|
+
* @param opts.projectId Project public ID
|
|
199
|
+
* @param opts.dataType Type of data being created ('observation' or 'track')
|
|
200
|
+
* @param opts.lang Language to translate presets into
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* function ObservationCategoryChooser() {
|
|
205
|
+
* const presets = usePresetsSelection({
|
|
206
|
+
* projectId: '...',
|
|
207
|
+
* dataType: 'observation',
|
|
208
|
+
* })
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* ```tsx
|
|
213
|
+
* function TrackCategoryChooser() {
|
|
214
|
+
* const presets = usePresetsSelection({
|
|
215
|
+
* projectId: '...',
|
|
216
|
+
* dataType: 'track',
|
|
217
|
+
* })
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export function usePresetsSelection({ projectId, dataType, lang, }) {
|
|
222
|
+
const { data: projectSettings } = useProjectSettings({ projectId });
|
|
223
|
+
const { data: presets } = useManyDocs({
|
|
224
|
+
projectId,
|
|
225
|
+
docType: 'preset',
|
|
226
|
+
lang,
|
|
227
|
+
});
|
|
228
|
+
const presetsSelection = useMemo(() => {
|
|
229
|
+
const geometry = dataTypeToGeometry[dataType];
|
|
230
|
+
const defaults = projectSettings.defaultPresets?.[geometry];
|
|
231
|
+
return getPresetsSelection(presets, defaults);
|
|
232
|
+
}, [presets, projectSettings.defaultPresets, dataType]);
|
|
233
|
+
return presetsSelection;
|
|
234
|
+
}
|
|
@@ -360,9 +360,38 @@ export declare function useLeaveProject(): {
|
|
|
360
360
|
reset: () => void;
|
|
361
361
|
status: "pending" | "success" | "idle";
|
|
362
362
|
};
|
|
363
|
+
/**
|
|
364
|
+
* Update the categories of a project using an external file.
|
|
365
|
+
*
|
|
366
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
367
|
+
*/
|
|
368
|
+
export declare function useImportProjectCategories({ projectId, }: {
|
|
369
|
+
projectId: string;
|
|
370
|
+
}): {
|
|
371
|
+
error: Error;
|
|
372
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
373
|
+
filePath: string;
|
|
374
|
+
}, unknown>;
|
|
375
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
376
|
+
filePath: string;
|
|
377
|
+
}, unknown>;
|
|
378
|
+
reset: () => void;
|
|
379
|
+
status: "error";
|
|
380
|
+
} | {
|
|
381
|
+
error: null;
|
|
382
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
383
|
+
filePath: string;
|
|
384
|
+
}, unknown>;
|
|
385
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
386
|
+
filePath: string;
|
|
387
|
+
}, unknown>;
|
|
388
|
+
reset: () => void;
|
|
389
|
+
status: "pending" | "success" | "idle";
|
|
390
|
+
};
|
|
363
391
|
/**
|
|
364
392
|
* Update the configuration of a project using an external file.
|
|
365
393
|
*
|
|
394
|
+
* @deprecated Use `useImportProjectCategories` instead.
|
|
366
395
|
* @param opts.projectId Public ID of the project to apply changes to.
|
|
367
396
|
*/
|
|
368
397
|
export declare function useImportProjectConfig({ projectId }: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
2
|
import { useSyncExternalStore } from 'react';
|
|
3
|
-
import { addServerPeerMutationOptions, changeMemberRoleMutationOptions, connectSyncServersMutationOptions, createBlobMutationOptions, createProjectMutationOptions, disconnectSyncServersMutationOptions, documentCreatedByQueryOptions, exportGeoJSONMutationOptions, exportZipFileMutationOptions, importProjectConfigMutationOptions, leaveProjectMutationOptions, mediaServerOriginQueryOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectOwnRoleQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, removeServerPeerMutationOptions, setAutostopDataSyncTimeoutMutationOptions, startSyncMutationOptions, stopSyncMutationOptions, updateProjectSettingsMutationOptions, } from '../lib/react-query/projects.js';
|
|
3
|
+
import { addServerPeerMutationOptions, changeMemberRoleMutationOptions, connectSyncServersMutationOptions, createBlobMutationOptions, createProjectMutationOptions, disconnectSyncServersMutationOptions, documentCreatedByQueryOptions, exportGeoJSONMutationOptions, exportZipFileMutationOptions, importProjectCategoriesMutationOptions, importProjectConfigMutationOptions, leaveProjectMutationOptions, mediaServerOriginQueryOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectOwnRoleQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, removeServerPeerMutationOptions, setAutostopDataSyncTimeoutMutationOptions, startSyncMutationOptions, stopSyncMutationOptions, updateProjectSettingsMutationOptions, } from '../lib/react-query/projects.js';
|
|
4
4
|
import { SyncStore } from '../lib/sync.js';
|
|
5
5
|
import { getBlobUrl, getIconUrl } from '../lib/urls.js';
|
|
6
6
|
import { useClientApi } from './client.js';
|
|
@@ -317,9 +317,27 @@ export function useLeaveProject() {
|
|
|
317
317
|
? { error, mutate, mutateAsync, reset, status }
|
|
318
318
|
: { error: null, mutate, mutateAsync, reset, status };
|
|
319
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Update the categories of a project using an external file.
|
|
322
|
+
*
|
|
323
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
324
|
+
*/
|
|
325
|
+
export function useImportProjectCategories({ projectId, }) {
|
|
326
|
+
const queryClient = useQueryClient();
|
|
327
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
328
|
+
const { error, mutate, mutateAsync, reset, status } = useMutation(importProjectCategoriesMutationOptions({
|
|
329
|
+
queryClient,
|
|
330
|
+
projectApi,
|
|
331
|
+
projectId,
|
|
332
|
+
}));
|
|
333
|
+
return status === 'error'
|
|
334
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
335
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
336
|
+
}
|
|
320
337
|
/**
|
|
321
338
|
* Update the configuration of a project using an external file.
|
|
322
339
|
*
|
|
340
|
+
* @deprecated Use `useImportProjectCategories` instead.
|
|
323
341
|
* @param opts.projectId Public ID of the project to apply changes to.
|
|
324
342
|
*/
|
|
325
343
|
export function useImportProjectConfig({ projectId }) {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
|
|
2
2
|
export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
|
|
3
|
-
export { useCreateDocument, useDeleteDocument, useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
|
|
3
|
+
export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
|
|
4
4
|
export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSetUpInvitesListeners, useSingleInvite, } from './hooks/invites.js';
|
|
5
5
|
export { useMapStyleUrl } from './hooks/maps.js';
|
|
6
|
-
export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectSettings, useRemoveServerPeer, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
|
|
6
|
+
export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectSettings, useRemoveServerPeer, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
|
|
7
7
|
export { type SyncState } from './lib/sync.js';
|
|
8
8
|
export { type WriteableDocument, type WriteableDocumentType, type WriteableValue, } from './lib/types.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
|
|
2
2
|
export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
|
|
3
|
-
export { useCreateDocument, useDeleteDocument, useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
|
|
3
|
+
export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
|
|
4
4
|
export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSetUpInvitesListeners, useSingleInvite, } from './hooks/invites.js';
|
|
5
5
|
export { useMapStyleUrl } from './hooks/maps.js';
|
|
6
|
-
export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectSettings, useRemoveServerPeer, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
|
|
6
|
+
export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectSettings, useRemoveServerPeer, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helper to sort presets alphabetically by name (case-insensitive).
|
|
3
|
+
*/
|
|
4
|
+
function sortByName(presets) {
|
|
5
|
+
return [...presets].sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
6
|
+
}
|
|
7
|
+
export function getPresetsSelection(presets, orderedPresetIds = []) {
|
|
8
|
+
if (orderedPresetIds.length === 0) {
|
|
9
|
+
return sortByName(presets);
|
|
10
|
+
}
|
|
11
|
+
const presetsSelection = [];
|
|
12
|
+
for (const presetId of orderedPresetIds) {
|
|
13
|
+
const preset = presets.find((p) => p.docId === presetId);
|
|
14
|
+
if (preset) {
|
|
15
|
+
presetsSelection.push(preset);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (presetsSelection.length === 0) {
|
|
19
|
+
return sortByName(presets);
|
|
20
|
+
}
|
|
21
|
+
return presetsSelection;
|
|
22
|
+
}
|