Kusuma04-dev commented on code in PR #3119:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3119#discussion_r2078258036


##########
packages/online-editor/src/editor/Toolbar/Accelerators/AcceleratorModal.tsx:
##########
@@ -26,18 +26,84 @@ import { Modal, ModalVariant } from 
"@patternfly/react-core/dist/js/components/M
 import { Button } from "@patternfly/react-core/dist/js/components/Button";
 import { AcceleratorIcon } from "./AcceleratorIcon";
 import { Divider } from "@patternfly/react-core/dist/js/components/Divider";
+import { AuthSession, AuthSessionStatus, GitAuthSession, isGitAuthSession } 
from "../../../authSessions/AuthSessionApi";
+import { Alert } from "@patternfly/react-core/dist/js/components/Alert";
+import {
+  getCompatibleAuthSessionWithUrlDomain,
+  gitAuthSessionSelectFilter,
+  isAuthSessionCompatibleWithUrlDomain,
+} from "../../../authSessions/CompatibleAuthSessions";
+import { AuthProvider } from "../../../authProviders/AuthProvidersApi";
+import { AuthSessionSelect } from "../../../authSessions/AuthSessionSelect";
 
 type Props = {
   accelerator: AcceleratorAppliedConfig;
   isOpen: boolean;
-  onClose: () => any;
+  onClose: () => void;
   isApplying?: boolean;
-  onApplyAccelerator?: () => void;
+  onApplyAccelerator?: (authSessionId?: string) => void;
+  authProviders: AuthProvider[];
+  authSessions: Map<string, AuthSession>;
+  authSessionStatus: Map<string, AuthSessionStatus>;
 };
 
+function getDomainFromUrl(url: string | undefined): string | undefined {
+  if (!url) return undefined;
+  try {
+    return new URL(url).hostname;
+  } catch {
+    return undefined;
+  }
+}
+
 export function AcceleratorModal(props: Props) {
   const { i18n } = useOnlineI18n();
 
+  const urlDomain = useMemo(
+    () => getDomainFromUrl(props.accelerator.gitRepositoryUrl),
+    [props.accelerator.gitRepositoryUrl]
+  );
+
+  const [selectedAuthSessionId, setSelectedAuthSessionId] = useState<string | 
undefined>(undefined);
+
+  useEffect(() => {
+    const { compatible } = getCompatibleAuthSessionWithUrlDomain({
+      authProviders: props.authProviders,
+      authSessions: props.authSessions,
+      authSessionStatus: props.authSessionStatus,
+      urlDomain,
+    });
+
+    setSelectedAuthSessionId(compatible.length > 0 ? compatible[0].id : "");
+  }, [props.authProviders, props.authSessions, props.authSessionStatus, 
urlDomain]);
+
+  const selectedAuthSession = useMemo(() => {
+    return selectedAuthSessionId ? 
props.authSessions.get(selectedAuthSessionId) : undefined;
+  }, [selectedAuthSessionId, props.authSessions]);
+
+  const selectedAuthProvider = useMemo(() => {
+    if (selectedAuthSession && isGitAuthSession(selectedAuthSession)) {
+      return props.authProviders.find((p) => p.id === 
selectedAuthSession.authProviderId);
+    }
+    return undefined;
+  }, [selectedAuthSession, props.authProviders]);
+
+  const selectedStatus = useMemo(() => {
+    return selectedAuthSession ? 
props.authSessionStatus.get(selectedAuthSession.id) : undefined;
+  }, [selectedAuthSession, props.authSessionStatus]);

Review Comment:
   Yeah I found functions to fetch authsession and authprovider details and 
updated the same. Thanks for noticing Tiago.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to