-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* CB-4707 move connection shield logic to separate component * CB-4707 use lazy import * CB-4707 revert interface --------- Co-authored-by: mr-anton-t <[email protected]>
- Loading branch information
1 parent
e9163b8
commit affbe44
Showing
6 changed files
with
103 additions
and
99 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
60 changes: 60 additions & 0 deletions
60
webapp/packages/plugin-connections/src/ConnectionShield.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,60 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { observer } from 'mobx-react-lite'; | ||
import { type PropsWithChildren, useState } from 'react'; | ||
|
||
import { Button, Loader, TextPlaceholder, useResource, useTranslate } from '@cloudbeaver/core-blocks'; | ||
import { ConnectionInfoResource, ConnectionsManagerService, type IConnectionInfoParams } from '@cloudbeaver/core-connections'; | ||
import { useService } from '@cloudbeaver/core-di'; | ||
import { NotificationService } from '@cloudbeaver/core-events'; | ||
|
||
export interface IConnectionShieldProps { | ||
connectionKey: IConnectionInfoParams | null; | ||
} | ||
|
||
export const ConnectionShield = observer<PropsWithChildren<IConnectionShieldProps>>(function ConnectionShield({ connectionKey, children }) { | ||
const translate = useTranslate(); | ||
const connectionsManagerService = useService(ConnectionsManagerService); | ||
const notificationService = useService(NotificationService); | ||
|
||
const connection = useResource(ConnectionShield, ConnectionInfoResource, connectionKey); | ||
|
||
const [connecting, setConnecting] = useState(false); | ||
|
||
async function handleConnect() { | ||
if (connecting || !connection.data || !connectionKey) { | ||
return; | ||
} | ||
|
||
setConnecting(true); | ||
|
||
try { | ||
await connectionsManagerService.requireConnection(connectionKey); | ||
} catch (exception: any) { | ||
notificationService.logException(exception); | ||
} finally { | ||
setConnecting(false); | ||
} | ||
} | ||
|
||
if (connection.data && !connection.data.connected) { | ||
if (connecting || connection.isLoading()) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<TextPlaceholder> | ||
<Button type="button" mod={['unelevated']} onClick={handleConnect}> | ||
{translate('connections_connection_connect')} | ||
</Button> | ||
</TextPlaceholder> | ||
); | ||
} | ||
|
||
return children; | ||
}); |
10 changes: 10 additions & 0 deletions
10
webapp/packages/plugin-connections/src/ConnectionShieldLazy.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,10 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { importLazyComponent } from '@cloudbeaver/core-blocks'; | ||
|
||
export const ConnectionShieldLazy = importLazyComponent(() => import('./ConnectionShield').then(m => m.ConnectionShield)); |
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