From c49e0b1288f83cd08fdb9e1deea7574b17de0334 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 9 Oct 2020 16:04:55 +0300 Subject: [PATCH] compute fix, compute history Signed-off-by: mihaisc --- src/components/atoms/BaseDialog.module.css | 4 + src/components/atoms/BaseDialog.tsx | 4 +- src/components/atoms/Time.tsx | 6 +- .../organisms/AssetActions/Compute.tsx | 10 +- .../pages/History/ComputeDetailsModal.tsx | 39 +++++ src/components/pages/History/ComputeJobs.tsx | 142 ++++++++++++++++++ .../pages/History/PoolTransactions.tsx | 4 +- src/components/pages/History/index.tsx | 3 +- 8 files changed, 198 insertions(+), 14 deletions(-) create mode 100644 src/components/pages/History/ComputeDetailsModal.tsx create mode 100644 src/components/pages/History/ComputeJobs.tsx diff --git a/src/components/atoms/BaseDialog.module.css b/src/components/atoms/BaseDialog.module.css index 7da7c5bb2..4e19f2430 100644 --- a/src/components/atoms/BaseDialog.module.css +++ b/src/components/atoms/BaseDialog.module.css @@ -4,3 +4,7 @@ border-radius: 15px; margin: auto; } + +.dialogTitle { + margin-top: 30px !important; +} diff --git a/src/components/atoms/BaseDialog.tsx b/src/components/atoms/BaseDialog.tsx index 6c9f659aa..c0a3d21dd 100644 --- a/src/components/atoms/BaseDialog.tsx +++ b/src/components/atoms/BaseDialog.tsx @@ -1,7 +1,7 @@ import React, { ReactNode, ReactElement } from 'react' import styles from './BaseDialog.module.css' import { Modal } from 'react-responsive-modal' - +import 'react-responsive-modal/styles.css' export default function BaseDialog({ open, title, @@ -28,7 +28,7 @@ export default function BaseDialog({ }} {...other} > -

{title}

+

{title}

{children}
) diff --git a/src/components/atoms/Time.tsx b/src/components/atoms/Time.tsx index 7151ca3b4..d78746aad 100644 --- a/src/components/atoms/Time.tsx +++ b/src/components/atoms/Time.tsx @@ -3,12 +3,14 @@ import { format, formatDistance } from 'date-fns' export default function Time({ date, - relative + relative, + isUnix }: { date: string relative?: boolean + isUnix?: boolean }): ReactElement { - const dateNew = new Date(date) + const dateNew = isUnix ? new Date(Number(date) * 1000) : new Date(date) const dateIso = dateNew.toISOString() return ( diff --git a/src/components/organisms/AssetActions/Compute.tsx b/src/components/organisms/AssetActions/Compute.tsx index dc8d2b443..7be014506 100644 --- a/src/components/organisms/AssetActions/Compute.tsx +++ b/src/components/organisms/AssetActions/Compute.tsx @@ -25,17 +25,15 @@ export default function Compute({ }): ReactElement { const { ocean } = useOcean() const { compute, isLoading, computeStepText, computeError } = useCompute() - const computeService = ddo.findServiceByType('compute').attributes.main + const computeService = ddo.findServiceByType('compute') const metadataService = ddo.findServiceByType('metadata') const [isJobStarting, setIsJobStarting] = useState(false) const [, setError] = useState('') const [computeType, setComputeType] = useState('nodejs') - const [computeContainer, setComputeContainer] = useState({ - entrypoint: '', - image: '', - tag: '' - }) + const [computeContainer, setComputeContainer] = useState( + computeOptions[0].value + ) const [algorithmRawCode, setAlgorithmRawCode] = useState('') const [isPublished, setIsPublished] = useState(false) const [file, setFile] = useState(null) diff --git a/src/components/pages/History/ComputeDetailsModal.tsx b/src/components/pages/History/ComputeDetailsModal.tsx new file mode 100644 index 000000000..b1f27731b --- /dev/null +++ b/src/components/pages/History/ComputeDetailsModal.tsx @@ -0,0 +1,39 @@ +import { Logger } from '@oceanprotocol/lib' +import { useOcean } from '@oceanprotocol/react' +import React, { ReactElement, useEffect, useState } from 'react' +import Loader from '../../atoms/Loader' +import AssetList from '../../organisms/AssetList' +import BaseDialog from '../../atoms/BaseDialog' +import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/ComputeJob' + +export default function ComputeDetailsModal({ + computeJob, + open, + onClose +}: { + computeJob: ComputeJob + open: boolean + onClose: () => void +}): ReactElement { + const { ocean, status, accountId } = useOcean() + const [isLoading, setIsLoading] = useState(false) + useEffect(() => { + async function getDetails() { + if (!accountId || !ocean || !computeJob) return + try { + setIsLoading(true) + } catch (error) { + Logger.error(error.message) + } finally { + setIsLoading(false) + } + } + getDetails() + }, [ocean, status, accountId]) + + return ( + + {isLoading ? : <>Details} + + ) +} diff --git a/src/components/pages/History/ComputeJobs.tsx b/src/components/pages/History/ComputeJobs.tsx new file mode 100644 index 000000000..f80c12300 --- /dev/null +++ b/src/components/pages/History/ComputeJobs.tsx @@ -0,0 +1,142 @@ +import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/ComputeJob' +import { useOcean } from '@oceanprotocol/react' +import React, { ReactElement, useState } from 'react' +import DataTable from 'react-data-table-component' +import Time from '../../atoms/Time' +import styles from './PoolTransactions.module.css' +import Loader from '../../atoms/Loader' +import Button from '../../atoms/Button' +import ComputeDetailsModal from './ComputeDetailsModal' + +// function AssetTitle({ row }: { row: ComputeJob }): ReactElement { +// const { ocean } = useOcean() + +// useEffect(() => { +// if (!ocean) return + +// async function getDid() { +// const { did } = await ocean.keeper.agreementStoreManager.getAgreement( +// job.agreementId +// ) +// ocean. + +// const ddo = await ocean.assets.resolve(did) +// } +// getDid() +// }, [ocean, row]) +// return {title || did} +// } + +function DetailsButton({ row }: { row: ComputeJob }): ReactElement { + const [isDialogOpen, setIsDialogOpen] = useState(false) + + return ( + <> + + setIsDialogOpen(false)} + /> + + ) +} + +function Empty() { + return
No results found
+} + +const columns = [ + { + name: 'Created', + selector: function getTimeRow(row: ComputeJob) { + return