market/src/components/Asset/AssetContent/index.tsx

99 lines
3.0 KiB
TypeScript
Raw Normal View History

import React, { ReactElement } from 'react'
import Markdown from '@shared/Markdown'
import MetaFull from './MetaFull'
import MetaSecondary from './MetaSecondary'
2020-07-08 17:57:53 +02:00
import AssetActions from '../AssetActions'
2021-10-13 18:48:59 +02:00
import { useUserPreferences } from '@context/UserPreferences'
import Bookmark from './Bookmark'
2021-10-18 20:44:33 +02:00
import { useAsset } from '@context/Asset'
2021-10-13 18:48:59 +02:00
import Alert from '@shared/atoms/Alert'
2021-10-18 20:44:33 +02:00
import DebugOutput from '@shared/DebugOutput'
import MetaMain from './MetaMain'
import EditHistory from './EditHistory'
Edit compute dataset (#417) * WIP * created form for editing compute privacy * used editComputePrivacy method * select and update trusted algorithm * display and select multiple trusted algorithms * fixed update when trusted algorithm list not changed * code refactoring * moved separator inside condition * moved functions and interface from EditComputeDataset component * moved algorithmOptions to parent component * used AssetSelection to display algorithms * use AssetSelection to select trusted algorithms * getAlgorithmsOptions function review * review fixes * removed unused imports * merge fixes * AssetSelection style & usability tweaks * use custom radio & checkbox styles * add simple search for name & DID * spacing adjustments * copy updates, remove raw algo input, hardcode allowRawAlgorithm * copy * AssetSelection usability tweaks * make rows clickable * tweak layout, style and markup * use formik set function to update values * sorted algorithm list, added checked field * sort assetSelection list on user select * fix getAlgorithmsForAssetSelection breaking on empty responses * form debug output * another empty publisherTrustedAlgorithms fix * created separate algorithms state for the form, sort list on edit * refactor * use Formik functionality wherever possible * unify transforming form data to final data * fix form debug transformation * fix form submit, fix defaultChecked * refactor * use Formik functionality wherever possible * unify transforming form data to final data * fix form debug transformation * fix form submit, fix defaultChecked * disable assetSelection when allowAllAlgorithms is true * added loader to AssetSelection * changed allowAllAlgorithms to allowAllPublishedAlgorithms * fixed lint error * updated transformComputeFormToServiceComputePrivacy * lint fix * modify publish defaults Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-03-25 08:34:07 +01:00
import styles from './index.module.css'
2021-10-18 20:44:33 +02:00
import NetworkName from '@shared/NetworkName'
import content from '../../../../content/purgatory.json'
import { AssetExtended } from 'src/@types/AssetExtended'
export default function AssetContent({
asset
}: {
asset: AssetExtended
}): ReactElement {
2020-09-09 16:07:37 +02:00
const { debug } = useUserPreferences()
const { isInPurgatory, purgatoryData } = useAsset()
Edit compute dataset (#417) * WIP * created form for editing compute privacy * used editComputePrivacy method * select and update trusted algorithm * display and select multiple trusted algorithms * fixed update when trusted algorithm list not changed * code refactoring * moved separator inside condition * moved functions and interface from EditComputeDataset component * moved algorithmOptions to parent component * used AssetSelection to display algorithms * use AssetSelection to select trusted algorithms * getAlgorithmsOptions function review * review fixes * removed unused imports * merge fixes * AssetSelection style & usability tweaks * use custom radio & checkbox styles * add simple search for name & DID * spacing adjustments * copy updates, remove raw algo input, hardcode allowRawAlgorithm * copy * AssetSelection usability tweaks * make rows clickable * tweak layout, style and markup * use formik set function to update values * sorted algorithm list, added checked field * sort assetSelection list on user select * fix getAlgorithmsForAssetSelection breaking on empty responses * form debug output * another empty publisherTrustedAlgorithms fix * created separate algorithms state for the form, sort list on edit * refactor * use Formik functionality wherever possible * unify transforming form data to final data * fix form debug transformation * fix form submit, fix defaultChecked * refactor * use Formik functionality wherever possible * unify transforming form data to final data * fix form debug transformation * fix form submit, fix defaultChecked * disable assetSelection when allowAllAlgorithms is true * added loader to AssetSelection * changed allowAllAlgorithms to allowAllPublishedAlgorithms * fixed lint error * updated transformComputeFormToServiceComputePrivacy * lint fix * modify publish defaults Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-03-25 08:34:07 +01:00
return (
<>
<div className={styles.networkWrap}>
<NetworkName networkId={asset?.chainId} className={styles.network} />
</div>
<article className={styles.grid}>
<div>
<div className={styles.content}>
<MetaMain ddo={asset} />
{asset?.accessDetails?.datatoken !== null && (
<Bookmark did={asset?.id} />
)}
{isInPurgatory === true ? (
<Alert
title={content.asset.title}
badge={`Reason: ${purgatoryData?.reason}`}
text={content.asset.description}
state="error"
/>
) : (
<>
<Markdown
className={styles.description}
text={asset?.metadata.description || ''}
/>
<MetaSecondary ddo={asset} />
</>
)}
<MetaFull ddo={asset} />
<EditHistory />
{debug === true && <DebugOutput title="DDO" output={asset} />}
</div>
2020-10-20 20:56:54 +02:00
</div>
<div className={styles.actions}>
<AssetActions asset={asset} />
{/*
TODO: restore edit actions, ideally put edit screens on new page
with own URL instead of switching out AssetContent in place.
Simple way would be modal usage
*/}
{/* {isOwner && isAssetNetwork && (
<div className={styles.ownerActions}>
<Button
style="text"
size="small"
onClick={handleEditButton}
>
Edit Metadata
</Button>
{serviceCompute && ddo?.metadata.type === 'dataset' && (
<>
<span className={styles.separator}>|</span>
<Button
style="text"
size="small"
onClick={handleEditComputeButton}
>
Edit Compute Settings
</Button>
</>
)}
</div>
)} */}
</div>
</article>
</>
)
}