Skip to content

Commit 3555498

Browse files
update job value in job panel
1 parent a9bf262 commit 3555498

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

redisinsight/ui/src/pages/rdi/pipeline-management/components/jobs-panel/Panel.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
33
import { cloneDeep } from 'lodash'
4+
import { EuiText } from '@elastic/eui'
5+
import { AxiosError } from 'axios'
46
import { act, cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
57

68
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
79
import { dryRunJob, rdiDryRunJobSelector } from 'uiSrc/slices/rdi/dryRun'
10+
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
811
import JobsPanel, { Props } from './Panel'
912

1013
const mockedProps = mock<Props>()
@@ -154,4 +157,29 @@ describe('JobsPanel', () => {
154157

155158
expect(queryByTestId('target-select')).toBeInTheDocument()
156159
})
160+
161+
it('should render error notification', () => {
162+
render(<JobsPanel {...instance(mockedProps)} name="jobName" job={'hsources:incorrect\n target:'} />)
163+
164+
fireEvent.change(screen.getByTestId('input-value'), { target: { value: '[]' } })
165+
166+
fireEvent.click(screen.getByTestId('dry-run-btn'))
167+
168+
const expectedActions = [
169+
addErrorNotification({
170+
response: {
171+
data: {
172+
message: (
173+
<>
174+
<EuiText>JobName has an invalid structure.</EuiText>
175+
<EuiText>end of the stream or a document separator is expected</EuiText>
176+
</>
177+
)
178+
}
179+
}
180+
} as AxiosError)
181+
]
182+
183+
expect(store.getActions().slice(0 - expectedActions.length)).toEqual(expectedActions)
184+
})
157185
})

redisinsight/ui/src/pages/rdi/pipeline-management/components/jobs-panel/Panel.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ import {
1313
} from '@elastic/eui'
1414
import { useDispatch, useSelector } from 'react-redux'
1515
import { useParams } from 'react-router-dom'
16-
import { isArray } from 'lodash'
16+
import { isArray, upperFirst } from 'lodash'
1717

1818
import { PipelineJobsTabs } from 'uiSrc/slices/interfaces/rdi'
1919
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
2020
import { rdiDryRunJobSelector, rdiDryRunJob, setInitialDryRunJob } from 'uiSrc/slices/rdi/dryRun'
2121
import MonacoJson from 'uiSrc/components/monaco-editor/components/monaco-json'
2222
import DryRunJobCommands from 'uiSrc/pages/rdi/pipeline-management/components/dry-run-job-commands'
2323
import DryRunJobTransformations from 'uiSrc/pages/rdi/pipeline-management/components/dry-run-job-transformations'
24-
import { formatLongName } from 'uiSrc/utils'
24+
import { createAxiosError, formatLongName, yamlToJson } from 'uiSrc/utils'
25+
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
2526

2627
import styles from './styles.module.scss'
2728

2829
export interface Props {
29-
job?: object
30+
job: string
31+
name: string
3032
onClose: () => void
3133
}
3234

@@ -42,7 +44,7 @@ const getTargetOption = (value: string) => {
4244
}
4345

4446
const DryRunJobPanel = (props: Props) => {
45-
const { job, onClose } = props
47+
const { job, name, onClose } = props
4648
const { loading: isDryRunning, results } = useSelector(rdiDryRunJobSelector)
4749

4850
const [isFullScreen, setIsFullScreen] = useState<boolean>(false)
@@ -110,9 +112,23 @@ const DryRunJobPanel = (props: Props) => {
110112
id: rdiInstanceId,
111113
},
112114
})
115+
const JSONJob = yamlToJson(job, (msg) => {
116+
dispatch(addErrorNotification(createAxiosError({
117+
message: (
118+
<>
119+
<EuiText>{`${upperFirst(name)} has an invalid structure.`}</EuiText>
120+
<EuiText>{msg}</EuiText>
121+
</>
122+
)
123+
})))
124+
})
125+
if (!JSONJob) {
126+
return
127+
}
113128
const JSONInput = JSON.parse(input)
114129
const formattedValue = isArray(JSONInput) ? JSONInput : [JSONInput]
115-
dispatch(rdiDryRunJob(rdiInstanceId, formattedValue, job))
130+
131+
dispatch(rdiDryRunJob(rdiInstanceId, formattedValue, JSONJob))
116132
}
117133

118134
const isSelectAvailable = selectedTab === PipelineJobsTabs.Output

redisinsight/ui/src/pages/rdi/pipeline-management/pages/job/Job.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const Job = (props: Props) => {
3434

3535
const [isPanelOpen, setIsPanelOpen] = useState<boolean>(false)
3636
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false)
37-
const [JSONJob, setJSONJob] = useState<object>()
3837
const [shouldOpenDedicatedEditor, setShouldOpenDedicatedEditor] = useState<boolean>(false)
3938

4039
const dispatch = useDispatch()
@@ -82,7 +81,6 @@ const Job = (props: Props) => {
8281
return
8382
}
8483
setIsPanelOpen(true)
85-
setJSONJob(JSONValue)
8684
sendEventTelemetry({
8785
event: TelemetryEvent.RDI_TEST_JOB_OPENED,
8886
eventData: {
@@ -250,7 +248,8 @@ const Job = (props: Props) => {
250248
{isPanelOpen && (
251249
<DryRunJobPanel
252250
onClose={() => setIsPanelOpen(false)}
253-
job={JSONJob}
251+
job={value}
252+
name={name}
254253
/>
255254
)}
256255
</>

0 commit comments

Comments
 (0)