Skip to content

Commit

Permalink
Refresh connection data on add/delete and improve loading spinner sta…
Browse files Browse the repository at this point in the history
…tes. (#252)

* Improve data refetching on connection add/delete

* Standardize loading spinner across the app

* Prevent double call on delete and correctly show spinner

* Disable destination id field

---------

Co-authored-by: Rodrigo Arze Leon <[email protected]>
  • Loading branch information
Rodri77 and Rodrigo Arze Leon authored Feb 6, 2025
1 parent 5011017 commit 8f87438
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export function ConnectorConfigForm({
links: zRaw.connector_config.shape.defaultPipeOut
.unwrap()
.unwrap().shape.links,
destination_id: zConnId.optional().openapi({
description: 'Defaults to the org-wide postgres',
}),
// destination_id: zConnId.optional().openapi({
// description: 'Defaults to the org-wide postgres',
// }),
})
.openapi({title: 'Enabled'}),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function AddConnectionTabContent({
} else if (event.type === 'success') {
onSuccessCallback?.()
refetch()
} else if (event.type === 'error') {
refetch()
}
}}
/>
Expand Down
13 changes: 6 additions & 7 deletions packages/engine-frontend/components/ConnectionPortal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import {Loader} from 'lucide-react'
import {Loader2} from 'lucide-react'
import {useTheme} from 'next-themes'
import {usePathname, useRouter, useSearchParams} from 'next/navigation'
import {useEffect} from 'react'
Expand Down Expand Up @@ -33,7 +33,7 @@ const getBaseView = (
export function LoadingSpinner() {
return (
<div className="flex h-full min-h-[600px] flex-1 items-center justify-center">
<Loader className="size-7 animate-spin text-button" />
<Loader2 className="size-7 animate-spin text-button" />
</div>
)
}
Expand Down Expand Up @@ -125,10 +125,7 @@ export function ConnectionPortal({className}: ConnectionPortalProps) {
const connectionCount = connections.length

const isLoading =
listConnectionsRes.isLoading ||
listConnectionsRes.isFetching ||
listConnectionsRes.isRefetching ||
deleteConnection.isLoading
listConnectionsRes.isLoading || listConnectionsRes.isFetching

const baseView = getBaseView(searchParams?.get('view'))

Expand All @@ -142,6 +139,7 @@ export function ConnectionPortal({className}: ConnectionPortalProps) {
<ConnectionsTabContent
connectionCount={connectionCount}
deleteConnection={deleteConnection.mutate}
isDeleting={deleteConnection.isLoading}
connections={connections}
onConnect={() => navigateToTab('add')}
refetch={() => ctx.listConnections.invalidate()}
Expand All @@ -158,8 +156,9 @@ export function ConnectionPortal({className}: ConnectionPortalProps) {
<AddConnectionTabContent
connectorConfigFilters={{}}
refetch={listConnectionsRes.refetch}
onSuccessCallback={() => {
onSuccessCallback={async () => {
navigateToTab('manage')
await listConnectionsRes.refetch()
}}
/>
),
Expand Down
3 changes: 3 additions & 0 deletions packages/engine-frontend/components/ConnectionsTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface Connection {
interface ConnectionsTabContentProps {
connectionCount: number
deleteConnection: ({id}: {id: string}) => void
isDeleting: boolean
onConnect: () => void
refetch: () => void
connections: Connection[]
Expand All @@ -31,6 +32,7 @@ export function ConnectionsTabContent({
connectionCount,
deleteConnection,
connections,
isDeleting,
onConnect,
refetch,
}: ConnectionsTabContentProps) {
Expand Down Expand Up @@ -78,6 +80,7 @@ export function ConnectionsTabContent({
connection={selectedConnection}
deleteConnection={deleteConnection}
onClose={() => setSelectedConnection(null)}
isDeleting={isDeleting}
/>
) : (
<div className="flex flex-row flex-wrap gap-4 p-4 lg:w-[70%]">
Expand Down
4 changes: 2 additions & 2 deletions packages/engine-frontend/components/IntegrationSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import {Loader, Search} from 'lucide-react'
import {Loader2, Search} from 'lucide-react'
import {useSearchParams} from 'next/navigation'
import {useCallback, useEffect, useState} from 'react'
import type {Id} from '@openint/cdk'
Expand Down Expand Up @@ -168,7 +168,7 @@ export function IntegrationSearch({
<div className="relative flex-1 overflow-y-auto">
{listIntegrationsRes.isLoading ? (
<div className="flex h-full min-h-[500px] items-center justify-center">
<Loader className="size-7 animate-spin text-button" />
<Loader2 className="size-7 animate-spin text-button" />
</div>
) : (
<div className="space-y-6 p-4">
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/domain-components/ConnectionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Loader} from 'lucide-react'
import {Loader2} from 'lucide-react'
import * as React from 'react'
import type {ConnectorConfig} from '../../engine-frontend/hocs/WithConnectConfig'
import {Ellipsis} from '../components'
Expand Down Expand Up @@ -59,7 +59,7 @@ export function ConnectionCard({
{/* Overlay spinner */}
{isProcessing && (
<div className="absolute inset-0 z-10 flex items-center justify-center rounded-md bg-card-loading">
<Loader className="size-8 animate-spin text-button" />
<Loader2 className="size-8 animate-spin text-button" />
</div>
)}

Expand Down Expand Up @@ -118,7 +118,7 @@ export function ConnectionCard({
</p>
) : conn.syncInProgress ? (
<div className="flex flex-row items-center justify-start gap-2">
<Loader className="size-5 animate-spin text-button" />
<Loader2 className="size-5 animate-spin text-button" />
<p className="text-center text-sm text-button">Syncing...</p>
</div>
) : (
Expand Down
14 changes: 11 additions & 3 deletions packages/ui/domain-components/ConnectionDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ArrowLeft} from 'lucide-react'
import {ArrowLeft, Loader2} from 'lucide-react'
import type {ConnectorConfig} from '../../engine-frontend/hocs/WithConnectConfig'
import {Button} from '../shadcn'
import {IntegrationLogo} from './ConnectionRawCard'
Expand All @@ -19,16 +19,23 @@ interface ConnectionDetailsProps {
type?: string
}
deleteConnection: ({id}: {id: string}) => void
isDeleting: boolean
onClose: () => void
}

export function ConnectionDetails({
connection,
deleteConnection,
isDeleting,
onClose,
}: ConnectionDetailsProps) {
return (
<div className="flex flex-col gap-4 p-4 pt-2">
<div className="relative flex flex-col gap-4 p-4 pt-2">
{isDeleting && (
<div className="absolute inset-0 z-10 flex items-center justify-center rounded-md bg-card-loading">
<Loader2 className="size-8 animate-spin text-button" />
</div>
)}
<div className="grid grid-cols-1 gap-4 rounded-lg bg-muted p-6">
<div className="flex items-center gap-2">
<ArrowLeft
Expand Down Expand Up @@ -84,8 +91,9 @@ export function ConnectionDetails({
<Button
variant="destructive"
onClick={() => deleteConnection({id: connection.id})}
disabled={isDeleting}
className="h-9">
Delete Connection
{isDeleting ? 'Deleting...' : 'Delete Connection'}
</Button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/domain-components/IntegrationCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Loader, Plus} from 'lucide-react'
import {Loader2, Plus} from 'lucide-react'
import {useEffect, useRef, useState} from 'react'
import {Card, CardContent} from '../shadcn'
import {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function IntegrationCard({
</CardContent>
{isLoading && (
<div className="absolute inset-0 z-10 flex items-center justify-center">
<Loader className="size-7 animate-spin text-button" />
<Loader2 className="size-7 animate-spin text-button" />
</div>
)}
</Card>
Expand Down

0 comments on commit 8f87438

Please sign in to comment.