1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

compute widget cleanup

This commit is contained in:
Matthias Kretschmann 2020-10-06 15:46:41 +02:00
parent 54b92aa514
commit 93b7b1b6c2
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 66 additions and 64 deletions

View File

@ -1,27 +1,24 @@
.compute { .info {
display: flex; display: flex;
flex-wrap: wrap; align-items: center;
width: auto;
margin-bottom: var(--spacer);
border-bottom: 1px solid var(--brand-grey-lighter);
margin-top: -1rem;
margin-left: -2rem;
margin-right: -2rem;
padding: 0 var(--spacer) calc(var(--spacer) / 2) var(--spacer);
} }
.jobButtonWrapper { .filewrapper {
flex-shrink: 0;
}
.actions {
margin-top: var(--spacer); margin-top: var(--spacer);
text-align: center;
} }
.feedback { .feedback {
width: 100%; width: 100%;
} }
.compute button {
margin-left: var(--spacer);
}
.compute button:first {
margin-left: 0px;
}
.info {
margin-top: var(--spacer);
display: flex;
flex-direction: column;
width: 100%;
}

View File

@ -1,9 +1,10 @@
import React, { useState, ReactElement, ChangeEvent } from 'react' import React, { useState, ReactElement, ChangeEvent } from 'react'
import { DDO } from '@oceanprotocol/lib' import { DDO, Logger } from '@oceanprotocol/lib'
import Loader from '../../atoms/Loader' import Loader from '../../atoms/Loader'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
import Dropzone from '../../atoms/Dropzone' import Dropzone from '../../atoms/Dropzone'
import Price from '../../atoms/Price' import Price from '../../atoms/Price'
import File from '../../atoms/File'
import { import {
computeOptions, computeOptions,
useCompute, useCompute,
@ -25,10 +26,11 @@ export default function Compute({
const { ocean } = useOcean() const { ocean } = useOcean()
const { compute, isLoading, computeStepText, computeError } = useCompute() const { compute, isLoading, computeStepText, computeError } = useCompute()
const computeService = ddo.findServiceByType('compute').attributes.main const computeService = ddo.findServiceByType('compute').attributes.main
const metadataService = ddo.findServiceByType('metadata')
const [isJobStarting, setIsJobStarting] = useState(false) const [isJobStarting, setIsJobStarting] = useState(false)
const [, setError] = useState('') const [, setError] = useState('')
const [computeType, setComputeType] = useState('') const [computeType, setComputeType] = useState('nodejs')
const [computeContainer, setComputeContainer] = useState({ const [computeContainer, setComputeContainer] = useState({
entrypoint: '', entrypoint: '',
image: '', image: '',
@ -39,7 +41,7 @@ export default function Compute({
const [file, setFile] = useState(null) const [file, setFile] = useState(null)
const isComputeButtonDisabled = const isComputeButtonDisabled =
isJobStarting || isJobStarting === true ||
file === null || file === null ||
computeType === '' || computeType === '' ||
!ocean || !ocean ||
@ -80,56 +82,59 @@ export default function Compute({
setFile(null) setFile(null)
} catch (error) { } catch (error) {
setError('Failed to start job!') setError('Failed to start job!')
console.log(error) Logger.error(error.message)
} finally {
setIsJobStarting(false)
} }
setIsJobStarting(false)
} }
return ( return (
<div className={styles.compute}> <>
<Price ddo={ddo} conversion />
<div className={styles.info}> <div className={styles.info}>
<div className={styles.selectType}> <div className={styles.filewrapper}>
<Input <File file={metadataService.attributes.main.files[0]} small />
type="select"
name="algorithm"
label="Select image to run the algorithm"
placeholder=""
value={computeType}
options={computeOptions.map((x) => x.name)}
onChange={handleSelectChange}
/>
</div> </div>
<div> <div className={styles.pricewrapper}>
<Dropzone multiple={false} handleOnDrop={onDrop} /> <Price ddo={ddo} conversion />
<div className={styles.jobButtonWrapper}>
<Button
style="primary"
onClick={() => startJob()}
disabled={isComputeButtonDisabled}
>
Start job
</Button>
</div>
</div> </div>
<footer className={styles.feedback}>
{isLoading && <Loader message={computeStepText} />}
{computeError !== undefined && (
<Alert text={computeError} state="error" />
)}
{isPublished && (
<Alert
title="Your job started!"
text="Watch the progress in the history page."
state="success"
/>
)}
<Web3Feedback isBalanceSufficient={isBalanceSufficient} />
</footer>
</div> </div>
</div>
<Input
type="select"
name="algorithm"
label="Select image to run the algorithm"
placeholder=""
small
value={computeType}
options={computeOptions.map((x) => x.name)}
onChange={handleSelectChange}
/>
<Dropzone multiple={false} handleOnDrop={onDrop} />
<div className={styles.actions}>
<Button
style="primary"
onClick={() => startJob()}
disabled={isComputeButtonDisabled}
>
Start job
</Button>
</div>
<footer className={styles.feedback}>
{isLoading && <Loader message={computeStepText} />}
{computeError !== undefined && (
<Alert text={computeError} state="error" />
)}
{isPublished && (
<Alert
title="Your job started!"
text="Watch the progress in the history page."
state="success"
/>
)}
<Web3Feedback isBalanceSufficient={isBalanceSufficient} />
</footer>
</>
) )
} }