commons/client/src/components/molecules/VersionNumbers/VersionTable.tsx

150 lines
4.4 KiB
TypeScript
Raw Normal View History

2019-06-18 14:35:18 +02:00
import React, { Fragment, useState } from 'react'
import { OceanPlatformTechStatus } from '@oceanprotocol/squid'
2019-06-18 14:35:18 +02:00
import slugify from '@sindresorhus/slugify'
import useCollapse from 'react-collapsed'
import { VersionNumbersState } from '.'
import styles from './VersionTable.module.scss'
const VersionTableContracts = ({
contracts,
network
}: {
contracts: {
[contractName: string]: string
}
network: string
}) => (
<table>
<tbody>
{contracts &&
2019-06-18 13:28:35 +02:00
Object.keys(contracts)
// sort alphabetically
.sort((a, b) => a.localeCompare(b))
.map(key => {
const submarineLink = `https://submarine${
network === 'duero'
? '.duero'
: network === 'pacific'
? '.pacific'
: ''
}.dev-ocean.com/address/${contracts[key]}`
2019-06-18 13:28:35 +02:00
return (
<tr key={key}>
<td>
<span className={styles.label}>{key}</span>
</td>
<td>
<a href={submarineLink}>
<code>{contracts[key]}</code>
</a>
</td>
</tr>
)
})}
</tbody>
</table>
)
2019-06-14 12:31:29 +02:00
const VersionNumber = ({
name,
2019-06-14 12:31:29 +02:00
version,
network,
status
2019-06-14 12:31:29 +02:00
}: {
name: string
version?: string
network?: string
status: OceanPlatformTechStatus
2019-06-14 12:31:29 +02:00
}) =>
version ? (
2019-06-14 12:31:29 +02:00
<>
<a
href={`https://github.com/oceanprotocol/${slugify(
name
2019-06-14 12:31:29 +02:00
)}/releases/tag/v${version}`}
>
<code>v{version}</code>
</a>
{network && `(${network})`}
</>
) : (
<span>{status || 'Could not get version'}</span>
2019-06-14 12:31:29 +02:00
)
2019-06-18 14:35:18 +02:00
const VersionRow = ({ value }: { value: any }) => {
const collapseStyles = {
transitionDuration: '0.1s'
}
const expandStyles = {
transitionDuration: '0.1s'
}
const { getCollapseProps, getToggleProps, isOpen } = useCollapse({
collapseStyles,
expandStyles
})
return (
<>
<tr>
<td>
{value.contracts && (
<button className={styles.handle} {...getToggleProps()}>
{isOpen ? (
<span>&#9660;</span>
) : (
<span>&#9658;</span>
2019-06-18 13:28:35 +02:00
)}
2019-06-18 14:35:18 +02:00
</button>
)}
<a
href={`https://github.com/oceanprotocol/${slugify(
value.name || value.software
)}`}
>
<strong>{value.name}</strong>
</a>
</td>
<td>
<VersionNumber
name={value.name || value.software}
version={value.version}
status={value.status}
network={value.network}
/>
</td>
</tr>
{value.contracts && (
<tr {...getCollapseProps()}>
<td colSpan={2}>
<VersionTableContracts
contracts={value.contracts}
network={value.network || ''}
/>
</td>
</tr>
)}
</>
)
}
const VersionTable = ({ data }: { data: VersionNumbersState }) => {
return (
<div className={styles.tableWrap}>
<table className={styles.table}>
<tbody>
{Object.entries(data)
.filter(([key, value]) => key !== 'status')
.map(([key, value]) => (
<VersionRow key={key} value={value} />
))}
</tbody>
</table>
</div>
)
}
export default VersionTable