From 871a7d63b2c9c08eec8998b0be7fc3fda2ced6ef Mon Sep 17 00:00:00 2001 From: Henrik Bossart Date: Wed, 13 Sep 2023 15:35:20 +0200 Subject: [PATCH] Make changes to the Job plugin UI --- .../job-ui-single/pages/CreateJobEntity.tsx | 54 +++++++------- .../job-ui-single/pages/JobControl.tsx | 73 ++++++++++++------- .../plugins/job-ui-single/pages/JobPlugin.tsx | 28 ++++--- 3 files changed, 87 insertions(+), 68 deletions(-) diff --git a/example/src/plugins/job-ui-single/pages/CreateJobEntity.tsx b/example/src/plugins/job-ui-single/pages/CreateJobEntity.tsx index de1669173..35cd92f0c 100644 --- a/example/src/plugins/job-ui-single/pages/CreateJobEntity.tsx +++ b/example/src/plugins/job-ui-single/pages/CreateJobEntity.tsx @@ -1,15 +1,13 @@ import { - EBlueprint, ErrorResponse, - Stack, TGenericObject, TJob, splitAddress, useDMSS, } from '@development-framework/dm-core' -import { Button, Card, Typography } from '@equinor/eds-core-react' +import { Button, Typography } from '@equinor/eds-core-react' import { AxiosError, AxiosResponse } from 'axios' -import React, { useEffect, useState } from 'react' +import React, { useState } from 'react' import { JobForm } from './JobForm' type TCreateJobEntityProps = { @@ -98,7 +96,6 @@ export const CreateJobEntity = (props: TCreateJobEntityProps) => { } } - // TODO: Implement document check DmssApi.documentCheck({ address: jobEntityDestination, }).then((response: AxiosResponse) => @@ -130,31 +127,34 @@ export const CreateJobEntity = (props: TCreateJobEntityProps) => { return (
- -

Create new object of type: {EBlueprint.JOB}

- {defaultJobEntity ? ( - <> + {defaultJobEntity ? ( +
+ Create new job + +

- Using default job entity. Will be saved to destination{' '} - {jobEntityDestination} + This will create a new job with a default job entity. The job will + be saved to the following destination:

- - - ) : ( - { - createJobEntity(jobEntityFormData as TJob) + +
{jobEntityDestination}
+
+ +
+ ) : ( + { + createJobEntity(jobEntityFormData as TJob) + }} + defaultJobOutputTarget={defaultJobOutputTarget} + /> + )}
) } diff --git a/example/src/plugins/job-ui-single/pages/JobControl.tsx b/example/src/plugins/job-ui-single/pages/JobControl.tsx index 028a2e9f6..4ef1791ff 100644 --- a/example/src/plugins/job-ui-single/pages/JobControl.tsx +++ b/example/src/plugins/job-ui-single/pages/JobControl.tsx @@ -4,8 +4,8 @@ import { Loading, useJob, } from '@development-framework/dm-core' -import React, {useContext, useState} from 'react' -import { Button, Chip, Icon } from '@equinor/eds-core-react' +import React, { useState } from 'react' +import {Button, Card, Icon} from '@equinor/eds-core-react' import { stop, play, refresh, autorenew } from '@equinor/eds-icons' import styled from 'styled-components' @@ -21,7 +21,7 @@ export const JobControl = (props: { jobEntityId: string }) => { start, error, isLoading, - // fetchResult, + fetchResult, fetchStatusAndLogs, logs, status, @@ -34,8 +34,8 @@ export const JobControl = (props: { jobEntityId: string }) => { if (error) console.error(error) return ( -
- Status: {status} +
+ {/*Status: {status}*/} {jobIsStarted ? ( )} - {(status === JobStatus.Completed || status === JobStatus.Failed) && } + aria-label="Re-run job" + > + + + )} {/* TODO: Make this button query the API for an update on the running job */} - {status === JobStatus.Running && } - {/* The results should be loaded automatically when the job is finished, and loaded initially if a result is available */} - {/**/} - {/* fetchResult().then((res: GetJobResultResponse) => setResult(res))*/} - {/* }*/} - {/* variant={'outlined'}*/} - {/* disabled={status === JobStatus.NotStarted}*/} - {/*>*/} - {/* Get results*/} - {/**/} + {status === JobStatus.Running && ( + + )} + + + + Job status: {status} + + + {(error || logs) && ( + <> +

Logs:

+ {error ? ( +
{JSON.stringify(error, null, 2)}
+ ) : ( +
{logs}
+ )} + + )} -

Logs:

- {error ?
{JSON.stringify(error, null, 2)}
:
{logs}
} -

Result:

{result && ( <> +

Result:

{result.message}
{result.result}
diff --git a/example/src/plugins/job-ui-single/pages/JobPlugin.tsx b/example/src/plugins/job-ui-single/pages/JobPlugin.tsx index 73888c059..2e0bb51ef 100644 --- a/example/src/plugins/job-ui-single/pages/JobPlugin.tsx +++ b/example/src/plugins/job-ui-single/pages/JobPlugin.tsx @@ -2,9 +2,10 @@ import { EBlueprint, JobStatus, TJob, - IUIPlugin, splitAddress, useDMSS, + IUIPlugin, + useDMSS, } from '@development-framework/dm-core' -import React, {useEffect, useState} from 'react' +import React, { useEffect, useState } from 'react' import { JobControl } from './JobControl' import { CreateJobEntity } from './CreateJobEntity' @@ -12,7 +13,7 @@ import { CreateJobEntity } from './CreateJobEntity' export const JobPlugin = (props: IUIPlugin) => { // TODO make this plugin general and move to dm-core-packages/packages/dm-core-plugins. Right now, it can only be used in the SignalApp due to hard coded values. - const DmssApi = useDMSS(); + const DmssApi = useDMSS() const [jobEntityId, setJobEntityId] = useState('') const [jobExists, setJobExists] = useState(false) const jobEntityDestination = `DemoDataSource/$4483c9b0-d505-46c9-a157-94c79f4d7a6a.study.cases[0].job` @@ -66,18 +67,15 @@ export const JobPlugin = (props: IUIPlugin) => { started: 'Not started', } - function fetchJobIfExists(): void { - const addressObject =splitAddress(jobEntityDestination) - const addressPath = `${addressObject.dataSource}/${addressObject.documentPath}` + // const addressObject =splitAddress(jobEntityDestination) + // const addressPath = `${addressObject.dataSource}/${addressObject.documentPath}` DmssApi.documentCheck({ - address: addressPath, + address: jobEntityDestination, }).then((res) => { - console.log(res) if (res.data) { - DmssApi.documentGet({ address: addressPath }).then((resp) => { - console.log(resp) - setJobEntityId(addressPath) + DmssApi.documentGet({ address: jobEntityDestination }).then((resp) => { + setJobEntityId(jobEntityDestination) setJobExists(true) }) } @@ -85,18 +83,18 @@ export const JobPlugin = (props: IUIPlugin) => { } useEffect(fetchJobIfExists, []) - - return (
{/*// TODO do not include CreateJobEntity component if entity exists in destination*/} {/*TODO have a way to check if an entity of type job already exists in 'jobEntityDestination'. Must scan content of entire package if jobEntityDestination is a package, but its simpler to check if jobEntityDestination is refering to an object's attribute. */} - {!jobExists && setJobEntityId(jobEntityId)} defaultJobOutputTarget={props.idReference + '.signal'} defaultJobEntity={defaultJobEntity} - />} + /> + )} {jobEntityId && }
)