Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useState} from "react";
import {Button, Form, Modal} from "react-bootstrap";
import {Setter} from "../../../util/types";
import "../../SelectionView/SelectionView.css";
import Dropzone from 'react-dropzone';
import AnnotationStore, {AnnotationJson} from "../../../model/annotation/AnnotationStore";
import EnumPair from "../../../model/EnumPair";
import PythonEnum from "../../../model/python/PythonEnum";
import {Setter} from "../../../util/types";
import {isValidJsonFile} from "../../../util/validation";
import "../../SelectionView/SelectionView.css";
import DialogCSS from "../dialogs.module.css";
import AnnotationStore from "../../../model/annotation/AnnotationStore";

interface ImportAnnotationFileDialogProps {
isVisible: boolean
Expand Down Expand Up @@ -38,9 +40,17 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi
const reader = new FileReader();
reader.onload = () => {
if (typeof reader.result === 'string') {
const readAnnotationJson = JSON.parse(reader.result);
readAnnotationJson["renamings"] = new Map(Object.entries(readAnnotationJson["renamings"]));
readAnnotationJson["enums"] = new Map(Object.entries(readAnnotationJson["enums"]));
const readAnnotationJson = JSON.parse(reader.result) as AnnotationJson;

readAnnotationJson.renamings = new Map(Object.entries(readAnnotationJson.renamings));

const enumEntries: [string, PythonEnum][] = Object.entries(readAnnotationJson.enums);
readAnnotationJson.enums = new Map(enumEntries
.map(([key, value]) => [key, new PythonEnum(
value.enumName,
value.enumPairs.map(pair => new EnumPair(pair.key, pair.value))
)]));

setNewAnnotationStore(AnnotationStore.fromJson(readAnnotationJson));
}
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/model/annotation/AnnotationStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Nullable} from "../../util/types";
import PythonDeclaration from "../python/PythonDeclaration";
import PythonEnum from "../python/PythonEnum";

interface annotationsJson {
export interface AnnotationJson {
// These are deliberately normal ES6 maps
renamings: Map<string, string>,
enums: Map<string, PythonEnum>
Expand Down Expand Up @@ -74,7 +74,7 @@ export default class AnnotationStore {
a.click();
}

static fromJson(annotations: annotationsJson): AnnotationStore {
static fromJson(annotations: AnnotationJson): AnnotationStore {
return new AnnotationStore(
Immutable.Map(annotations.renamings),
Immutable.Map(annotations.enums)
Expand Down