Skip to content

Commit

Permalink
Ehnance control oauth (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcloudquery authored Nov 26, 2024
1 parent f2d09eb commit 6e893b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion etc/plugin-config-ui-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ export interface ControlNumberFieldProps {
}

// @public
export function ControlOAuthField({ getConnectPayloadSpec, getFinishPayloadSpec, }: ControlOAuthFieldProps): JSX_2.Element;
export function ControlOAuthField({ shouldAuthenticate, getConnectPayloadSpec, getFinishPayloadSpec, }: ControlOAuthFieldProps): JSX_2.Element;

// @public (undocumented)
export type ControlOAuthFieldProps = {
shouldAuthenticate?: () => Promise<boolean>;
getConnectPayloadSpec?: (formValues: any) => Promise<Record<string, any>>;
getFinishPayloadSpec?: (formValues: any) => Promise<Record<string, any>>;
};
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cloudquery/plugin-config-ui-lib",
"description": "Plugin configuration UI library for CloudQuery Cloud App",
"version": "4.2.2",
"version": "4.2.3",
"private": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand All @@ -21,6 +21,7 @@
"require": "./dist/components/devWrapper.cjs.js"
},
"./e2e-utils": {
"types": "./dist/e2e-utils/index.d.ts",
"import": "./dist/e2e-utils/index.esm.js",
"require": "./dist/e2e-utils/index.cjs.js"
},
Expand Down
16 changes: 14 additions & 2 deletions src/components/form/controls/controlOAuthField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { cloudQueryOauthConnectorUrl } from '../../../utils';
* @public
*/
export type ControlOAuthFieldProps = {
shouldAuthenticate?: () => Promise<boolean>;
getConnectPayloadSpec?: (formValues: any) => Promise<Record<string, any>>;
getFinishPayloadSpec?: (formValues: any) => Promise<Record<string, any>>;
};
Expand All @@ -30,6 +31,7 @@ export type ControlOAuthFieldProps = {
* @public
*/
export function ControlOAuthField({
shouldAuthenticate,
getConnectPayloadSpec,
getFinishPayloadSpec,
}: ControlOAuthFieldProps) {
Expand All @@ -55,6 +57,16 @@ export function ControlOAuthField({
getFinishPayloadSpec: async () => await getFinishPayloadSpec?.(getValues()),
});

const handleAuthenticate = async () => {
let proceed = true;
if (shouldAuthenticate) {
proceed = await shouldAuthenticate();
}
if (proceed) {
authenticate();
}
};

useEffect(() => {
if (authConnectorResult && connectorId) {
setValue('connectorId', connectorId);
Expand Down Expand Up @@ -86,7 +98,7 @@ export function ControlOAuthField({
<LoadingButton
size="large"
variant="contained"
onClick={authenticate}
onClick={handleAuthenticate}
loading={isLoading}
fullWidth={false}
disabled={!!connectorIdValue}
Expand All @@ -106,7 +118,7 @@ export function ControlOAuthField({
<Typography variant="body2" color="textSecondary">
To reconnect CloudQuery via {config.label}{' '}
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link underline="always" sx={{ cursor: 'pointer' }} onClick={authenticate}>
<Link underline="always" sx={{ cursor: 'pointer' }} onClick={handleAuthenticate}>
click here
</Link>
</Typography>
Expand Down

0 comments on commit 6e893b6

Please sign in to comment.