From 91b5d0123e343bd6af66fa005f4c566282dcf6a7 Mon Sep 17 00:00:00 2001 From: Baptiste Poulain <64689165+bpoulaindev@users.noreply.github.com> Date: Wed, 22 May 2024 15:23:12 +0200 Subject: [PATCH] Feat/UI feedback : Visual + console feedback for failed postman translated imports (#2316) * feat(translation-feedback): console log incomplete postman import translations with stats and details * feat(translation-feedback): warn instead of log, reformat layout * feat(translation-feedback): optional callback function, update index.spec.js * feat(ui-feedback): display translation errors in the UI before choosing import location * feat(ui-feedback): syntax fix --------- Co-authored-by: bpoulaindev --- .../Sidebar/ImportCollectionLocation/index.js | 108 +++++++++++++++++- .../src/components/Sidebar/TitleBar/index.js | 5 +- .../bruno-app/src/components/Welcome/index.js | 5 +- .../src/utils/importers/postman-collection.js | 56 ++++++++- .../translators/postman_translation.js | 9 +- 5 files changed, 168 insertions(+), 15 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js index 62a02bdd5..96fade0db 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js @@ -1,11 +1,110 @@ -import React, { useRef, useEffect } from 'react'; +import React, { useRef, useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import { useFormik } from 'formik'; import * as Yup from 'yup'; import { browseDirectory } from 'providers/ReduxStore/slices/collections/actions'; import Modal from 'components/Modal'; +import { IconAlertTriangle, IconArrowRight, IconCaretDown, IconCaretRight, IconCopy } from '@tabler/icons'; +import toast from 'react-hot-toast'; -const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName }) => { +const TranslationLog = ({ translationLog }) => { + const [showDetails, setShowDetails] = useState(false); + const preventSetShowDetails = (e) => { + e.stopPropagation(); + e.preventDefault(); + setShowDetails(!showDetails); + }; + const copyClipboard = (e, value) => { + e.stopPropagation(); + e.preventDefault(); + navigator.clipboard.writeText(value); + toast.success('Copied to clipboard'); + }; + return ( +
+
+
+
+
+
+

+ Warning: Some commands were not translated.{' '} +

+
+
+
+ + {showDetails && ( +
+ + Impacted Collections: {Object.keys(translationLog || {}).length} + + + Impacted Lines:{' '} + {Object.values(translationLog || {}).reduce( + (acc, curr) => acc + (curr.script?.length || 0) + (curr.test?.length || 0), + 0 + )} + + + The numbers after 'script' and 'test' indicate the line numbers of incomplete translations. + +
    + {Object.entries(translationLog || {}).map(([name, value]) => ( +
  • +
    + + {name} +
    +
    + {value.script && ( +
    + + test : + {value.script.map((scriptValue, index) => ( + + {scriptValue} + {index < value.script.length - 1 && <> - } + + ))} + +
    + )} + {value.test && ( +
    + test : + {value.test.map((testValue, index) => ( +
    + {testValue} + {index < value.test.length - 1 && <> - } +
    + ))} +
    + )} +
    +
  • + ))} +
+ +
+ )} +
+ ); +}; + +const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName, translationLog }) => { const inputRef = useRef(); const dispatch = useDispatch(); @@ -24,7 +123,6 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName }) => handleSubmit(values.collectionLocation); } }); - const browse = () => { dispatch(browseDirectory()) .then((dirPath) => { @@ -52,7 +150,9 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName }) => Name
{collectionName}
- + {translationLog && Object.keys(translationLog).length > 0 && ( + + )} <>