From fedce680bdd040d371361598d638ea88308f7477 Mon Sep 17 00:00:00 2001 From: kolnogorov Date: Sun, 28 Jul 2024 14:39:27 +0300 Subject: [PATCH 1/3] JDOC-794 Fix OpenAPI code copying to the JSight panel after sharing --- src/components/Editor/index.tsx | 4 +++- src/components/MainContent/index.tsx | 1 + src/components/ShareButton/index.tsx | 17 ++++++++++++----- src/hooks/useSharing.ts | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/Editor/index.tsx b/src/components/Editor/index.tsx index 8e866dc..732f3fb 100644 --- a/src/components/Editor/index.tsx +++ b/src/components/Editor/index.tsx @@ -29,6 +29,7 @@ interface EditorProps { setError?: React.Dispatch>; readOnly?: boolean; currentTheme?: string; + jsightEditorId?: string; } function initializeEditor( @@ -67,6 +68,7 @@ export const Editor = React.memo( reload, reloadedEditor, readOnly = false, + jsightEditorId = 'jsightEditor', }: EditorProps) => { const {key, version, history} = useContext(SharingContext); const ref = useRef(null); @@ -78,7 +80,7 @@ export const Editor = React.memo( const currentLanguage = 'jsight'; // @ts-ignore - window['jsightEditor'] = jsightEditor; + window[jsightEditorId] = jsightEditor; const languages: monaco.languages.ILanguageExtensionPoint[] = languagesList.map((id) => ({ id, diff --git a/src/components/MainContent/index.tsx b/src/components/MainContent/index.tsx index 3848037..466ee78 100644 --- a/src/components/MainContent/index.tsx +++ b/src/components/MainContent/index.tsx @@ -416,6 +416,7 @@ export const MainContent = React.memo((props: MainContentProps) => { = ({openSharingModal, disab const {key, version} = useContext(SharingContext); const isAbleUpdate = useMemo(() => key && version, [key, version]); - const handleNewState = async (updateOrCreateState: () => void) => { + const handleCreateState = async () => { try { - await updateOrCreateState(); + await createState(); + openSharingModal(); + } catch (err) {} + }; + + const handleUpdateState = async () => { + try { + await updateExistState(); openSharingModal(); } catch (err) {} }; @@ -37,7 +44,7 @@ export const ShareButton: React.FC = ({openSharingModal, disab -
handleNewState(updateExistState)}> +
@@ -47,7 +54,7 @@ export const ShareButton: React.FC = ({openSharingModal, disab

-
handleNewState(createState)}> +
@@ -64,7 +71,7 @@ export const ShareButton: React.FC = ({openSharingModal, disab disabled={disableSharing || !process.env.REACT_APP_CLOUD_URL} icon="link" className="save-by-link-btn" - onClick={() => handleNewState(createState)} + onClick={handleCreateState} > Share diff --git a/src/hooks/useSharing.ts b/src/hooks/useSharing.ts index fbf9f31..57a4154 100644 --- a/src/hooks/useSharing.ts +++ b/src/hooks/useSharing.ts @@ -30,7 +30,7 @@ export function useSharing() { ? (window as any).jsightEditor : null; - const createState = () => { + const createState = async () => { const content = jsightEditor.current?.getValue(); if (content !== undefined) { @@ -47,7 +47,7 @@ export function useSharing() { } }; - const updateExistState = () => { + const updateExistState = async () => { const content = jsightEditor.current?.getValue(); if (content !== undefined) { From 37ac493bd9cb1f876082e7d9027357761b45a733 Mon Sep 17 00:00:00 2001 From: kolnogorov Date: Mon, 29 Jul 2024 14:40:00 +0300 Subject: [PATCH 2/3] JDOC-794 Openapi window update after sharing fix --- src/components/Editor/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Editor/index.tsx b/src/components/Editor/index.tsx index 732f3fb..3803127 100644 --- a/src/components/Editor/index.tsx +++ b/src/components/Editor/index.tsx @@ -75,6 +75,7 @@ export const Editor = React.memo( const jsightEditor = useRef(null); const decorationsRef = useRef([]); const [isEditorLoaded, setIsEditorLoaded] = useState(false); + const [isContentRendered, setIsContentRendered] = useState(false); const dontUpdateSharingBtn = useRef(false); const languagesList = ['jsight', 'jschema', 'markdown']; const currentLanguage = 'jsight'; @@ -212,6 +213,8 @@ export const Editor = React.memo( useEffect(() => { if (isEditorLoaded) { if (key) { + // if (isContentRendered && readOnly) return; + dontUpdateSharingBtn.current = true; (async () => { try { @@ -225,6 +228,7 @@ export const Editor = React.memo( history.push(`/r/${result.code}/${result.version}`); } highlightError(); + setIsContentRendered(true); } catch (error) { if (error.Code) { setError && From 2a73d64d6e8d6b970b4c632faa96ad45ee6ed612 Mon Sep 17 00:00:00 2001 From: kolnogorov Date: Thu, 1 Aug 2024 11:58:49 +0400 Subject: [PATCH 3/3] JDOC-794 Partial openapi window after sharing fix --- src/components/MainContent/index.tsx | 5 ++++- src/hooks/useSharing.ts | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/MainContent/index.tsx b/src/components/MainContent/index.tsx index 466ee78..d2b72f0 100644 --- a/src/components/MainContent/index.tsx +++ b/src/components/MainContent/index.tsx @@ -408,10 +408,13 @@ export const MainContent = React.memo((props: MainContentProps) => { (currentDocSidebar === 'htmldoc' && isJdocLoading), }); + /* TODO: This is workaround. Refactor to avoid openapi compatibility check */ + const isValidOpenApiContent = openApiContent.substr(0, 7) === 'openapi'; + return (
- {currentDocSidebar === 'openapi' && viewMode !== 'doc' && ( + {currentDocSidebar === 'openapi' && viewMode !== 'doc' && isValidOpenApiContent && (
+ `/r/${response.code}/${response.version}${path ? `#${path}` : ''}`; + const createState = async () => { const content = jsightEditor.current?.getValue(); if (content !== undefined) { return createNewState(content) .then((response) => { - history.push(`/r/${response.code}/${response.version}${path ? `#${path}` : ''}`); + const url = getUrl(response); + console.log(url); + window.history.pushState({}, document.title, url); }) .catch(() => { toast.warning(SharingErrorNotification, errorOptions); @@ -53,7 +58,8 @@ export function useSharing() { if (content !== undefined) { return updateState(key, content) .then((response) => { - history.push(`/r/${response.code}/${response.version}${path ? `#${path}` : ''}`); + const url = getUrl(response); + window.history.pushState({}, document.title, url); }) .catch(() => { toast.warning(SharingErrorNotification, errorOptions);