1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

Refetch compute status (#558)

* WIP

* use interval to refetch every minute

* fixes

* get jobs after verifications

* refetch jobs on button click

* fix loading when no jobs, hide refresh button then no jobs

* button UI changes

* styling updates

Co-authored-by: Norbi <katunanorbert@gmai.com>
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
Norbi 2021-05-17 17:04:17 +03:00 committed by GitHub
parent f0ed9f68cb
commit c2d03f94ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 155 additions and 112 deletions

View File

@ -2,3 +2,25 @@
text-transform: uppercase; text-transform: uppercase;
color: var(--color-secondary); color: var(--color-secondary);
} }
.computeTableContainer {
display: flex;
align-items: center;
}
.refresh,
.refresh:first-child {
margin-bottom: calc(var(--spacer) / 2);
margin-left: auto;
margin-right: auto;
display: block;
}
.refresh svg {
display: inline-block;
fill: currentColor;
width: 1em;
height: 1em;
margin-right: calc(var(--spacer) / 6);
margin-bottom: -0.1rem;
}

View File

@ -6,6 +6,7 @@ import { DDO, Logger, Service, Provider } from '@oceanprotocol/lib'
import { ComputeJobMetaData } from '../../../../@types/ComputeJobMetaData' import { ComputeJobMetaData } from '../../../../@types/ComputeJobMetaData'
import Dotdotdot from 'react-dotdotdot' import Dotdotdot from 'react-dotdotdot'
import Table from '../../../atoms/Table' import Table from '../../../atoms/Table'
import Button from '../../../atoms/Button'
import { useOcean } from '../../../../providers/Ocean' import { useOcean } from '../../../../providers/Ocean'
import { gql, useQuery } from '@apollo/client' import { gql, useQuery } from '@apollo/client'
import { useWeb3 } from '../../../../providers/Web3' import { useWeb3 } from '../../../../providers/Web3'
@ -13,8 +14,9 @@ import { queryMetadata } from '../../../../utils/aquarius'
import axios, { CancelToken } from 'axios' import axios, { CancelToken } from 'axios'
import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders' import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders'
import Details from './Details' import Details from './Details'
import styles from './index.module.css'
import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute' import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
import { ReactComponent as Refresh } from '../../../../images/refresh.svg'
import styles from './index.module.css'
const getComputeOrders = gql` const getComputeOrders = gql`
query ComputeOrders($user: String!) { query ComputeOrders($user: String!) {
@ -99,7 +101,7 @@ async function getAssetMetadata(
export default function ComputeJobs(): ReactElement { export default function ComputeJobs(): ReactElement {
const { ocean, account, config } = useOcean() const { ocean, account, config } = useOcean()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(true)
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([]) const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
const { data } = useQuery<ComputeOrders>(getComputeOrders, { const { data } = useQuery<ComputeOrders>(getComputeOrders, {
variables: { variables: {
@ -107,9 +109,6 @@ export default function ComputeJobs(): ReactElement {
} }
}) })
useEffect(() => {
if (data === undefined || !config?.metadataCacheUri) return
async function getJobs() { async function getJobs() {
if (!ocean || !account) return if (!ocean || !account) return
@ -229,11 +228,32 @@ export default function ComputeJobs(): ReactElement {
} finally { } finally {
setIsLoading(false) setIsLoading(false)
} }
return true
}
useEffect(() => {
if (data === undefined || !config?.metadataCacheUri) {
setIsLoading(false)
return
} }
getJobs() getJobs()
}, [ocean, account, data, config?.metadataCacheUri]) }, [ocean, account, data, config?.metadataCacheUri])
return ( return (
<>
{jobs.length > 0 && (
<Button
style="text"
size="small"
title="Refresh compute jobs"
onClick={() => getJobs()}
disabled={isLoading}
className={styles.refresh}
>
<Refresh />
Refresh
</Button>
)}
<Table <Table
columns={columns} columns={columns}
data={jobs} data={jobs}
@ -241,5 +261,6 @@ export default function ComputeJobs(): ReactElement {
defaultSortField="row.dateCreated" defaultSortField="row.dateCreated"
defaultSortAsc={false} defaultSortAsc={false}
/> />
</>
) )
} }