mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 10:19:50 -04:00
9240478816
## Screenshots ### New cron job edge function timeout Before: <img width="1157" height="259" alt="image" src="https://github.com/user-attachments/assets/b5e056e7-6216-45a6-9cc6-15e56621c62a" /> After: <img width="1162" height="258" alt="image" src="https://github.com/user-attachments/assets/bfb12a20-8a11-47f1-b7e6-c1ebc2fc187e" /> ### New cron job http request timeout Before: <img width="1161" height="237" alt="image" src="https://github.com/user-attachments/assets/ad1dc7ef-e9ec-4219-8f84-f20025aa1c68" /> After: <img width="1160" height="231" alt="image" src="https://github.com/user-attachments/assets/eb4d0df2-db20-4e04-a78d-fa36656a2987" /> ### New queue, partition configuration Before: <img width="786" height="677" alt="image" src="https://github.com/user-attachments/assets/34b3f1fc-b1e8-434f-bfc7-8a5686bd1c29" /> After: <img width="778" height="668" alt="image" src="https://github.com/user-attachments/assets/f7423240-b810-47d6-af1d-9d5647c78843" /> ### Queue: send message dialog Before: <img width="522" height="411" alt="image" src="https://github.com/user-attachments/assets/f9cf5993-c7e4-4bd0-9718-0c9e85e41378" /> After: <img width="532" height="414" alt="image" src="https://github.com/user-attachments/assets/d965bfcc-c074-44a1-8a8f-ecdd4e766221" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Enhanced input field presentation for timeout, delay, and interval configurations with inline unit labels (milliseconds, seconds, messages) for improved clarity and consistency across integration settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
149 lines
4.2 KiB
TypeScript
149 lines
4.2 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useParams } from 'common'
|
|
import { useEffect } from 'react'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupInput,
|
|
InputGroupText,
|
|
Modal,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import z from 'zod'
|
|
|
|
import CodeEditor from '@/components/ui/CodeEditor/CodeEditor'
|
|
import { useDatabaseQueueMessageSendMutation } from '@/data/database-queues/database-queue-messages-send-mutation'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
interface SendMessageModalProps {
|
|
visible: boolean
|
|
onClose: () => void
|
|
}
|
|
|
|
const FormSchema = z.object({
|
|
delay: z.coerce.number().int().gte(0).default(5),
|
|
payload: z.string().refine(
|
|
(val) => {
|
|
try {
|
|
JSON.parse(val)
|
|
} catch {
|
|
return false
|
|
}
|
|
},
|
|
{
|
|
message: 'The payload should be a JSON object',
|
|
}
|
|
),
|
|
})
|
|
|
|
export type SendMessageForm = z.infer<typeof FormSchema>
|
|
|
|
const FORM_ID = 'QUEUES_SEND_MESSAGE_FORM'
|
|
|
|
export const SendMessageModal = ({ visible, onClose }: SendMessageModalProps) => {
|
|
const { childId: queueName } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const form = useForm<SendMessageForm>({
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues: {
|
|
delay: 1,
|
|
payload: '{}',
|
|
},
|
|
})
|
|
|
|
const { isPending, mutate } = useDatabaseQueueMessageSendMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully added a message to the queue.`)
|
|
onClose()
|
|
},
|
|
})
|
|
|
|
const onSubmit: SubmitHandler<SendMessageForm> = (values) => {
|
|
mutate({
|
|
projectRef: project?.ref!,
|
|
connectionString: project?.connectionString,
|
|
queueName: queueName!,
|
|
payload: values.payload,
|
|
delay: values.delay,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (visible) {
|
|
form.reset({ delay: 1, payload: '{}' })
|
|
}
|
|
}, [visible])
|
|
|
|
return (
|
|
<Modal
|
|
size="medium"
|
|
alignFooter="right"
|
|
header="Add a message to the queue"
|
|
visible={visible}
|
|
loading={isPending}
|
|
onCancel={onClose}
|
|
confirmText="Add"
|
|
onConfirm={() => {
|
|
const values = form.getValues()
|
|
onSubmit(values)
|
|
}}
|
|
>
|
|
<Modal.Content className="flex flex-col gap-y-4">
|
|
<Form {...form}>
|
|
<form
|
|
id={FORM_ID}
|
|
className="grow overflow-auto gap-2 flex flex-col"
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
>
|
|
<FormField
|
|
control={form.control}
|
|
name="delay"
|
|
render={({ field: { ref, ...rest } }) => (
|
|
<FormItemLayout
|
|
label="Delay"
|
|
layout="vertical"
|
|
className="gap-1"
|
|
description="Time in seconds before the message becomes available for reading."
|
|
>
|
|
<FormControl>
|
|
<InputGroup>
|
|
<InputGroupInput {...rest} type="number" placeholder="1" />
|
|
<InputGroupAddon align="inline-end">
|
|
<InputGroupText>sec</InputGroupText>
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="payload"
|
|
render={({ field }) => (
|
|
<FormItemLayout label="Message payload" layout="vertical" className="gap-1">
|
|
<FormControl>
|
|
<CodeEditor
|
|
id="message-payload"
|
|
language="json"
|
|
autofocus={false}
|
|
className="mb-0! h-32 overflow-hidden rounded-sm border"
|
|
onInputChange={(e: string | undefined) => field.onChange(e)}
|
|
options={{ wordWrap: 'off', contextmenu: false }}
|
|
value={field.value}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</form>
|
|
</Form>
|
|
</Modal.Content>
|
|
</Modal>
|
|
)
|
|
}
|