-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(api): add job route * feat(adapter): pass body * feat(ui): add job modal * feat(ui): prevent submit when json invalid
- Loading branch information
Showing
23 changed files
with
332 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { BaseAdapter } from '../queueAdapters/base'; | ||
import { BullBoardRequest, ControllerHandlerReturnType } from '../../typings/app'; | ||
import { queueProvider } from '../providers/queue'; | ||
import { formatJob } from './queues'; | ||
|
||
async function addJob( | ||
req: BullBoardRequest, | ||
queue: BaseAdapter | ||
): Promise<ControllerHandlerReturnType> { | ||
const { name, data, options } = req.body; | ||
|
||
const job = await queue.addJob(name, data, options); | ||
|
||
return { | ||
status: 200, | ||
body: { | ||
job: formatJob(job, queue), | ||
status: job.getState(), | ||
}, | ||
}; | ||
} | ||
|
||
export const addJobHandler = queueProvider(addJob); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { AppQueue } from '@bull-board/api/dist/typings/app'; | ||
import * as Dialog from '@radix-ui/react-dialog'; | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { QueueActions } from '../../../typings/app'; | ||
import { Button } from '../Button/Button'; | ||
import { InputField } from '../Form/InputField/InputField'; | ||
import { JsonField } from '../Form/JsonField/JsonField'; | ||
import { Modal } from '../Modal/Modal'; | ||
|
||
export interface AddJobModalProps { | ||
open: boolean; | ||
|
||
onClose(): void; | ||
|
||
actions: QueueActions; | ||
queue: AppQueue; | ||
} | ||
|
||
export const AddJobModal = ({ open, onClose, actions, queue }: AddJobModalProps) => { | ||
const [isValid, setValid] = useState(true); | ||
const [jobName, setJobName] = useState(''); | ||
const [jobData, setJobData] = useState<any>({}); | ||
const [jobDelay, setJobDelay] = useState(''); | ||
const [jobAttempts, setJobAttempts] = useState(''); | ||
const { t } = useTranslation(); | ||
|
||
const addJob = () => { | ||
actions.addJob(queue.name, 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} disabled={!isValid}> | ||
{t('ADD_JOB.ADD')} | ||
</Button> | ||
</Dialog.Close> | ||
} | ||
> | ||
<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)} | ||
onValidationError={(errors) => setValid(!errors.length)} | ||
/> | ||
<InputField | ||
label={t('ADD_JOB.JOB_DELAY')} | ||
id="job-delay" | ||
type="number" | ||
value={jobDelay} | ||
min={0} | ||
onChange={(event) => setJobDelay(event.target.value)} | ||
/> | ||
<InputField | ||
label={t('ADD_JOB.JOB_ATTEMPTS')} | ||
id="job-attempts" | ||
type="number" | ||
value={jobAttempts} | ||
min={1} | ||
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,17 @@ | ||
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; | ||
onValidationError?: (errors: Error[]) => 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
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> | ||
); |
Oops, something went wrong.