From b6dd2efddabe2b4dd1f2a95e3c68dfdb87b14ca4 Mon Sep 17 00:00:00 2001 From: PaulV Date: Fri, 16 Jul 2021 15:29:08 +0200 Subject: [PATCH 01/12] =?UTF-8?q?Json=20Funktionalit=C3=A4t=20im=20Annotat?= =?UTF-8?q?ionStore=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dialog/ImportAnnotationFileDialog.tsx | 67 +++++++++++-------- .../src/model/annotation/AnnotationStore.tsx | 21 ++++++ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx index d50ff6ca0..ed576f73d 100644 --- a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx +++ b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx @@ -1,10 +1,11 @@ -import React, {useState} from "react"; +import React, {FormEvent, 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 {isValidJsonFile} from "../../util/validation"; import DialogCSS from "./dialog.module.css"; +import AnnotationStore from "../../model/annotation/AnnotationStore"; interface ImportAnnotationFileDialogProps { isVisible: boolean @@ -14,28 +15,43 @@ interface ImportAnnotationFileDialogProps { export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDialogProps): JSX.Element { const [fileName, setFileName] = useState(""); - /* not yet needed, but important for storing the file later - const [file, setFile] = useState([]); */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const [annotationJson, setAnnotationJson] = useState(); const close = () => { props.setIsVisible(false); }; - const submit = () => { - console.log("TODO"); + const submit = (event: FormEvent) => { + event.preventDefault(); + props.setIsVisible(false); + }; + + const onDrop = (acceptedFiles: File[]) => { + if (isValidJsonFile(acceptedFiles[acceptedFiles.length - 1].name)) { + if (acceptedFiles.length > 1) { + acceptedFiles = [acceptedFiles[acceptedFiles.length - 1]]; + } + setFileName(acceptedFiles[0].name); + const reader = new FileReader(); + reader.onload = () => { + if (typeof reader.result === 'string') { + const readAnnotationJson = JSON.parse(reader.result); + setAnnotationJson(readAnnotationJson); + new AnnotationStore().fromJson(readAnnotationJson); + } + }; + } }; return ( - + Import annotation file -
@@ -44,22 +60,16 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi Select an annotation file to upload.
- { - if (isValidJsonFile(acceptedFiles[acceptedFiles.length - 1].name)) { - if (acceptedFiles.length > 1) { - acceptedFiles = [acceptedFiles[acceptedFiles.length - 1]]; - } - setFileName(acceptedFiles[0].name); - /* not yet needed, but important for storing the file later - setFile([acceptedFiles[0]]);*/ - } - }}> + {({getRootProps, getInputProps}) => (
- -

Drag and drop an annotation files here, or click to select the - file
(only *.json will be accepted)

+ +

+ Drag and drop an annotation file here or click to select the + file.
+ (only *.json will be accepted) +

)} @@ -69,10 +79,13 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi - - diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index 066f1525d..000a64595 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -2,6 +2,13 @@ import {Map} from "immutable"; import {Nullable} from "../../util/types"; import PythonDeclaration from "../python/PythonDeclaration"; +/* TODO: Es fehlen die Enums. */ + +interface annotationsJson { + renamings: Map, + enums: Map> +} + export default class AnnotationStore { private readonly renamings: RenameAnnotationStore @@ -21,9 +28,23 @@ export default class AnnotationStore { return new AnnotationStore(this.renamings.set(declaration.pathAsString(), newName)); } + private setRenaming(path: string, newName: string) { + return new AnnotationStore(this.renamings.set(path, newName)); + } + removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { return new AnnotationStore(this.renamings.remove(declaration.pathAsString())); } + + toJson(): string { + return JSON.stringify({"renamings": this.renamings}); + } + + fromJson(annotations: annotationsJson): void { + annotations.renamings.forEach(((value, key) => { + this.setRenaming(value, key); + })); + } } export type RenameAnnotationStore = Map From ae5e762761e11a6c6342830d861137cf15afb111 Mon Sep 17 00:00:00 2001 From: PaulV Date: Fri, 16 Jul 2021 16:33:44 +0200 Subject: [PATCH 02/12] prepare annotation store --- client/src/Components/App/App.tsx | 2 +- client/src/Components/Menu/Menu.tsx | 14 +++++++++++-- .../src/model/annotation/AnnotationStore.tsx | 21 ++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/client/src/Components/App/App.tsx b/client/src/Components/App/App.tsx index 592c83d2e..970335d65 100644 --- a/client/src/Components/App/App.tsx +++ b/client/src/Components/App/App.tsx @@ -17,7 +17,7 @@ export default function App(): JSX.Element {
- +
diff --git a/client/src/Components/Menu/Menu.tsx b/client/src/Components/Menu/Menu.tsx index 9d4a70ea4..dfb8620bf 100644 --- a/client/src/Components/Menu/Menu.tsx +++ b/client/src/Components/Menu/Menu.tsx @@ -8,9 +8,11 @@ import ImportAnnotationFileDialog from "../Dialog/ImportAnnotationFileDialog"; import ImportPythonPackageDialog from "../Dialog/ImportPythonPackageDialog"; import {Setter} from "../../util/types"; import PythonPackage from "../../model/python/PythonPackage"; +import AnnotationStore from "../../model/annotation/AnnotationStore"; interface MenuProps { setPythonPackage: Setter + annotationStore: AnnotationStore } export default function Menu(props: MenuProps): JSX.Element { @@ -24,6 +26,10 @@ export default function Menu(props: MenuProps): JSX.Element { const pathname = useLocation().pathname.split("/").slice(1); const cssClasses = classNames(MenuCSS.menu, "justify-content-between"); + const exportAnnotations = () => { + props.annotationStore.downloadAnnotations(props.annotationStore.toJson()); + }; + return ( { @@ -40,9 +46,13 @@ export default function Menu(props: MenuProps): JSX.Element { {showImportAnnotationFileDialog && } diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index 0ce10b0cd..3789a5861 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -7,7 +7,7 @@ import PythonEnum from "../python/PythonEnum"; interface annotationsJson { renamings: Map, - enums: Map> + enums: Map } export default class AnnotationStore { @@ -47,6 +47,10 @@ export default class AnnotationStore { return new AnnotationStore(this.renamings.set(path, newName)); } + private setEnum(path: string, pythonEnum: PythonEnum) { + return new AnnotationStore(this.renamings, this.enums.set(path, pythonEnum)); + } + removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { return new AnnotationStore(this.renamings.remove(declaration.pathAsString()), this.enums); } @@ -56,12 +60,23 @@ export default class AnnotationStore { } toJson(): string { - return JSON.stringify({"renamings": this.renamings}); + return JSON.stringify({"renamings": this.renamings, "enums": this.enums}); + } + + downloadAnnotations(content: string): void { + const a = document.createElement("a"); + const file = new Blob([content], {type: "text/plain"}); + a.href = URL.createObjectURL(file); + a.download = "annotations.json"; + a.click(); } fromJson(annotations: annotationsJson): void { annotations.renamings.forEach(((value, key) => { - this.setRenaming(value, key); + this.setRenaming(key, value); + })); + annotations.enums.forEach(((value, key) => { + this.setEnum(key, value); })); } } From f5656b0d74f64ae30c15a7e238e22a2b335e067e Mon Sep 17 00:00:00 2001 From: PaulV Date: Fri, 16 Jul 2021 16:59:32 +0200 Subject: [PATCH 03/12] prepare annotation store --- client/src/model/annotation/AnnotationStore.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index 3789a5861..b0b5f03ba 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -44,7 +44,7 @@ export default class AnnotationStore { } private setRenaming(path: string, newName: string) { - return new AnnotationStore(this.renamings.set(path, newName)); + return new AnnotationStore(this.renamings.set(path, newName), this.enums); } private setEnum(path: string, pythonEnum: PythonEnum) { From 8fdaeb6fe3da8d043c5c483f8f97973af1738d92 Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 13:59:48 +0200 Subject: [PATCH 04/12] import now working using map before imports still missing --- client/src/Components/App/App.tsx | 3 +- .../Dialog/ImportAnnotationFileDialog.tsx | 9 +++--- client/src/Components/Menu/Menu.tsx | 4 ++- .../Components/SelectionView/FunctionView.tsx | 28 ++++++++++--------- .../src/model/annotation/AnnotationStore.tsx | 23 +++++++-------- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/client/src/Components/App/App.tsx b/client/src/Components/App/App.tsx index 970335d65..5e1a05e16 100644 --- a/client/src/Components/App/App.tsx +++ b/client/src/Components/App/App.tsx @@ -17,7 +17,8 @@ export default function App(): JSX.Element {
- +
diff --git a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx index ed576f73d..961e2ddde 100644 --- a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx +++ b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx @@ -10,13 +10,12 @@ import AnnotationStore from "../../model/annotation/AnnotationStore"; interface ImportAnnotationFileDialogProps { isVisible: boolean setIsVisible: Setter + setAnnotationStore: Setter } export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDialogProps): JSX.Element { const [fileName, setFileName] = useState(""); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [annotationJson, setAnnotationJson] = useState(); const close = () => { props.setIsVisible(false); @@ -37,8 +36,10 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi reader.onload = () => { if (typeof reader.result === 'string') { const readAnnotationJson = JSON.parse(reader.result); - setAnnotationJson(readAnnotationJson); - new AnnotationStore().fromJson(readAnnotationJson); + readAnnotationJson["renamings"] = new Map(Object.entries(readAnnotationJson["renamings"])); + readAnnotationJson["enums"] = new Map(Object.entries(readAnnotationJson["enums"])); + const result = AnnotationStore.fromJson(readAnnotationJson); + props.setAnnotationStore(result); } }; } diff --git a/client/src/Components/Menu/Menu.tsx b/client/src/Components/Menu/Menu.tsx index dfb8620bf..87a5e65d0 100644 --- a/client/src/Components/Menu/Menu.tsx +++ b/client/src/Components/Menu/Menu.tsx @@ -13,6 +13,7 @@ import AnnotationStore from "../../model/annotation/AnnotationStore"; interface MenuProps { setPythonPackage: Setter annotationStore: AnnotationStore + setAnnotationStore: Setter } export default function Menu(props: MenuProps): JSX.Element { @@ -55,7 +56,8 @@ export default function Menu(props: MenuProps): JSX.Element { {showImportAnnotationFileDialog && } + setIsVisible={setShowImportAnnotationFileDialog} + setAnnotationStore={props.setAnnotationStore}/>} {showImportPythonPackageDialog && } diff --git a/client/src/Components/SelectionView/FunctionView.tsx b/client/src/Components/SelectionView/FunctionView.tsx index 1dae0c4bb..763465663 100644 --- a/client/src/Components/SelectionView/FunctionView.tsx +++ b/client/src/Components/SelectionView/FunctionView.tsx @@ -25,19 +25,21 @@ export default function FunctionView(props: FunctionViewProps): JSX.Element {

{declaration.name}

Parameters

- { - !isEmptyList(declaration.parameters) ? - declaration.parameters.map(parameters => ( - - )) : - There are no parameters. - } +
+ { + !isEmptyList(declaration.parameters) ? + declaration.parameters.map(parameters => ( + + )) : + There are no parameters. + } +
}
diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index b0b5f03ba..b81edc223 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -20,6 +20,7 @@ export default class AnnotationStore { } getRenamingFor(declaration: PythonDeclaration): Nullable { + console.log("renamings", this.renamings); return this.renamings.get(declaration.pathAsString()) ?? null; } @@ -43,12 +44,14 @@ export default class AnnotationStore { return new AnnotationStore(this.renamings, this.enums.set(declaration.pathAsString(), parameterEnum)); } - private setRenaming(path: string, newName: string) { - return new AnnotationStore(this.renamings.set(path, newName), this.enums); + private setRenamings(renamings: Map): AnnotationStore { + console.log("renamings setRenamings", renamings); + console.log("enums setRenamings", this.enums); + return new AnnotationStore(renamings, this.enums); } - private setEnum(path: string, pythonEnum: PythonEnum) { - return new AnnotationStore(this.renamings, this.enums.set(path, pythonEnum)); + private setEnums(enums: Map): AnnotationStore { + return new AnnotationStore(this.renamings, enums); } removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { @@ -71,13 +74,11 @@ export default class AnnotationStore { a.click(); } - fromJson(annotations: annotationsJson): void { - annotations.renamings.forEach(((value, key) => { - this.setRenaming(key, value); - })); - annotations.enums.forEach(((value, key) => { - this.setEnum(key, value); - })); + static fromJson(annotations: annotationsJson): AnnotationStore { + console.log("fromJson Annotation Renamings", annotations.renamings); + return new AnnotationStore() + .setRenamings(annotations.renamings) + .setEnums(annotations.enums); } } From f9675dc3e867134413c7d8cb244591589bd54eca Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 15:37:31 +0200 Subject: [PATCH 05/12] fix initial state of annotationStore and delete of enums / renamings --- client/src/Components/App/App.tsx | 5 ++++- client/src/model/annotation/AnnotationStore.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/Components/App/App.tsx b/client/src/Components/App/App.tsx index 5e1a05e16..03d749607 100644 --- a/client/src/Components/App/App.tsx +++ b/client/src/Components/App/App.tsx @@ -11,7 +11,10 @@ import SelectionView from "../SelectionView/SelectionView"; export default function App(): JSX.Element { const [pythonPackage, setPythonPackage] = useState(parsePythonPackageJson(pythonPackageJson as PythonPackageJson)); - const [annotationStore, setAnnotationStore] = useState(new AnnotationStore()); + const initialJSON = JSON.parse('{"renamings":{},"enums":{}}'); + initialJSON["renamings"] = new Map(); + initialJSON["enums"] = new Map(); + const [annotationStore, setAnnotationStore] = useState(AnnotationStore.fromJson(initialJSON)); return ( diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index b81edc223..eff361855 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -55,11 +55,13 @@ export default class AnnotationStore { } removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { - return new AnnotationStore(this.renamings.remove(declaration.pathAsString()), this.enums); + this.renamings.delete(declaration.pathAsString()); + return new AnnotationStore(this.renamings, this.enums); } removeEnumFor(enumDefinition: PythonDeclaration): AnnotationStore { - return new AnnotationStore(this.renamings.remove(enumDefinition.pathAsString()), this.enums); + this.renamings.delete(enumDefinition.pathAsString()); + return new AnnotationStore(this.renamings, this.enums); } toJson(): string { From 5bc7ffc267dbc78f9f4aef7c0797ca79784c1c99 Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 15:38:24 +0200 Subject: [PATCH 06/12] readInputFile --- client/src/Components/Dialog/ImportAnnotationFileDialog.tsx | 1 + client/src/model/annotation/AnnotationStore.tsx | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx index 961e2ddde..79369c7a1 100644 --- a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx +++ b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx @@ -42,6 +42,7 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi props.setAnnotationStore(result); } }; + reader.readAsText(acceptedFiles[0]); } }; diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index eff361855..e1f095f5d 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -3,8 +3,6 @@ import {Nullable} from "../../util/types"; import PythonDeclaration from "../python/PythonDeclaration"; import PythonEnum from "../python/PythonEnum"; -/* TODO: Es fehlen die Enums. */ - interface annotationsJson { renamings: Map, enums: Map From 32a52b398cafc61682acef9b0dfcfdf66ceb501d Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 15:55:08 +0200 Subject: [PATCH 07/12] update onDrop / submit logic, size of annotations text --- .../src/Components/Dialog/ImportAnnotationFileDialog.tsx | 7 +++++-- .../src/Components/SelectionView/RenameAnnotationView.tsx | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx index 79369c7a1..cebe2c2f3 100644 --- a/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx +++ b/client/src/Components/Dialog/ImportAnnotationFileDialog.tsx @@ -16,6 +16,7 @@ interface ImportAnnotationFileDialogProps { export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDialogProps): JSX.Element { const [fileName, setFileName] = useState(""); + const [newAnnotationStore, setNewAnnotationStore] = useState(new AnnotationStore()); const close = () => { props.setIsVisible(false); @@ -23,6 +24,9 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi const submit = (event: FormEvent) => { event.preventDefault(); + if (fileName) { + props.setAnnotationStore(newAnnotationStore); + } props.setIsVisible(false); }; @@ -38,8 +42,7 @@ export default function ImportAnnotationFileDialog(props: ImportAnnotationFileDi const readAnnotationJson = JSON.parse(reader.result); readAnnotationJson["renamings"] = new Map(Object.entries(readAnnotationJson["renamings"])); readAnnotationJson["enums"] = new Map(Object.entries(readAnnotationJson["enums"])); - const result = AnnotationStore.fromJson(readAnnotationJson); - props.setAnnotationStore(result); + setNewAnnotationStore(AnnotationStore.fromJson(readAnnotationJson)); } }; reader.readAsText(acceptedFiles[0]); diff --git a/client/src/Components/SelectionView/RenameAnnotationView.tsx b/client/src/Components/SelectionView/RenameAnnotationView.tsx index d30886e54..5c6724e36 100644 --- a/client/src/Components/SelectionView/RenameAnnotationView.tsx +++ b/client/src/Components/SelectionView/RenameAnnotationView.tsx @@ -15,7 +15,7 @@ const RenameAnnotationView: React.FC = (props) => { if (props.newName !== null) { return (
-

Annotations

+
Annotations
{`@rename: ${props.newName}`} From ee6164c54e446ecae25d3a38ce620f003a88c739 Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 15:55:37 +0200 Subject: [PATCH 08/12] extract method --- .../Dialog/ImportPythonPackageDialog.tsx | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/client/src/Components/Dialog/ImportPythonPackageDialog.tsx b/client/src/Components/Dialog/ImportPythonPackageDialog.tsx index cfaac9330..bc78c74e5 100644 --- a/client/src/Components/Dialog/ImportPythonPackageDialog.tsx +++ b/client/src/Components/Dialog/ImportPythonPackageDialog.tsx @@ -29,17 +29,32 @@ export default function ImportPythonPackageDialog(props: ImportPythonPackageDial if (newPythonPackage) props.setPythonPackage(newPythonPackage); }; + const slurpAndParse = (acceptedFiles: File[]) => { + if (isValidJsonFile(acceptedFiles[acceptedFiles.length - 1].name)) { + if (acceptedFiles.length > 1) { + acceptedFiles = [acceptedFiles[acceptedFiles.length - 1]]; + } + setFileName(acceptedFiles[0].name); + const reader = new FileReader(); + reader.onload = () => { + if (typeof reader.result === 'string') { + setNewPythonPackage(parsePythonPackageJson(JSON.parse(reader.result))); + } + }; + reader.readAsText(acceptedFiles[0]); + } + }; + return ( - + - Import Python package + + Import Python package + - @@ -48,27 +63,16 @@ export default function ImportPythonPackageDialog(props: ImportPythonPackageDial Select a Python package to upload.
- { - if (isValidJsonFile(acceptedFiles[acceptedFiles.length - 1].name)) { - if (acceptedFiles.length > 1) { - acceptedFiles = [acceptedFiles[acceptedFiles.length - 1]]; - } - setFileName(acceptedFiles[0].name); - const reader = new FileReader(); - reader.onload = () => { - if (typeof reader.result === 'string') { - setNewPythonPackage(parsePythonPackageJson(JSON.parse(reader.result))); - } - }; - reader.readAsText(acceptedFiles[0]); - } - }}> + {({getRootProps, getInputProps}) => (
-

Drag and drop a Python package here, or click to select the - file
(only *.json will be accepted)

+

+ Drag and drop a Python package here, or click to select the + file.
+ (Only *.json will be accepted.) +

)} @@ -78,10 +82,13 @@ export default function ImportPythonPackageDialog(props: ImportPythonPackageDial - - From 390fd9b32732902bb83862073bb3b04ad67f6129 Mon Sep 17 00:00:00 2001 From: PaulV Date: Sun, 18 Jul 2021 15:59:23 +0200 Subject: [PATCH 09/12] remove console.logs --- client/src/model/annotation/AnnotationStore.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index e1f095f5d..cd5545fe5 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -18,7 +18,6 @@ export default class AnnotationStore { } getRenamingFor(declaration: PythonDeclaration): Nullable { - console.log("renamings", this.renamings); return this.renamings.get(declaration.pathAsString()) ?? null; } @@ -43,8 +42,6 @@ export default class AnnotationStore { } private setRenamings(renamings: Map): AnnotationStore { - console.log("renamings setRenamings", renamings); - console.log("enums setRenamings", this.enums); return new AnnotationStore(renamings, this.enums); } @@ -75,7 +72,6 @@ export default class AnnotationStore { } static fromJson(annotations: annotationsJson): AnnotationStore { - console.log("fromJson Annotation Renamings", annotations.renamings); return new AnnotationStore() .setRenamings(annotations.renamings) .setEnums(annotations.enums); From 8ef13f89d845f881593b8d4af2fe9c5b861defba Mon Sep 17 00:00:00 2001 From: PaulV Date: Mon, 19 Jul 2021 00:16:28 +0200 Subject: [PATCH 10/12] fix typo --- client/src/model/annotation/AnnotationStore.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index cd5545fe5..67b4d6285 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -55,7 +55,7 @@ export default class AnnotationStore { } removeEnumFor(enumDefinition: PythonDeclaration): AnnotationStore { - this.renamings.delete(enumDefinition.pathAsString()); + this.enums.delete(enumDefinition.pathAsString()); return new AnnotationStore(this.renamings, this.enums); } From 908707de353d48736906741b7da1a7c3185bef6e Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 19 Jul 2021 17:28:13 +0200 Subject: [PATCH 11/12] fix: use immutable data structures in AnnotationStore again and make their usage more obvious --- .../src/model/annotation/AnnotationStore.tsx | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/client/src/model/annotation/AnnotationStore.tsx b/client/src/model/annotation/AnnotationStore.tsx index 67b4d6285..444fd709d 100644 --- a/client/src/model/annotation/AnnotationStore.tsx +++ b/client/src/model/annotation/AnnotationStore.tsx @@ -1,18 +1,24 @@ -import {Map} from "immutable"; +import * as Immutable from "immutable"; import {Nullable} from "../../util/types"; import PythonDeclaration from "../python/PythonDeclaration"; import PythonEnum from "../python/PythonEnum"; interface annotationsJson { + // These are deliberately normal ES6 maps renamings: Map, enums: Map } +export type PythonPath = string +export type PythonName = string +export type RenameAnnotationStore = Immutable.Map +export type EnumAnnotationStore = Immutable.Map + export default class AnnotationStore { private readonly renamings: RenameAnnotationStore; private readonly enums: EnumAnnotationStore; - constructor(renamings: RenameAnnotationStore = Map(), enums: EnumAnnotationStore = Map()) { + constructor(renamings: RenameAnnotationStore = Immutable.Map(), enums: EnumAnnotationStore = Immutable.Map()) { this.renamings = renamings; this.enums = enums; } @@ -25,12 +31,12 @@ export default class AnnotationStore { return this.enums.get(enumDefinition.pathAsString()) ?? null; } - setRenamingFor(declaration: PythonDeclaration, parameterName: Nullable): AnnotationStore { + setRenamingFor(declaration: PythonDeclaration, parameterName: Nullable): AnnotationStore { if (parameterName === null || declaration.name === parameterName) { return this.removeRenamingFor(declaration); } - return new AnnotationStore(this.renamings.set(declaration.pathAsString(), parameterName), this.enums); + return this.setRenamings(this.renamings.set(declaration.pathAsString(), parameterName)); } setEnumFor(declaration: PythonDeclaration, parameterEnum: Nullable): AnnotationStore { @@ -38,25 +44,23 @@ export default class AnnotationStore { return this.removeEnumFor(declaration); } - return new AnnotationStore(this.renamings, this.enums.set(declaration.pathAsString(), parameterEnum)); + return this.setEnums(this.enums.set(declaration.pathAsString(), parameterEnum)); } - private setRenamings(renamings: Map): AnnotationStore { - return new AnnotationStore(renamings, this.enums); + removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { + return this.setRenamings(this.renamings.remove(declaration.pathAsString())); } - private setEnums(enums: Map): AnnotationStore { - return new AnnotationStore(this.renamings, enums); + removeEnumFor(enumDefinition: PythonDeclaration): AnnotationStore { + return this.setEnums(this.enums.remove(enumDefinition.pathAsString())); } - removeRenamingFor(declaration: PythonDeclaration): AnnotationStore { - this.renamings.delete(declaration.pathAsString()); - return new AnnotationStore(this.renamings, this.enums); + private setRenamings(renamings: RenameAnnotationStore): AnnotationStore { + return new AnnotationStore(renamings, this.enums); } - removeEnumFor(enumDefinition: PythonDeclaration): AnnotationStore { - this.enums.delete(enumDefinition.pathAsString()); - return new AnnotationStore(this.renamings, this.enums); + private setEnums(enums: EnumAnnotationStore): AnnotationStore { + return new AnnotationStore(this.renamings, enums); } toJson(): string { @@ -72,11 +76,9 @@ export default class AnnotationStore { } static fromJson(annotations: annotationsJson): AnnotationStore { - return new AnnotationStore() - .setRenamings(annotations.renamings) - .setEnums(annotations.enums); + return new AnnotationStore( + Immutable.Map(annotations.renamings), + Immutable.Map(annotations.enums) + ); } } - -export type RenameAnnotationStore = Map -export type EnumAnnotationStore = Map From bf8d2bede6838ebefe9c3c9e3503f49c7125bda6 Mon Sep 17 00:00:00 2001 From: PaulV Date: Wed, 21 Jul 2021 18:01:36 +0200 Subject: [PATCH 12/12] merge master and fix-styling --- client/src/Components/SelectionView/ParameterNode.tsx | 2 +- client/src/Components/SelectionView/RenameAnnotationView.tsx | 1 - client/src/Components/SelectionView/SelectionView.css | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/src/Components/SelectionView/ParameterNode.tsx b/client/src/Components/SelectionView/ParameterNode.tsx index b55db4284..51fffc94b 100644 --- a/client/src/Components/SelectionView/ParameterNode.tsx +++ b/client/src/Components/SelectionView/ParameterNode.tsx @@ -62,7 +62,7 @@ export default function ParameterNode(props: ParameterNodeProps): JSX.Element {
{(newName || newEnumDefinition) && -

Annotations

+
Annotations
} = (props) => { if (props.newName !== null) { return (
-
Annotations
{`@rename: ${props.newName}`} diff --git a/client/src/Components/SelectionView/SelectionView.css b/client/src/Components/SelectionView/SelectionView.css index 194c6d732..52552e616 100644 --- a/client/src/Components/SelectionView/SelectionView.css +++ b/client/src/Components/SelectionView/SelectionView.css @@ -116,5 +116,5 @@ h1 { .annotation-list { padding-bottom: 20px; - padding-left: 1rem; + padding-left: 2rem; }