mirror of
https://github.com/oceanprotocol/react-tutorial
synced 2024-11-22 09:47:01 +01:00
compute section restructuring and markup
This commit is contained in:
parent
af3e96c958
commit
a536be4f72
@ -1,7 +1,7 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
import { asset } from './asset'
|
import { asset } from './asset'
|
||||||
import { algoAsset, createComputeService, rawAlgoMeta } from './compute-asset'
|
import { algoAsset, createComputeService, rawAlgoMeta } from './asset-compute'
|
||||||
|
|
||||||
export default function Compute({ ocean, web3 }) {
|
export default function Compute({ ocean, web3 }) {
|
||||||
const [ddoAssetId, setDdoAssetId] = useState('')
|
const [ddoAssetId, setDdoAssetId] = useState('')
|
||||||
@ -83,7 +83,7 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
)
|
)
|
||||||
setJobId(status.jobId)
|
setJobId(status.jobId)
|
||||||
console.log(status)
|
console.log(status)
|
||||||
alert('Job created. You can query for status now')
|
alert('Compute job created. You can query for its status now.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
@ -123,9 +123,11 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
async function updateDdoAssetId(event) {
|
async function updateDdoAssetId(event) {
|
||||||
setDdoAssetId(event.target.value)
|
setDdoAssetId(event.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handlePublishOutputState(event) {
|
async function handlePublishOutputState(event) {
|
||||||
setPublishOutputState(event.target.checked)
|
setPublishOutputState(event.target.checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handlePublishLogState(event) {
|
async function handlePublishLogState(event) {
|
||||||
setPublishLogState(event.target.checked)
|
setPublishLogState(event.target.checked)
|
||||||
}
|
}
|
||||||
@ -136,30 +138,71 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h3>Compute</h3>
|
<h2>Compute</h2>
|
||||||
<ComputeSection>
|
<ComputeSection>
|
||||||
|
<h3>1. Publish Dataset</h3>
|
||||||
<button onClick={publish}>Publish dataset with compute service</button>
|
<button onClick={publish}>Publish dataset with compute service</button>
|
||||||
Asset DID:
|
|
||||||
<input type="text" value={ddoAssetId} onChange={updateDdoAssetId} />
|
<p>
|
||||||
|
<Label for="ddoAssetId">Asset DID</Label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="ddoAssetId"
|
||||||
|
value={ddoAssetId}
|
||||||
|
onChange={updateDdoAssetId}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
</ComputeSection>
|
</ComputeSection>
|
||||||
<ComputeSection>
|
<ComputeSection>
|
||||||
|
<h3>2. Publish Algorithm</h3>
|
||||||
<button onClick={publishalgo}>Publish algorithm</button>
|
<button onClick={publishalgo}>Publish algorithm</button>
|
||||||
Algo DID:
|
<p>
|
||||||
<input type="text" value={ddoAlgorithmId} readOnly />
|
<Label for="ddoAlgorithmId">Algorithm DID</Label>
|
||||||
|
<code id="ddoAlgorithmId">{ddoAlgorithmId}</code>
|
||||||
|
</p>
|
||||||
</ComputeSection>
|
</ComputeSection>
|
||||||
<ComputeSection>
|
<ComputeSection>
|
||||||
|
<h3>3. Start Compute Job</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<Label for="publishOutputState">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
id="publishOutputState"
|
||||||
checked={publishOutputState}
|
checked={publishOutputState}
|
||||||
onChange={handlePublishOutputState}
|
onChange={handlePublishOutputState}
|
||||||
/>
|
/>
|
||||||
Publish Output into the Marketplace
|
Publish Output into the Marketplace
|
||||||
|
</Label>
|
||||||
|
<Label for="publishLogState">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
id="publishLogState"
|
||||||
checked={publishLogState}
|
checked={publishLogState}
|
||||||
onChange={handlePublishLogState}
|
onChange={handlePublishLogState}
|
||||||
/>
|
/>
|
||||||
Publish Algorithm Logs into the Marketplace
|
Publish Algorithm Logs into the Marketplace
|
||||||
|
</Label>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button onClick={showDivAlgo}>Show/Hide Raw Algorithm</button>
|
||||||
|
<p style={{ display: isAlgoInputVisible ? 'block' : 'none' }}>
|
||||||
|
<Label for="jobStatus">Raw Algorithm</Label>
|
||||||
|
<textarea
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
rows="10"
|
||||||
|
value={textRawAlgo}
|
||||||
|
onChange={updateRawAlgoCode}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<Label for="jobId">Compute Job ID</Label>
|
||||||
|
<code>{jobId}</code>
|
||||||
|
</p>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={startWithPublishedAlgo}
|
onClick={startWithPublishedAlgo}
|
||||||
disabled={!ddoAssetId || !ddoAlgorithmId}
|
disabled={!ddoAssetId || !ddoAlgorithmId}
|
||||||
@ -169,24 +212,23 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
<button onClick={startWithRawAlgo} disabled={!ddoAssetId}>
|
<button onClick={startWithRawAlgo} disabled={!ddoAssetId}>
|
||||||
Order and start compute service with raw algorithm
|
Order and start compute service with raw algorithm
|
||||||
</button>
|
</button>
|
||||||
<button onClick={showDivAlgo}>Show/Hide Raw Algo</button>
|
|
||||||
<div style={{ display: isAlgoInputVisible ? 'block' : 'none' }}>
|
|
||||||
<textarea
|
|
||||||
rows="10"
|
|
||||||
cols="120"
|
|
||||||
value={textRawAlgo}
|
|
||||||
onChange={updateRawAlgoCode}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
Job ID:
|
|
||||||
<input type="text" value={jobId} readOnly />
|
|
||||||
</ComputeSection>
|
</ComputeSection>
|
||||||
<ComputeSection>
|
<ComputeSection>
|
||||||
|
<h3>4. Get Compute Job Status</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<Label for="jobStatus">Compute Job Status</Label>
|
||||||
|
<pre
|
||||||
|
id="jobStatus"
|
||||||
|
style={{ padding: '1rem', background: 'ghostwhite' }}
|
||||||
|
>
|
||||||
|
<code>{jobStatus}</code>
|
||||||
|
</pre>
|
||||||
|
</p>
|
||||||
|
|
||||||
<button onClick={getStatus} disabled={!jobId}>
|
<button onClick={getStatus} disabled={!jobId}>
|
||||||
Get Job Status
|
Get Job Status
|
||||||
</button>
|
</button>
|
||||||
Compute status:
|
|
||||||
<textarea rows="15" cols="120" value={jobStatus} readOnly />
|
|
||||||
</ComputeSection>
|
</ComputeSection>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
@ -197,9 +239,10 @@ function ComputeSection({ children }) {
|
|||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
textAlign: 'left',
|
||||||
flexDirection: 'column',
|
paddingBottom: '1rem',
|
||||||
alignItems: 'center'
|
maxWidth: '40rem',
|
||||||
|
margin: '1rem auto'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@ -208,3 +251,11 @@ function ComputeSection({ children }) {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Label({ children, ...props }) {
|
||||||
|
return (
|
||||||
|
<label style={{ display: 'block', fontSize: '0.8rem' }} {...props}>
|
||||||
|
{children}
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user