Skip to content

Commit

Permalink
Bring back process now button + tweak logic for processing captures
Browse files Browse the repository at this point in the history
  • Loading branch information
annavik committed Nov 7, 2023
1 parent c7af4ee commit 180bcb3
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 38 deletions.
1 change: 1 addition & 0 deletions ui/src/data-services/hooks/jobs/useCancelJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useCancelJob = () => {
),
onSuccess: () => {
queryClient.invalidateQueries([API_ROUTES.JOBS])
queryClient.invalidateQueries([API_ROUTES.CAPTURES])
},
})

Expand Down
3 changes: 2 additions & 1 deletion ui/src/data-services/hooks/jobs/useCreateJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useCreateJob = (onSuccess?: (id: string) => void) => {

const { mutateAsync, isLoading, isSuccess, reset, error } = useMutation({
mutationFn: (fieldValues: JobFieldValues) =>
axios.post<{ id: number }>(
axios.post<{ id: number; source_image_single?: { id: number } }>(
`${API_URL}/${API_ROUTES.JOBS}/${
fieldValues.startNow ? '?start_now' : ''
}`,
Expand All @@ -42,6 +42,7 @@ export const useCreateJob = (onSuccess?: (id: string) => void) => {
),
onSuccess: ({ data }) => {
queryClient.invalidateQueries([API_ROUTES.JOBS])
queryClient.invalidateQueries([API_ROUTES.CAPTURES])
onSuccess?.(`${data.id}`)
setTimeout(reset, SUCCESS_TIMEOUT)
},
Expand Down
1 change: 1 addition & 0 deletions ui/src/data-services/hooks/jobs/useDeleteJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useDeleteJob = (onSuccess?: () => void) => {
}),
onSuccess: () => {
queryClient.invalidateQueries([API_ROUTES.JOBS])
queryClient.invalidateQueries([API_ROUTES.CAPTURES])
onSuccess?.()
},
})
Expand Down
1 change: 1 addition & 0 deletions ui/src/data-services/hooks/jobs/useQueueJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useQueueJob = () => {
}),
onSuccess: () => {
queryClient.invalidateQueries([API_ROUTES.JOBS])
queryClient.invalidateQueries([API_ROUTES.CAPTURES])
},
})

Expand Down
11 changes: 10 additions & 1 deletion ui/src/data-services/models/capture-details.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capture, ServerCapture } from './capture'
import { Job } from './job'
import { Job, JobStatus } from './job'

export type ServerCaptureDetails = ServerCapture & any // TODO: Update this type

Expand All @@ -17,4 +17,13 @@ export class CaptureDetails extends Capture {
get jobs(): Job[] {
return this._jobs
}

get hasJobInProgress(): boolean {
return this._jobs.some(
(job) =>
job.status === JobStatus.Created ||
job.status === JobStatus.Pending ||
job.status === JobStatus.Started
)
}
}
48 changes: 19 additions & 29 deletions ui/src/pages/job-details/job-details-form/job-details-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FormConfig } from 'components/form/types'
import { Button, ButtonTheme } from 'design-system/components/button/button'
import { Checkbox } from 'design-system/components/checkbox/checkbox'
import { IconType } from 'design-system/components/icon/icon'
import { InputContent, InputValue } from 'design-system/components/input/input'
import { InputContent } from 'design-system/components/input/input'
import { useForm } from 'react-hook-form'
import { STRING, translate } from 'utils/language'
import { useFormError } from 'utils/useFormError'
Expand Down Expand Up @@ -52,13 +52,11 @@ const config: FormConfig = {
}

export const JobDetailsForm = ({
captureId,
error,
isLoading,
isSuccess,
onSubmit,
}: {
captureId?: string
error?: unknown
isLoading?: boolean
isSuccess?: boolean
Expand All @@ -70,9 +68,8 @@ export const JobDetailsForm = ({
setError: setFieldError,
} = useForm<JobFormValues>({
defaultValues: {
name: captureId ? `Capture #${captureId}` : '',
name: '',
delay: 0,
sourceImage: captureId,
},
mode: 'onChange',
})
Expand Down Expand Up @@ -104,30 +101,23 @@ export const JobDetailsForm = ({
/>
</FormRow>
<FormRow>
{captureId ? (
<InputValue
label={translate(STRING.FIELD_LABEL_SOURCE_IMAGE)}
value={`Capture #${captureId}`}
/>
) : (
<FormController
name="sourceImages"
control={control}
config={config.sourceImages}
render={({ field, fieldState }) => (
<InputContent
description={config[field.name].description}
label={config[field.name].label}
error={fieldState.error?.message}
>
<CollectionsPicker
value={field.value}
onValueChange={field.onChange}
/>
</InputContent>
)}
/>
)}
<FormController
name="sourceImages"
control={control}
config={config.sourceImages}
render={({ field, fieldState }) => (
<InputContent
description={config[field.name].description}
label={config[field.name].label}
error={fieldState.error?.message}
>
<CollectionsPicker
value={field.value}
onValueChange={field.onChange}
/>
</InputContent>
)}
/>
<FormController
name="pipeline"
control={control}
Expand Down
5 changes: 2 additions & 3 deletions ui/src/pages/job-details/new-job-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './job-details.module.scss'

const CLOSE_TIMEOUT = 1000

export const NewJobDialog = ({ captureId }: { captureId?: string }) => {
export const NewJobDialog = () => {
const { projectId } = useParams()
const [isOpen, setIsOpen] = useState(false)
const { createJob, isLoading, isSuccess, error } = useCreateJob(() =>
Expand All @@ -29,14 +29,13 @@ export const NewJobDialog = ({ captureId }: { captureId?: string }) => {
<Button
label={label}
icon={IconType.Plus}
theme={captureId ? ButtonTheme.Neutral : ButtonTheme.Default}
theme={ButtonTheme.Default}
/>
</Dialog.Trigger>
<Dialog.Content ariaCloselabel={translate(STRING.CLOSE)}>
<Dialog.Header title={label} />
<div className={styles.content}>
<JobDetailsForm
captureId={captureId}
error={error}
isLoading={isLoading}
isSuccess={isSuccess}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useCaptureDetails } from 'data-services/hooks/captures/useCaptureDetails'
import { NewJobDialog } from 'pages/job-details/new-job-dialog'
import { CaptureJobDialog } from './capture-job-dialog'
import { ProcessNow } from './process-now'

export const CaptureJob = ({ captureId }: { captureId: string }) => {
const { capture } = useCaptureDetails(captureId)

return (
<>
<NewJobDialog captureId={captureId} />
<ProcessNow capture={capture} captureId={captureId} />
{capture?.jobs.length ? (
<CaptureJobDialog id={capture.jobs[0].id} />
) : null}
Expand Down
36 changes: 36 additions & 0 deletions ui/src/pages/session-details/playback/capture-job/process-now.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useCreateJob } from 'data-services/hooks/jobs/useCreateJob'
import { CaptureDetails } from 'data-services/models/capture-details'
import { Button, ButtonTheme } from 'design-system/components/button/button'
import { IconType } from 'design-system/components/icon/icon'
import { useParams } from 'react-router-dom'
import { STRING, translate } from 'utils/language'

export const ProcessNow = ({
capture,
captureId,
}: {
capture?: CaptureDetails
captureId: string
}) => {
const { projectId } = useParams()
const { createJob, isLoading, isSuccess } = useCreateJob()

return (
<Button
icon={isSuccess ? IconType.RadixCheck : IconType.BatchId}
disabled={!capture || capture.hasJobInProgress}
label={translate(STRING.PROCESS_NOW)}
loading={isLoading}
theme={ButtonTheme.Neutral}
onClick={() => {
createJob({
delay: 1,
name: `Capture #${captureId}`,
sourceImage: captureId,
projectId: projectId as string,
startNow: true,
})
}}
/>
)
}
6 changes: 4 additions & 2 deletions ui/src/utils/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export enum STRING {
DELETE,
DELETED,
EDIT,
NEXT,

LOGIN,
LOGOUT,
NEXT,
PROCESS_NOW,
REFRESH,
RESET,
RETRY,
Expand Down Expand Up @@ -166,6 +168,7 @@ const ENGLISH_STRINGS: { [key in STRING]: string } = {
[STRING.LOGIN]: 'Login',
[STRING.LOGOUT]: 'Logout',
[STRING.NEXT]: 'Next',
[STRING.PROCESS_NOW]: 'Process now',
[STRING.REFRESH]: 'Refresh',
[STRING.RESET]: 'Reset',
[STRING.RETRY]: 'Retry',
Expand All @@ -176,7 +179,6 @@ const ENGLISH_STRINGS: { [key in STRING]: string } = {
[STRING.START]: 'Start',
[STRING.SUBMIT]: 'Submit',
[STRING.SUGGEST_ID]: 'Suggest ID',

[STRING.VIEW_PUBLIC_PROJECTS]: 'View public projects',

/* FIELD_LABEL */
Expand Down

0 comments on commit 180bcb3

Please sign in to comment.