-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎉 Add frontend redirect for Cloud API token management (#19488)
* add open api spec & orval config * add page & data fetching logic for speakeasy * typo * update error copy * Missed comma in merge conflict. * commit orval-generated api methods * create hook for calling cloud api endpoint * remove orval config * Address feedback * Change CTA text * Move to speakeasy folder * Use new spearate cloudPublicApiUrl * Change i18n message * Extract types * Revert accidental change Co-authored-by: Bryce Groff <bryce@airbyte.io> Co-authored-by: Bryce Groff <bgroff@hawaii.edu> Co-authored-by: Tim Roes <tim@airbyte.io>
- Loading branch information
1 parent
5fc2a6b
commit 09154f3
Showing
14 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
airbyte-webapp/src/hooks/services/AppMonitoringService/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export type { TrackActionFn, TrackErrorFn } from "./AppMonitoringService"; | ||
|
||
export { AppMonitoringServiceProvider, useAppMonitoringService } from "./AppMonitoringService"; | ||
export { AppActionCodes } from "./actionCodes"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
airbyte-webapp/src/packages/cloud/lib/domain/speakeasy/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { apiOverride } from "core/request/apiOverride"; | ||
|
||
export interface RedirectUrlResponse { | ||
redirectUrl?: string; | ||
} | ||
|
||
// eslint-disable-next-line | ||
type SecondParameter<T extends (...args: any) => any> = T extends (config: any, args: infer P) => any ? P : never; | ||
|
||
/** | ||
* Return a JSON datastructure that contains the URL that should be redirected to in the redirectUrl field. | ||
* @summary Get the Speakeasy Callback URL | ||
*/ | ||
export const getSpeakeasyCallbackUrl = (options?: SecondParameter<typeof apiOverride>, signal?: AbortSignal) => { | ||
return apiOverride<RedirectUrlResponse>({ url: `/speakeasy_callback_url`, method: "get", signal }, options); | ||
}; | ||
|
||
type AwaitedInput<T> = PromiseLike<T> | T; | ||
|
||
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never; | ||
|
||
export type GetSpeakeasyCallbackUrlResult = NonNullable<Awaited<ReturnType<typeof getSpeakeasyCallbackUrl>>>; |
1 change: 1 addition & 0 deletions
1
airbyte-webapp/src/packages/cloud/lib/domain/speakeasy/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./api"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useSpeakeasyRedirect"; |
16 changes: 16 additions & 0 deletions
16
airbyte-webapp/src/packages/cloud/services/speakeasy/useSpeakeasyRedirect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getSpeakeasyCallbackUrl } from "packages/cloud/lib/domain/speakeasy"; | ||
import { useSuspenseQuery } from "services/connector/useSuspenseQuery"; | ||
import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares"; | ||
|
||
import { useConfig } from "../config"; | ||
|
||
const SPEAKEASY_QUERY_KEY = "speakeasy-redirect"; | ||
|
||
export const useSpeakeasyRedirect = () => { | ||
const { cloudPublicApiUrl } = useConfig(); | ||
const config = { apiUrl: cloudPublicApiUrl }; | ||
const middlewares = useDefaultRequestMiddlewares(); | ||
const requestOptions = { config, middlewares }; | ||
|
||
return useSuspenseQuery([SPEAKEASY_QUERY_KEY], () => getSpeakeasyCallbackUrl(requestOptions)); | ||
}; |
71 changes: 71 additions & 0 deletions
71
airbyte-webapp/src/pages/SpeakeasyRedirectPage/SpeakeasyRedirectPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Suspense, useEffect } from "react"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
import { LoadingPage } from "components/LoadingPage"; | ||
|
||
import { useAppMonitoringService, TrackErrorFn } from "hooks/services/AppMonitoringService"; | ||
import { useSpeakeasyRedirect } from "packages/cloud/services/speakeasy"; | ||
import { RoutePaths } from "pages/routePaths"; | ||
import { ErrorOccurredView } from "views/common/ErrorOccurredView"; | ||
|
||
export const SpeakeasyRedirectPage = () => { | ||
const { trackError } = useAppMonitoringService(); | ||
|
||
return ( | ||
<SpeakeasyErrorBoundary trackError={trackError}> | ||
<Suspense fallback={<LoadingPage />}> | ||
<SpeakeasyLoginRedirect /> | ||
</Suspense> | ||
</SpeakeasyErrorBoundary> | ||
); | ||
}; | ||
|
||
const SpeakeasyLoginRedirect = () => { | ||
const { redirectUrl } = useSpeakeasyRedirect(); | ||
|
||
useEffect(() => { | ||
if (redirectUrl) { | ||
window.location.replace(redirectUrl); | ||
} | ||
}, [redirectUrl]); | ||
|
||
return redirectUrl ? <LoadingPage /> : <CloudApiErrorView />; | ||
}; | ||
|
||
const CloudApiErrorView = () => { | ||
const navigate = useNavigate(); | ||
return ( | ||
<ErrorOccurredView | ||
message={<FormattedMessage id="cloudApi.loginCallbackUrlError" />} | ||
ctaButtonText={<FormattedMessage id="ui.goToHome" />} | ||
onCtaButtonClick={() => { | ||
navigate(RoutePaths.Root); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
interface SpeakeasyErrorBoundaryProps { | ||
trackError: TrackErrorFn; | ||
} | ||
|
||
export class SpeakeasyErrorBoundary extends React.Component<React.PropsWithChildren<SpeakeasyErrorBoundaryProps>> { | ||
state = { error: null }; | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
return { error }; | ||
} | ||
|
||
componentDidCatch(error: Error): void { | ||
this.props.trackError(error); | ||
} | ||
|
||
render() { | ||
if (this.state.error) { | ||
return <CloudApiErrorView />; | ||
} | ||
return this.props.children; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SpeakeasyRedirectPage } from "./SpeakeasyRedirectPage"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters