From e3d2679d3454726370b69801d7d5f2f9cca9c794 Mon Sep 17 00:00:00 2001 From: Ezequiel-Vega Date: Tue, 5 Apr 2022 13:19:11 -0300 Subject: [PATCH] Added verify that it is a valid freemind map --- .../src/components/export/freemind/Map.ts | 9 +- .../input/SQLServerTip-version-0.8.0.mm | 20 ++++ .../input/anonymity_on_the_edge-invalid.mm | 112 ++++++++++++++++++ .../test/unit/import/input/bug2-invalid.mm | 49 ++++++++ .../action-dispatcher/import-dialog/index.tsx | 31 +++-- 5 files changed, 208 insertions(+), 13 deletions(-) create mode 100644 packages/mindplot/test/unit/import/input/SQLServerTip-version-0.8.0.mm create mode 100644 packages/mindplot/test/unit/import/input/anonymity_on_the_edge-invalid.mm create mode 100644 packages/mindplot/test/unit/import/input/bug2-invalid.mm diff --git a/packages/mindplot/src/components/export/freemind/Map.ts b/packages/mindplot/src/components/export/freemind/Map.ts index f336212f..a64a0be0 100644 --- a/packages/mindplot/src/components/export/freemind/Map.ts +++ b/packages/mindplot/src/components/export/freemind/Map.ts @@ -60,7 +60,14 @@ export default class Freemap { // Is a freemap? $assert( rootElem.tagName === 'map', - `This seem not to be a map document. Found tag: ${rootElem.tagName}`, + `This seem not to be a map document. Found first tag: ${rootElem.tagName}`, + ); + + // Verify that the version attribute exists + console.log(rootElem.getAttribute('version')); + $assert( + rootElem.getAttribute('version') !== null, + 'Freemind version not found', ); // Start the loading process... diff --git a/packages/mindplot/test/unit/import/input/SQLServerTip-version-0.8.0.mm b/packages/mindplot/test/unit/import/input/SQLServerTip-version-0.8.0.mm new file mode 100644 index 00000000..4ca29e7a --- /dev/null +++ b/packages/mindplot/test/unit/import/input/SQLServerTip-version-0.8.0.mm @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/input/anonymity_on_the_edge-invalid.mm b/packages/mindplot/test/unit/import/input/anonymity_on_the_edge-invalid.mm new file mode 100644 index 00000000..0efb25b0 --- /dev/null +++ b/packages/mindplot/test/unit/import/input/anonymity_on_the_edge-invalid.mm @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/mindplot/test/unit/import/input/bug2-invalid.mm b/packages/mindplot/test/unit/import/input/bug2-invalid.mm new file mode 100644 index 00000000..13f03161 --- /dev/null +++ b/packages/mindplot/test/unit/import/input/bug2-invalid.mm @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Todos los contenidos de los talleres están relacionados con el currículo de la enseñanza básica.

+

A diferencia de la práctica tradicional, pretendemos ahondar en el conocimiento partiendo de lo que realmente interesa al niño o niña,

+

ayudándole a que encuentre respuesta a las preguntas que él o ella se plantea.

+

+

Por ese motivo, SaberMás proyecta estar al lado de los niños que necesitan una motivación extra para entender la escuela y fluir en ella,

+

y también al lado de aquellos a quienes la curiosidad y las ganas de saber les lleva más allá.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx index bbebc9d3..1efad759 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx @@ -23,12 +23,17 @@ export type CreateProps = { onClose: () => void; }; +type ErrorFile = { + error: boolean; + message: string; +} + const defaultModel: ImportModel = { title: '' }; const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => { const client: Client = useSelector(activeInstance); const [model, setModel] = React.useState(defaultModel); const [error, setError] = React.useState(); - const [errorFile, setErrorFile] = React.useState(false); + const [errorFile, setErrorFile] = React.useState({error: false, message: ''}); const intl = useIntl(); const mutation = useMutation( @@ -85,7 +90,13 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => { const extensionAccept = ['wxml', 'mm']; if (!extensionAccept.includes(extensionFile)) { - setErrorFile(true); + setErrorFile({ + error: true, + message: intl.formatMessage({ + id: 'import.error-file', + defaultMessage: 'You can import WiseMapping and Freemind maps to your list of maps. Select the file you want to import.' + }) + }); } model.contentType = 'application/xml' @@ -101,13 +112,12 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => { model.content = res; setModel({ ...model }); }) - .catch(e => { - console.log(e); - setErrorFile(true) - }); } catch (e) { if (e instanceof Error) { - setErrorFile(true); + setErrorFile({ + error: true, + message: e.message + }); } } }; @@ -134,12 +144,9 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => { })} submitButton={intl.formatMessage({ id: 'import.button', defaultMessage: 'Create' })} > - {errorFile && + {errorFile.error && - +

{errorFile.message}

}