Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 877f9ef

Browse files
authored
fix(gui): import of annotation files without schema version (#929)
* fix(gui): include schema version on annotation export * fix(gui): default schema version to 1 for annotation files * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent bfcaced commit 877f9ef

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

api-editor/gui/src/features/annotations/AnnotationImportDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const AnnotationImportDialog: React.FC = function () {
4242
return false;
4343
}
4444

45-
if (!supportedAnnotationStoreSchemaVersions.includes(newAnnotationStore.schemaVersion)) {
45+
if (!supportedAnnotationStoreSchemaVersions.includes(newAnnotationStore.schemaVersion ?? 1)) {
4646
toast({
4747
title: 'Incompatible Annotation File',
4848
description: 'This file is not compatible with the current version of the API Editor.',

api-editor/gui/src/features/annotations/versioning/migrations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { VersionedAnnotationStore } from './VersionedAnnotationStore';
55
export const migrateAnnotationStoreToCurrentVersion = function <OldAnnotationStore extends VersionedAnnotationStore>(
66
oldAnnotationStore: OldAnnotationStore,
77
): AnnotationStoreV2 {
8-
switch (oldAnnotationStore.schemaVersion) {
8+
switch (oldAnnotationStore.schemaVersion ?? 1) {
99
case 1:
1010
return migrateAnnotationStoreV1ToV2(oldAnnotationStore as unknown as AnnotationStoreV1);
1111
case 2:

api-editor/gui/src/features/menuBar/MenuBar.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
6464
import { SelectionBreadcrumbs } from './SelectionBreadcrumbs';
6565
import { HelpMenu } from './HelpMenu';
6666
import { AnnotationStore } from '../annotations/versioning/AnnotationStoreV2';
67+
import { supportedAnnotationStoreSchemaVersions } from '../annotations/versioning/expectedVersions';
6768

6869
interface MenuBarProps {
6970
displayInferErrors: (errors: string[]) => void;
@@ -93,9 +94,22 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
9394

9495
const exportAnnotations = () => {
9596
const a = document.createElement('a');
96-
const file = new Blob([JSON.stringify(annotationStore, null, 4)], {
97-
type: 'application/json',
98-
});
97+
const file = new Blob(
98+
[
99+
JSON.stringify(
100+
{
101+
...annotationStore,
102+
schemaVersion:
103+
supportedAnnotationStoreSchemaVersions[supportedAnnotationStoreSchemaVersions.length - 1],
104+
},
105+
null,
106+
4,
107+
),
108+
],
109+
{
110+
type: 'application/json',
111+
},
112+
);
99113
a.href = URL.createObjectURL(file);
100114
a.download = 'annotations.json';
101115
a.click();

0 commit comments

Comments
 (0)