From a90aff601da114eeb3b2764f420a308d683e9013 Mon Sep 17 00:00:00 2001 From: Alexey Safronov Date: Thu, 25 Jul 2024 16:44:40 +0400 Subject: [PATCH] Fix Bug 69398 - Files.Editor. There is no transition from viewing mode to editing mode in the editor using the Edit current file button. --- packages/doceditor/src/utils/events.ts | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/doceditor/src/utils/events.ts b/packages/doceditor/src/utils/events.ts index 5ec6d17acb..45ec4597e2 100644 --- a/packages/doceditor/src/utils/events.ts +++ b/packages/doceditor/src/utils/events.ts @@ -81,30 +81,31 @@ export const onSDKRequestEditRights = async ( const url = window.location.href; const isPDF = documentType === "pdf"; - if (isPDF) { - const newURL = new URL(url); + let newURL = new URL(url); - if (newURL.searchParams.has("action")) { - newURL.searchParams.delete("action"); + if ( + !isPDF && + fileInfo?.viewAccessibility?.MustConvert && + fileInfo?.security?.Convert + ) { + try { + const response = await convertDocumentUrl(fileInfo.id); + if (response && response.webUrl) { + newURL = new URL(response.webUrl); + } else { + throw new Error("Invalid response data"); + } + } catch (error) { + console.error("Error converting document", { error }); + return; } + } else { + if (newURL.searchParams.has("action")) newURL.searchParams.delete("action"); newURL.searchParams.append("action", "edit"); - - history.pushState({}, "", newURL.toString()); - document.location.reload(); - - return; } - let convertUrl = url; - - if (fileInfo?.viewAccessibility?.MustConvert && fileInfo?.security?.Convert) { - const newUrl = await convertDocumentUrl(fileInfo.id); - if (newUrl) { - convertUrl = newUrl.webUrl; - } - } - history.pushState({}, "", convertUrl); + history.pushState({}, "", newURL.toString()); document.location.reload(); };