Skip to content

Commit

Permalink
feat(job): configurable title
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed May 29, 2024
1 parent d8cc86b commit 4ba3f6c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 99 deletions.
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"
}
]
}
166 changes: 77 additions & 89 deletions packages/dm-core-plugins/src/job/JobControl/JobControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { defaultCronValues, scheduleTemplate } from '../templateEntities'
type TJobControlConfig = {
hideLogs?: boolean
runnerTemplates?: TTemplate[]
title?: string
}

const defaultConfig: TJobControlConfig = {
Expand Down Expand Up @@ -166,100 +167,87 @@ export const JobControl = (props: IUIPlugin) => {
throw new Error(JSON.stringify(error || jobEntityError, null, 2))

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=' dm-plugin-padding flex-col border rounded-md bg-equinor-lightgray'>
{internalConfig.title && <h2>{config.title}</h2>}
{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>
)}
<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 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.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)
)}
/>
</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>
</JobButtonWrapper>

{!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)
)}
/>
</div>
)}
</JobButtonWrapper>

{status === JobStatus.Running && progress !== null && (
<div className='px-4 pb-2'>
<Progress progress={progress} />
</div>
)}
{status === JobStatus.Running && progress !== null && (
<div className='px-4 pb-2'>
<Progress progress={progress} />
</div>
</div>
)}
</div>
)
}
33 changes: 23 additions & 10 deletions packages/dm-core-plugins/src/job/JobCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface TJobPluginConfig {
showGetResult?: boolean
jobTemplates: TTemplate[]
hideLogs?: boolean
title?: string
}

export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
Expand Down Expand Up @@ -165,7 +166,12 @@ export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
if (jobDocument.type === EBlueprint.RECURRING_JOB) setAsCronJob(true)
}, [jobDocument])
return (
<div className={'flex-col'}>
<div
className={
'dm-plugin-padding flex-col border rounded-md bg-equinor-lightgray'
}
>
{config.title && <h2>{config.title}</h2>}
{config.recurring !== false && (
<ConfigureRecurring
asCron={asCronJob}
Expand All @@ -185,15 +191,22 @@ export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
/>
)}
<JobButtonWrapper>
{getControlButton(
status,
deregister,
createAndStartJob,
false,
jobIsLoading
)}
{!config.hideLogs && <JobLog logs={logs} error={error} />}
<Chip variant={getVariant(status)}>{status ?? 'Not registered'}</Chip>
<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: `}>
Expand Down

0 comments on commit 4ba3f6c

Please sign in to comment.