Skip to content

Commit 4d927e5

Browse files
fix: project filter was not properly saved in webhook modal (#2834)
1 parent fe2ee47 commit 4d927e5

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

libs/domains/organizations/feature/src/lib/settings-webhook/webhook-crud-modal/webhook-crud-modal.spec.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ describe('WebhookCrudModal', () => {
156156
})
157157
})
158158

159+
it('should commit a project filter typed but not confirmed with Enter when submitting', async () => {
160+
const { userEvent } = renderWithProviders(<WebhookCrudModal {...props} webhook={mockWebhook} />)
161+
const url = screen.getByLabelText('URL')
162+
const kind = screen.getByLabelText('Kind')
163+
const tags = screen.getByTestId('input-tags-field')
164+
165+
await userEvent.clear(url)
166+
await userEvent.type(url, 'https://test.com')
167+
168+
await selectEvent.select(kind, ['Standard'], {
169+
container: document.body,
170+
})
171+
172+
await userEvent.type(tags, 'test')
173+
174+
const button = screen.getByTestId('submit-button')
175+
await userEvent.click(button)
176+
177+
expect(editWebhookMock).toHaveBeenCalledWith({
178+
organizationId: '000-000-000',
179+
webhookId: mockWebhook.id,
180+
webhookRequest: expect.objectContaining({
181+
project_names_filter: ['test'],
182+
}),
183+
})
184+
})
185+
159186
it('should trim URL with trailing whitespace on create', async () => {
160187
const { userEvent } = renderWithProviders(<WebhookCrudModal {...props} />)
161188

libs/shared/ui/src/lib/components/inputs/input-tags/input-tags.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ export function InputTags(props: InputTagsProps) {
5555
isLabelTransitionDisabled && '!transition-none'
5656
)
5757

58+
const commitTag = (rawValue: string) => {
59+
const value = rawValue.trim()
60+
if (!value) return
61+
if (currentTags.find((v) => value.toLowerCase() === v.toLowerCase())) return
62+
63+
const newTags = [...currentTags, value]
64+
setCurrentTags(newTags)
65+
setInputValue('')
66+
onChange && onChange(newTags)
67+
}
68+
5869
const handleKeyDown = (event: FormEvent<HTMLInputElement>) => {
5970
const key = (event as KeyboardEvent<HTMLInputElement>).key
6071
const target = event.target as HTMLInputElement
@@ -69,14 +80,7 @@ export function InputTags(props: InputTagsProps) {
6980
if (key === 'Enter') {
7081
event.preventDefault()
7182
event.stopPropagation()
72-
73-
if (!value.trim()) return
74-
if (currentTags.find((v) => value.toLowerCase() === v.toLowerCase())) return
75-
76-
const newTags = [...currentTags, value]
77-
setCurrentTags(newTags)
78-
setInputValue('')
79-
onChange && onChange(newTags)
83+
commitTag(value)
8084
}
8185
}
8286

@@ -116,6 +120,7 @@ export function InputTags(props: InputTagsProps) {
116120
ref={ref}
117121
data-testid="input-tags-field"
118122
onKeyDown={handleKeyDown}
123+
onBlur={(e) => commitTag(e.currentTarget.value)}
119124
type="text"
120125
className={twMerge(
121126
'bg-transparent',

0 commit comments

Comments
 (0)