From febba3608960b741a1576c6c685836ec1dd7071d Mon Sep 17 00:00:00 2001 From: Kbowers <92726146+kbowers-ibm@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:30:18 +0200 Subject: [PATCH] kie-issues#129: chrome-extension: Open in KIE Sandbox button doesn't work in a private repository (#1665) Co-authored-by: Kennedy Bowers --- .../importFromUrl/NewWorkspaceFromUrlPage.tsx | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/online-editor/src/importFromUrl/NewWorkspaceFromUrlPage.tsx b/packages/online-editor/src/importFromUrl/NewWorkspaceFromUrlPage.tsx index 9ffce2b9590..25cb620ed62 100644 --- a/packages/online-editor/src/importFromUrl/NewWorkspaceFromUrlPage.tsx +++ b/packages/online-editor/src/importFromUrl/NewWorkspaceFromUrlPage.tsx @@ -20,16 +20,16 @@ import { Spinner } from "@patternfly/react-core/dist/js/components/Spinner"; import { Text, TextContent, TextVariants } from "@patternfly/react-core/dist/js/components/Text"; import { Bullseye } from "@patternfly/react-core/dist/js/layouts/Bullseye"; import { basename } from "path"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { useHistory } from "react-router"; import { EditorPageErrorPage } from "../editor/EditorPageErrorPage"; import { useRoutes } from "../navigation/Hooks"; import { QueryParams } from "../navigation/Routes"; import { OnlineEditorPage } from "../pageTemplate/OnlineEditorPage"; import { useQueryParam, useQueryParams } from "../queryParams/QueryParamsContext"; -import { useSettingsDispatch } from "../settings/SettingsContext"; import { ImportableUrl, + isCertainlyGit, isPotentiallyGit, isSingleFile, UrlType, @@ -42,7 +42,7 @@ import { fetchSingleFileContent } from "./fetchSingleFileContent"; import { useGitHubClient } from "../github/Hooks"; import { AccountsDispatchActionKind, useAccountsDispatch } from "../accounts/AccountsContext"; import { useAuthSession, useAuthSessions } from "../authSessions/AuthSessionsContext"; -import { useAuthProvider, useAuthProviders } from "../authProviders/AuthProvidersContext"; +import { useAuthProviders } from "../authProviders/AuthProvidersContext"; import { getCompatibleAuthSessionWithUrlDomain } from "../authSessions/CompatibleAuthSessions"; import { useWorkspaces } from "@kie-tools-core/workspaces-git-fs/dist/context/WorkspacesContext"; import { LocalFile } from "@kie-tools-core/workspaces-git-fs/dist/worker/api/LocalFile"; @@ -59,9 +59,7 @@ export function NewWorkspaceFromUrlPage() { const accountsDispatch = useAccountsDispatch(); const [importingError, setImportingError] = useState(""); - const queryParams = useQueryParams(); - const queryParamUrl = useQueryParam(QueryParams.URL); const queryParamBranch = useQueryParam(QueryParams.BRANCH); const queryParamAuthSessionId = useQueryParam(QueryParams.AUTH_SESSION_ID); @@ -142,35 +140,40 @@ export function NewWorkspaceFromUrlPage() { // Startup the page. Only import if those are set. useEffect(() => { - if (!selectedGitRefName || !queryParamUrl) { - return; - } - + const urlDomain = importableUrl.url?.hostname; const { compatible } = getCompatibleAuthSessionWithUrlDomain({ authProviders, authSessions, authSessionStatus, - urlDomain: new URL(queryParamUrl).hostname, + urlDomain, }); + setAuthSessionId(compatible[0].id); - history.replace({ - pathname: routes.import.path({}), - search: queryParams - .with(QueryParams.BRANCH, selectedGitRefName) - .with(QueryParams.AUTH_SESSION_ID, authSession?.id ?? compatible[0].id) - .toString(), - }); + if (compatible[0].id === AUTH_SESSION_NONE.id && !selectedGitRefName) { + history.replace({ + pathname: routes.import.path({}), + search: queryParams.with(QueryParams.CONFIRM, "true").toString(), + }); + } else { + history.replace({ + pathname: routes.import.path({}), + search: queryParams + .without(QueryParams.CONFIRM) + .with(QueryParams.BRANCH, selectedGitRefName) + .with(QueryParams.AUTH_SESSION_ID, compatible[0].id) + .toString(), + }); + } }, [ authProviders, - authSession?.id, authSessionStatus, authSessions, history, - queryParamUrl, + importableUrl.url?.hostname, queryParams, routes.import, selectedGitRefName, - setGitRefName, + setAuthSessionId, ]); const cloneGitRepository: typeof workspaces.createWorkspaceFromGitRepository = useCallback( @@ -251,6 +254,10 @@ export function NewWorkspaceFromUrlPage() { return; } + if (!queryParamBranch && isCertainlyGit(importableUrl.type) && queryParamAuthSessionId !== AUTH_SESSION_NONE.id) { + return; + } + if (clonableUrl.type === UrlType.INVALID || clonableUrl.type === UrlType.NOT_SUPPORTED) { setImportingError(clonableUrl.error); return; @@ -387,7 +394,6 @@ export function NewWorkspaceFromUrlPage() { advancedImportModalRef.current?.open(); return; } - setImportingError(""); doImport(); }, [