Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(job): configurable title #1441

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "CORE:UiRecipe",
"config": {
"type": "PLUGINS:dm-core-plugins/job/CreateConfig",
"title": "Run a reverse description job",
"hideLogs": true,
"jobTargetAddress": ".job",
"jobTemplates": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"type": "CORE:UiRecipe",
"config": {
"type": "PLUGINS:dm-core-plugins/job/ControlConfig",
"title": "Schedule an example recurring job",
"runnerTemplates": [
{
"type": "PLUGINS:dm-core-plugins/common/Template",
Expand Down
7 changes: 7 additions & 0 deletions packages/dm-core-plugins/blueprints/job/ControlConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"attributeType": "PLUGINS:dm-core-plugins/common/Template",
"dimensions": "*",
"optional": true
},
{
"name": "title",
"type": "CORE:BlueprintAttribute",
"attributeType": "string",
"optional": true,
"description": "Show a title for the job controls"
}
]
}
7 changes: 7 additions & 0 deletions packages/dm-core-plugins/blueprints/job/CreateConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
"description": "'applicationInput' for the created job. Absolute or relative address",
"attributeType": "string",
"optional": true
},
{
"name": "title",
"type": "CORE:BlueprintAttribute",
"attributeType": "string",
"optional": true,
"description": "Show a title for the job controls"
}
]
}
174 changes: 86 additions & 88 deletions packages/dm-core-plugins/src/job/JobControl/JobControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import {
useDocument,
useJob,
} from '@development-framework/dm-core'
import { Button, Chip, Icon, Tooltip } from '@equinor/eds-core-react'
import {
Button,
Chip,
Icon,
Tooltip,
Typography,
} from '@equinor/eds-core-react'
import { gear } from '@equinor/eds-icons'
import { AxiosError } from 'axios'
import _ from 'lodash'
Expand All @@ -38,6 +44,7 @@ import { defaultCronValues, scheduleTemplate } from '../templateEntities'
type TJobControlConfig = {
hideLogs?: boolean
runnerTemplates?: TTemplate[]
title?: string
}

const defaultConfig: TJobControlConfig = {
Expand Down Expand Up @@ -167,98 +174,89 @@ export const JobControl = (props: IUIPlugin) => {

return (
<div className='dm-plugin-padding'>
<div className='flex-col border rounded-md bg-equinor-lightgray'>
<div>
{asCronJob && (
<div className='rounded-md p-2 m-2 bg-white border'>
<ConfigureRecurring
asCron={asCronJob}
readOnly={true}
schedule={schedule}
setSchedule={(s: TSchedule) => {
setSchedule(s)
setCronValues(parseCronStringToCronValues(s.cron))
}}
cronValues={cronValues}
setCronValues={(c: TCronValues) => {
setSchedule({
...schedule,
cron: parseCronValuesToCronString(c),
})
setCronValues(c)
}}
registered={status === JobStatus.Registered}
/>
<div className='flex flex-col gap-1 border rounded-md bg-equinor-lightgray p-2'>
{internalConfig.title && (
<Typography variant='h6'>{config.title}</Typography>
)}
{asCronJob && (
<div className='rounded-md p-2 bg-white border'>
<ConfigureRecurring
asCron={asCronJob}
readOnly={true}
schedule={schedule}
setSchedule={(s: TSchedule) => {
setSchedule(s)
setCronValues(parseCronStringToCronValues(s.cron))
}}
cronValues={cronValues}
setCronValues={(c: TCronValues) => {
setSchedule({
...schedule,
cron: parseCronValuesToCronString(c),
})
setCronValues(c)
}}
registered={status === JobStatus.Registered}
/>
</div>
)}
<JobButtonWrapper>
<div className='flex items-center space-x-2'>
{getControlButton(status, remove, start, false, jobIsLoading)}
<div className='flex flex-row items-center'>
<p className='text-sm'>Status:</p>
<Chip variant={getVariant(status)} data-testid={'jobStatus'}>
{status ?? 'Not registered'}
</Chip>
</div>
)}
<JobButtonWrapper>
<div className='flex items-center space-x-2'>
{getControlButton(status, remove, start, false, jobIsLoading)}
<div
style={{
width: '100px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<p className='text-sm text-center'>Status:</p>
<Chip variant={getVariant(status)} data-testid={'jobStatus'}>
{status ?? 'Not registered'}
</Chip>
</div>

{!internalConfig.hideLogs && <JobLog logs={logs} error={error} />}
</div>
{!internalConfig.hideLogs && <JobLog logs={logs} error={error} />}
</div>

{internalConfig.runnerTemplates &&
internalConfig.runnerTemplates.length > 0 && (
<div className={'flex flex-row items-center justify-end'}>
<Tooltip
title={`Change runner. Current: ${(
(asCronJob
? jobEntity.applicationInput?.runner.type
: jobEntity.runner?.type) || 'None'
)
.split('/')
.at(-1)}`}
>
<Button
disabled={[
JobStatus.Starting,
JobStatus.Running,
].includes(
// @ts-ignore
status
)}
onClick={() => setTemplateMenuIsOpen(true)}
variant='ghost_icon'
>
<Icon data={gear} size={24} />
</Button>
</Tooltip>
<TemplateMenu
templates={internalConfig.runnerTemplates || []}
onSelect={(template: TTemplate) =>
handleRunnerTemplateSelect(template)
}
onClose={() => setTemplateMenuIsOpen(false)}
isOpen={isTemplateMenuOpen}
title='Runner'
selected={templates.findIndex((template: TJobHandler) =>
_.isEqual(template, jobEntity.runner)
{internalConfig.runnerTemplates &&
internalConfig.runnerTemplates.length > 0 && (
<div className={'flex flex-row items-center justify-end'}>
<Tooltip
title={`Change runner. Current: ${(
(asCronJob
? jobEntity.applicationInput?.runner.type
: jobEntity.runner?.type) || 'None'
)
.split('/')
.at(-1)}`}
>
<Button
disabled={[JobStatus.Starting, JobStatus.Running].includes(
// @ts-ignore
status
)}
/>
</div>
)}
</JobButtonWrapper>
onClick={() => setTemplateMenuIsOpen(true)}
variant='ghost_icon'
>
<Icon data={gear} size={24} />
</Button>
</Tooltip>
<TemplateMenu
templates={internalConfig.runnerTemplates || []}
onSelect={(template: TTemplate) =>
handleRunnerTemplateSelect(template)
}
onClose={() => setTemplateMenuIsOpen(false)}
isOpen={isTemplateMenuOpen}
title='Runner'
selected={templates.findIndex((template: TJobHandler) =>
_.isEqual(template, jobEntity.runner)
)}
/>
</div>
)}
</JobButtonWrapper>

{status === JobStatus.Running && progress !== null && (
<div className='px-4 pb-2'>
<Progress progress={progress} />
</div>
)}
</div>
{status === JobStatus.Running && progress !== null && (
<div className='px-4 pb-2'>
<Progress progress={progress} />
</div>
)}
</div>
</div>
)
Expand Down
127 changes: 72 additions & 55 deletions packages/dm-core-plugins/src/job/JobCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import {
useDocument,
useJob,
} from '@development-framework/dm-core'
import { Button, Chip, Icon, Tooltip } from '@equinor/eds-core-react'
import {
Button,
Chip,
Icon,
Tooltip,
Typography,
} from '@equinor/eds-core-react'
import { gear } from '@equinor/eds-icons'
import { useEffect, useState } from 'react'

Expand Down Expand Up @@ -48,6 +54,7 @@ interface TJobPluginConfig {
showGetResult?: boolean
jobTemplates: TTemplate[]
hideLogs?: boolean
title?: string
}

export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
Expand Down Expand Up @@ -165,63 +172,73 @@ export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
if (jobDocument.type === EBlueprint.RECURRING_JOB) setAsCronJob(true)
}, [jobDocument])
return (
<div className={'flex-col'}>
{config.recurring !== false && (
<ConfigureRecurring
asCron={asCronJob}
setAsCron={setAsCronJob}
readOnly={true}
schedule={schedule}
setSchedule={(s: TSchedule) => {
setSchedule(s)
setCronValues(parseCronStringToCronValues(s.cron))
}}
cronValues={cronValues}
setCronValues={(c: TCronValues) => {
setSchedule({ ...schedule, cron: parseCronValuesToCronString(c) })
setCronValues(c)
}}
registered={status === JobStatus.Registered}
/>
)}
<JobButtonWrapper>
{getControlButton(
status,
deregister,
createAndStartJob,
false,
jobIsLoading
<div className='dm-plugin-padding'>
<div className='flex-col border rounded-md bg-equinor-lightgray p-2'>
{config.title && <Typography variant='h6'>{config.title}</Typography>}
{config.recurring !== false && (
<ConfigureRecurring
asCron={asCronJob}
setAsCron={setAsCronJob}
readOnly={true}
schedule={schedule}
setSchedule={(s: TSchedule) => {
setSchedule(s)
setCronValues(parseCronStringToCronValues(s.cron))
}}
cronValues={cronValues}
setCronValues={(c: TCronValues) => {
setSchedule({ ...schedule, cron: parseCronValuesToCronString(c) })
setCronValues(c)
}}
registered={status === JobStatus.Registered}
/>
)}
{!config.hideLogs && <JobLog logs={logs} error={error} />}
<Chip variant={getVariant(status)}>{status ?? 'Not registered'}</Chip>
{config.jobTemplates.length > 1 && (
<div className={'flex flex-row items-center'}>
<Tooltip title={`Change Job template. Current: `}>
<Button
onClick={() => setTemplateMenuIsOpen(true)}
variant='ghost_icon'
disabled={[JobStatus.Starting, JobStatus.Running].includes(
// @ts-ignore
status
)}
>
<Icon data={gear} size={24} />
</Button>
</Tooltip>
<TemplateMenu
templates={config.jobTemplates || []}
onSelect={(_: any, index: number) => setSelectedTemplate(index)}
onClose={() => setTemplateMenuIsOpen(false)}
isOpen={isTemplateMenuOpen}
title='Job template'
selected={selectedTemplate}
/>
<JobButtonWrapper>
<div className='flex items-center space-x-2'>
{getControlButton(
status,
deregister,
createAndStartJob,
false,
jobIsLoading
)}
<div className='flex flex-row items-center'>
<p className='text-sm text-center'>Status:</p>
<Chip variant={getVariant(status)} data-testid={'jobStatus'}>
{status ?? 'Not registered'}
</Chip>
</div>
{!config.hideLogs && <JobLog logs={logs} error={error} />}
</div>
{config.jobTemplates.length > 1 && (
<div className={'flex flex-row items-center'}>
<Tooltip title={`Change Job template. Current: `}>
<Button
onClick={() => setTemplateMenuIsOpen(true)}
variant='ghost_icon'
disabled={[JobStatus.Starting, JobStatus.Running].includes(
// @ts-ignore
status
)}
>
<Icon data={gear} size={24} />
</Button>
</Tooltip>
<TemplateMenu
templates={config.jobTemplates || []}
onSelect={(_: any, index: number) => setSelectedTemplate(index)}
onClose={() => setTemplateMenuIsOpen(false)}
isOpen={isTemplateMenuOpen}
title='Job template'
selected={selectedTemplate}
/>
</div>
)}
</JobButtonWrapper>
{status === JobStatus.Running && progress !== null && (
<Progress progress={progress} />
)}
</JobButtonWrapper>
{status === JobStatus.Running && progress !== null && (
<Progress progress={progress} />
)}
</div>
</div>
)
}
Loading
Loading