-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
263 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as Dialog from '@radix-ui/react-dialog'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useQueues } from '../../hooks/useQueues'; | ||
import { Button } from '../Button/Button'; | ||
import { InputField } from '../Form/InputField/InputField'; | ||
import { JsonField } from '../Form/JsonField/JsonField'; | ||
import { SelectField } from '../Form/SelectField/InputField'; | ||
import { Modal } from '../Modal/Modal'; | ||
|
||
export interface AddJobModalProps { | ||
open: boolean; | ||
|
||
onClose(): void; | ||
} | ||
|
||
export const AddJobModal = ({ open, onClose }: AddJobModalProps) => { | ||
const { actions, queues } = useQueues(); | ||
const [queueName, setQueueName] = useState(''); | ||
const [jobName, setJobName] = useState(''); | ||
const [jobData, setJobData] = useState<any>({}); | ||
const [jobDelay, setJobDelay] = useState(''); | ||
const [jobAttempts, setJobAttempts] = useState(''); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
if (queues && queues.length) { | ||
setQueueName(queues[0].name); | ||
} | ||
}, [queues]); | ||
|
||
const addJob = () => { | ||
actions.addJob(queueName, jobName || '__default__', jobData, { | ||
delay: jobDelay ? +jobDelay : undefined, | ||
attempts: jobAttempts ? +jobAttempts : undefined, | ||
})(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
width="small" | ||
open={open} | ||
onClose={onClose} | ||
title={t('ADD_JOB.TITLE')} | ||
actionButton={ | ||
<Dialog.Close asChild> | ||
<Button theme="primary" onClick={addJob}> | ||
{t('ADD_JOB.ADD')} | ||
</Button> | ||
</Dialog.Close> | ||
} | ||
> | ||
<SelectField | ||
label={t('ADD_JOB.QUEUE_NAME')} | ||
id="queue-name" | ||
options={(queues || []).map((queue) => ({ | ||
text: queue.name, | ||
value: queue.name, | ||
}))} | ||
value={queueName} | ||
onChange={(event) => setQueueName(event.target.value)} | ||
/> | ||
<InputField | ||
label={t('ADD_JOB.JOB_NAME')} | ||
id="job-name" | ||
value={jobName} | ||
placeholder="__default__" | ||
onChange={(event) => setJobName(event.target.value)} | ||
/> | ||
<JsonField | ||
label={t('ADD_JOB.JOB_DATA')} | ||
id="job-data" | ||
value={jobData} | ||
onChange={(v) => setJobData(v)} | ||
/> | ||
<InputField | ||
label={t('ADD_JOB.JOB_DELAY')} | ||
id="job-delay" | ||
type="number" | ||
value={jobDelay} | ||
onChange={(event) => setJobDelay(event.target.value)} | ||
/> | ||
<InputField | ||
label={t('ADD_JOB.JOB_ATTEMPTS')} | ||
id="job-attempts" | ||
type="number" | ||
value={jobAttempts} | ||
onChange={(event) => setJobAttempts(event.target.value)} | ||
/> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { JsonEditor as Editor } from 'jsoneditor-react'; | ||
import 'jsoneditor-react/es/editor.min.css'; | ||
import React, { HTMLProps } from 'react'; | ||
import { Field } from '../Field/Field'; | ||
|
||
interface JsonFieldProps extends HTMLProps<any> { | ||
label?: string; | ||
value?: any; | ||
onChange?: (v: any) => void; | ||
} | ||
|
||
export const JsonField = ({ label, id, ...props }: JsonFieldProps) => ( | ||
<Field label={label} id={id}> | ||
<Editor mode="code" {...props} /> | ||
</Field> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
|
||
export const AddIcon = () => ( | ||
<svg | ||
role="img" | ||
width="256px" | ||
height="256px" | ||
viewBox="0 0 24.00 24.00" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
stroke="#748094" | ||
> | ||
<g id="SVGRepo_bgCarrier" strokeWidth="0"></g> | ||
<g id="SVGRepo_tracerCarrier" strokeLinecap="round" strokeLinejoin="round"></g> | ||
<g id="SVGRepo_iconCarrier"> | ||
<path | ||
d="M12 6C12.5523 6 13 6.44772 13 7V11H17C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13H13V17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17V13H7C6.44772 13 6 12.5523 6 12C6 11.4477 6.44772 11 7 11H11V7C11 6.44772 11.4477 6 12 6Z" | ||
fill="#748094" | ||
></path> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M2 4.5C2 3.11929 3.11929 2 4.5 2H19.5C20.8807 2 22 3.11929 22 4.5V19.5C22 20.8807 20.8807 22 19.5 22H4.5C3.11929 22 2 20.8807 2 19.5V4.5ZM4.5 4C4.22386 4 4 4.22386 4 4.5V19.5C4 19.7761 4.22386 20 4.5 20H19.5C19.7761 20 20 19.7761 20 19.5V4.5C20 4.22386 19.7761 4 19.5 4H4.5Z" | ||
fill="#748094" | ||
></path> | ||
</g> | ||
</svg> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.