Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FileChangeType, IPipeline, RdiPipelineTabs } from 'uiSrc/slices/interfa
import MonacoYaml from 'uiSrc/components/monaco-editor/components/monaco-yaml'
import TestConnectionsPanel from 'uiSrc/pages/rdi/pipeline-management/components/test-connections-panel'
import TemplatePopover from 'uiSrc/pages/rdi/pipeline-management/components/template-popover'
import { testConnectionsAction, rdiTestConnectionsSelector } from 'uiSrc/slices/rdi/testConnections'
import { testConnectionsAction, rdiTestConnectionsSelector, testConnectionsController } from 'uiSrc/slices/rdi/testConnections'
import { appContextPipelineManagement } from 'uiSrc/slices/app/context'
import { isEqualPipelineFile } from 'uiSrc/utils'

Expand All @@ -37,6 +37,10 @@ const Config = () => {
sendPageViewTelemetry({
name: TelemetryPageView.RDI_CONFIG,
})

return () => {
testConnectionsController?.abort()
}
}, [])

useEffect(() => {
Expand Down Expand Up @@ -81,6 +85,11 @@ const Config = () => {
checkIsFileUpdated(value)
}

const handleClosePanel = () => {
testConnectionsController?.abort()
setIsPanelOpen(false)
}

return (
<>
<div className={cx('content', 'rdi__wrapper', { [styles.isPanelOpen]: isPanelOpen })}>
Expand Down Expand Up @@ -137,7 +146,7 @@ const Config = () => {
</div>
</div>
{isPanelOpen && (
<TestConnectionsPanel onClose={() => setIsPanelOpen(false)} />
<TestConnectionsPanel onClose={handleClosePanel} />
)}
</>
)
Expand Down
46 changes: 36 additions & 10 deletions redisinsight/ui/src/slices/rdi/testConnections.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { AxiosError } from 'axios'
import axios, { AxiosError } from 'axios'
import { apiService, } from 'uiSrc/services'
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
import { getApiErrorMessage, getRdiUrl, isStatusSuccessful, transformConnectionResults } from 'uiSrc/utils'
import {
getApiErrorMessage,
getRdiUrl,
isStatusSuccessful,
Maybe,
Nullable,
transformConnectionResults
} from 'uiSrc/utils'
import {
IStateRdiTestConnections,
TestConnectionsResponse,
Expand Down Expand Up @@ -31,10 +38,13 @@ const rdiTestConnectionsSlice = createSlice({
state.results = payload
state.error = ''
},
testConnectionsFailure: (state, { payload }) => {
testConnectionsFailure: (state, { payload }: PayloadAction<Maybe<string>>) => {
state.loading = false
state.error = payload
state.results = null

if (payload) {
state.error = payload
}
},
}
})
Expand All @@ -50,6 +60,9 @@ export const {
// The reducer
export default rdiTestConnectionsSlice.reducer

// eslint-disable-next-line import/no-mutable-exports
export let testConnectionsController: Nullable<AbortController> = null

// Asynchronous thunk action
export function testConnectionsAction(
rdiInstanceId: string,
Expand All @@ -58,23 +71,36 @@ export function testConnectionsAction(
onFailAction?: () => void,
) {
return async (dispatch: AppDispatch) => {
dispatch(testConnections())

try {
dispatch(testConnections())
testConnectionsController?.abort()
testConnectionsController = new AbortController()

const { status, data } = await apiService.post<TestConnectionsResponse>(
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_TEST_CONNECTIONS),
config,
{
signal: testConnectionsController.signal
}
)

testConnectionsController = null

if (isStatusSuccessful(status)) {
dispatch(testConnectionsSuccess(transformConnectionResults(data?.sources)))
onSuccessAction?.()
}
} catch (_err) {
const error = _err as AxiosError
const errorMessage = getApiErrorMessage(error)
dispatch(addErrorNotification(error))
dispatch(testConnectionsFailure(errorMessage))
onFailAction?.()
if (!axios.isCancel(_err)) {
const error = _err as AxiosError
const errorMessage = getApiErrorMessage(error)
dispatch(addErrorNotification(error))
dispatch(testConnectionsFailure(errorMessage))
onFailAction?.()
} else {
dispatch(testConnectionsFailure())
}
}
}
}