Skip to content

Commit aa19b89

Browse files
authored
Merge pull request #3566 from RedisInsight/fe/bugfix/inline_editor_submit
add validation on submit
2 parents 4dac939 + 056f7dc commit aa19b89

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

redisinsight/api/config/features-config.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 2.52,
2+
"version": 2.5202,
33
"features": {
44
"rdi": {
55
"flag": true,
@@ -18,7 +18,7 @@
1818
},
1919
"documentationChat": {
2020
"flag": true,
21-
"perc": [[0,5]],
21+
"perc": [[0,20]],
2222
"filters": [
2323
{
2424
"name": "config.server.buildType",
@@ -29,7 +29,7 @@
2929
},
3030
"databaseChat": {
3131
"flag": true,
32-
"perc": [[0,5]],
32+
"perc": [[0,20]],
3333
"filters": [
3434
{
3535
"name": "config.server.buildType",
@@ -78,11 +78,6 @@
7878
"name": "config.server.buildType",
7979
"value": "ELECTRON",
8080
"cond": "eq"
81-
},
82-
{
83-
"name": "agreements.analytics",
84-
"value": true,
85-
"cond": "eq"
8681
}
8782
]
8883
},

redisinsight/ui/src/components/inline-item-editor/InlineItemEditor.spec.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,42 @@ describe('InlineItemEditor', () => {
100100
fireEvent.click(screen.getByTestId(/save-btn/))
101101
expect(onApplyMock).toBeCalled()
102102
})
103+
104+
it('should not call onApply if form is invalid', () => {
105+
const onApplyMock = jest.fn().mockReturnValue(false)
106+
render(
107+
<InlineItemEditor
108+
{...instance(mockedProps)}
109+
isLoading
110+
onApply={onApplyMock}
111+
onDecline={jest.fn()}
112+
/>
113+
)
114+
115+
expect(screen.getByTestId('apply-btn')).toBeDisabled()
116+
117+
fireEvent.submit(screen.getByTestId(INLINE_ITEM_EDITOR))
118+
119+
expect(onApplyMock).not.toBeCalled()
120+
})
121+
122+
it('should call onApply if form is valid', () => {
123+
const onApplyMock = jest.fn().mockReturnValue(false)
124+
render(
125+
<InlineItemEditor
126+
{...instance(mockedProps)}
127+
onApply={onApplyMock}
128+
onDecline={jest.fn()}
129+
/>
130+
)
131+
132+
fireEvent.change(screen.getByTestId(INLINE_ITEM_EDITOR), { target: { value: 'val123' } })
133+
134+
expect(screen.getByTestId('apply-btn')).not.toBeDisabled()
135+
136+
fireEvent.submit(screen.getByTestId(INLINE_ITEM_EDITOR))
137+
138+
expect(onApplyMock).toBeCalled()
139+
})
103140
})
104141
})

redisinsight/ui/src/components/inline-item-editor/InlineItemEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ const InlineItemEditor = (props: Props) => {
158158
const handleFormSubmit = (event: React.MouseEvent<HTMLElement>): void => {
159159
event.preventDefault()
160160
event.stopPropagation()
161-
onApply(value, event)
161+
if (!isDisabledApply()) {
162+
onApply(value, event)
163+
}
162164
}
163165

164166
const isDisabledApply = (): boolean =>

0 commit comments

Comments
 (0)