1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

refactor to use optional chain expressions

This commit is contained in:
Matthias Kretschmann 2020-09-10 22:22:16 +02:00
parent a4510459f1
commit acfa0b8d06
Signed by: m
GPG Key ID: 606EEEF3C479A91F
12 changed files with 58 additions and 67 deletions

View File

@ -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}

View File

@ -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?" />

View File

@ -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>

View File

@ -41,8 +41,7 @@ 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 && (

View File

@ -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>

View File

@ -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

View File

@ -12,13 +12,11 @@ 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"

View File

@ -28,8 +28,7 @@ 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]}"]`}

View File

@ -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')

View File

@ -28,9 +28,7 @@ export default function Preview({
small small
/> />
)} )}
{values.links && {typeof values.links !== 'string' && values.links?.length && (
typeof values.links !== 'string' &&
values.links.length && (
<Button <Button
href={(values.links[0] as FileMetadata).url} href={(values.links[0] as FileMetadata).url}
target="_blank" target="_blank"

View File

@ -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

View File

@ -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/)
}) })
}) })