mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
refactor to use optional chain expressions
This commit is contained in:
parent
a4510459f1
commit
acfa0b8d06
@ -53,8 +53,7 @@ export default function Input(props: Partial<InputProps>): ReactElement {
|
|||||||
} = props
|
} = props
|
||||||
|
|
||||||
const hasError =
|
const hasError =
|
||||||
props.form &&
|
props.form?.touched[field.name] &&
|
||||||
props.form.touched[field.name] &&
|
|
||||||
typeof props.form.errors[field.name] === 'string'
|
typeof props.form.errors[field.name] === 'string'
|
||||||
|
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
@ -65,7 +64,7 @@ export default function Input(props: Partial<InputProps>): ReactElement {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styleClasses}
|
className={styleClasses}
|
||||||
data-is-submitting={props.form && props.form.isSubmitting ? true : null}
|
data-is-submitting={props.form?.isSubmitting ? true : null}
|
||||||
>
|
>
|
||||||
<Label htmlFor={name} required={required}>
|
<Label htmlFor={name} required={required}>
|
||||||
{label}
|
{label}
|
||||||
|
@ -22,14 +22,14 @@ export default function Price({
|
|||||||
|
|
||||||
return !ocean ? (
|
return !ocean ? (
|
||||||
<div className={styles.empty}>Connect your wallet to view price</div>
|
<div className={styles.empty}>Connect your wallet to view price</div>
|
||||||
) : price && price.value ? (
|
) : price?.value ? (
|
||||||
<PriceUnit
|
<PriceUnit
|
||||||
price={price.value}
|
price={price.value}
|
||||||
className={className}
|
className={className}
|
||||||
small={small}
|
small={small}
|
||||||
conversion={conversion}
|
conversion={conversion}
|
||||||
/>
|
/>
|
||||||
) : price && price.value === '' ? (
|
) : price?.value === '' ? (
|
||||||
<div className={styles.empty}>
|
<div className={styles.empty}>
|
||||||
No price found{' '}
|
No price found{' '}
|
||||||
<Tooltip content="We could not find a pool for this data set, which can have multiple reasons. Is your wallet connected to the correct network?" />
|
<Tooltip content="We could not find a pool for this data set, which can have multiple reasons. Is your wallet connected to the correct network?" />
|
||||||
|
@ -25,7 +25,7 @@ export default function Table({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{data && data.length ? (
|
{data?.length ? (
|
||||||
<DataTable noHeader columns={columns} data={data} />
|
<DataTable noHeader columns={columns} data={data} />
|
||||||
) : (
|
) : (
|
||||||
<div>No Data Sets Yet.</div>
|
<div>No Data Sets Yet.</div>
|
||||||
|
@ -41,10 +41,9 @@ const Tags: React.FC<TagsProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
{tags &&
|
{tags?.map((tag) => (
|
||||||
tags.map((tag) => (
|
<Tag tag={tag} noLinks={noLinks} key={shortid.generate()} />
|
||||||
<Tag tag={tag} noLinks={noLinks} key={shortid.generate()} />
|
))}
|
||||||
))}
|
|
||||||
{shouldShowMore && (
|
{shouldShowMore && (
|
||||||
<span className={styles.more}>{`+ ${items.length - max} more`}</span>
|
<span className={styles.more}>{`+ ${items.length - max} more`}</span>
|
||||||
)}
|
)}
|
||||||
|
@ -68,7 +68,7 @@ export default function Dynamic({
|
|||||||
<FormHelp className={stylesIndex.help}>{content.info}</FormHelp>
|
<FormHelp className={stylesIndex.help}>{content.info}</FormHelp>
|
||||||
|
|
||||||
<aside className={styles.wallet}>
|
<aside className={styles.wallet}>
|
||||||
{balance && balance.ocean && (
|
{balance?.ocean && (
|
||||||
<div className={styles.balance}>
|
<div className={styles.balance}>
|
||||||
OCEAN <strong>{balance.ocean}</strong>
|
OCEAN <strong>{balance.ocean}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,7 +19,7 @@ function MenuLink({ item }: { item: MenuItem }) {
|
|||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
|
||||||
const classes =
|
const classes =
|
||||||
location && location.pathname === item.link
|
location?.pathname === item.link
|
||||||
? `${styles.link} ${styles.active}`
|
? `${styles.link} ${styles.active}`
|
||||||
: styles.link
|
: styles.link
|
||||||
|
|
||||||
|
@ -12,31 +12,29 @@ export default function MetaSecondary({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
return (
|
return (
|
||||||
<aside className={styles.metaSecondary}>
|
<aside className={styles.metaSecondary}>
|
||||||
{metadata?.additionalInformation?.tags &&
|
{metadata?.additionalInformation?.tags.length > 0 && (
|
||||||
metadata?.additionalInformation?.tags.length > 0 && (
|
<Tags items={metadata?.additionalInformation?.tags} />
|
||||||
<Tags items={metadata?.additionalInformation?.tags} />
|
)}
|
||||||
)}
|
|
||||||
|
|
||||||
{metadata?.additionalInformation?.links &&
|
{metadata?.additionalInformation?.links.length && (
|
||||||
metadata?.additionalInformation?.links.length && (
|
<div className={styles.samples}>
|
||||||
<div className={styles.samples}>
|
<MetaItem
|
||||||
<MetaItem
|
title="Sample Data"
|
||||||
title="Sample Data"
|
content={
|
||||||
content={
|
<Button
|
||||||
<Button
|
href={metadata?.additionalInformation?.links[0].url}
|
||||||
href={metadata?.additionalInformation?.links[0].url}
|
target="_blank"
|
||||||
target="_blank"
|
rel="noreferrer"
|
||||||
rel="noreferrer"
|
download
|
||||||
download
|
style="text"
|
||||||
style="text"
|
size="small"
|
||||||
size="small"
|
>
|
||||||
>
|
Download Sample
|
||||||
Download Sample
|
</Button>
|
||||||
</Button>
|
}
|
||||||
}
|
/>
|
||||||
/>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
|
||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,15 @@ export default function AssetContent({
|
|||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<aside className={styles.meta}>
|
<aside className={styles.meta}>
|
||||||
<p>{datePublished && <Time date={datePublished} />}</p>
|
<p>{datePublished && <Time date={datePublished} />}</p>
|
||||||
{metadata?.additionalInformation?.categories &&
|
{metadata?.additionalInformation?.categories?.length && (
|
||||||
metadata?.additionalInformation?.categories?.length && (
|
<p>
|
||||||
<p>
|
<Link
|
||||||
<Link
|
to={`/search?categories=["${metadata?.additionalInformation?.categories[0]}"]`}
|
||||||
to={`/search?categories=["${metadata?.additionalInformation?.categories[0]}"]`}
|
>
|
||||||
>
|
{metadata?.additionalInformation?.categories[0]}
|
||||||
{metadata?.additionalInformation?.categories[0]}
|
</Link>
|
||||||
</Link>
|
</p>
|
||||||
</p>
|
)}
|
||||||
)}
|
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<Markdown text={metadata?.additionalInformation?.description || ''} />
|
<Markdown text={metadata?.additionalInformation?.description || ''} />
|
||||||
|
@ -43,7 +43,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.assetList}>
|
<div className={styles.assetList}>
|
||||||
{queryResult && queryResult.totalResults > 0 ? (
|
{queryResult?.totalResults > 0 ? (
|
||||||
queryResult.results.map((ddo: DDO) => {
|
queryResult.results.map((ddo: DDO) => {
|
||||||
const { attributes } = ddo.findServiceByType('metadata')
|
const { attributes } = ddo.findServiceByType('metadata')
|
||||||
|
|
||||||
|
@ -28,20 +28,18 @@ export default function Preview({
|
|||||||
small
|
small
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{values.links &&
|
{typeof values.links !== 'string' && values.links?.length && (
|
||||||
typeof values.links !== 'string' &&
|
<Button
|
||||||
values.links.length && (
|
href={(values.links[0] as FileMetadata).url}
|
||||||
<Button
|
target="_blank"
|
||||||
href={(values.links[0] as FileMetadata).url}
|
rel="noreferrer"
|
||||||
target="_blank"
|
download
|
||||||
rel="noreferrer"
|
style="text"
|
||||||
download
|
size="small"
|
||||||
style="text"
|
>
|
||||||
size="small"
|
Download Sample
|
||||||
>
|
</Button>
|
||||||
Download Sample
|
)}
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{values.tags && <Tags items={values.tags.split(',')} />}
|
{values.tags && <Tags items={values.tags.split(',')} />}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
@ -42,11 +42,9 @@ function UserPreferencesProvider({
|
|||||||
const localStorage = getLocalStorage()
|
const localStorage = getLocalStorage()
|
||||||
|
|
||||||
// Set default values from localStorage
|
// Set default values from localStorage
|
||||||
const [debug, setDebug] = useState<boolean>(
|
const [debug, setDebug] = useState<boolean>(localStorage?.debug || false)
|
||||||
(localStorage && localStorage.debug) || false
|
|
||||||
)
|
|
||||||
const [currency, setCurrency] = useState<string>(
|
const [currency, setCurrency] = useState<string>(
|
||||||
(localStorage && localStorage.currency) || 'EUR'
|
localStorage?.currency || 'EUR'
|
||||||
)
|
)
|
||||||
|
|
||||||
// Write values to localStorage on change
|
// Write values to localStorage on change
|
||||||
|
@ -11,7 +11,7 @@ describe('Button', () => {
|
|||||||
const button = container.querySelector('button')
|
const button = container.querySelector('button')
|
||||||
expect(button).toBeInTheDocument()
|
expect(button).toBeInTheDocument()
|
||||||
expect(button).toHaveTextContent('primary')
|
expect(button).toHaveTextContent('primary')
|
||||||
expect(button && button.className).toMatch(/primary/)
|
expect(button?.className).toMatch(/primary/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('href renders correctly without crashing', () => {
|
it('href renders correctly without crashing', () => {
|
||||||
@ -31,6 +31,6 @@ describe('Button', () => {
|
|||||||
const button = container.querySelector('button')
|
const button = container.querySelector('button')
|
||||||
expect(button).toBeInTheDocument()
|
expect(button).toBeInTheDocument()
|
||||||
expect(button).toHaveTextContent('text')
|
expect(button).toHaveTextContent('text')
|
||||||
expect(button && button.className).toMatch(/text/)
|
expect(button?.className).toMatch(/text/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user