Skip to content

Commit

Permalink
kie-issues#129: chrome-extension: Open in KIE Sandbox button doesn't …
Browse files Browse the repository at this point in the history
…work in a private repository (apache#1665)

Co-authored-by: Kennedy Bowers <kennedy.bowers@ibm.com>
  • Loading branch information
kbowers-ibm and kbowers-ibm authored Jun 9, 2023
1 parent fe3e30f commit febba36
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -387,7 +394,6 @@ export function NewWorkspaceFromUrlPage() {
advancedImportModalRef.current?.open();
return;
}

setImportingError("");
doImport();
}, [
Expand Down

0 comments on commit febba36

Please sign in to comment.