1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-09-28 03:58:59 +02:00

Merge pull request #66 from oceanprotocol/feature/sample

add sample file during publish
This commit is contained in:
Matthias Kretschmann 2020-09-02 14:24:49 +02:00 committed by GitHub
commit c8d3565d21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 54 additions and 41 deletions

View File

@ -20,12 +20,19 @@
}, },
{ {
"name": "files", "name": "files",
"label": "Files", "label": "File",
"placeholder": "e.g. https://file.com/file.json", "placeholder": "e.g. https://file.com/file.json",
"help": "Please provide a URL to your data set file.", "help": "Please provide a URL to your data set file. This URL will be stored encrypted after publishing.",
"type": "files", "type": "files",
"required": true "required": true
}, },
{
"name": "links",
"label": "Sample file",
"placeholder": "e.g. https://file.com/samplefile.json",
"help": "Please provide a URL to a sample of your data set file. This file should reveal the data structure of your data set, e.g. by including the header and one line of a CSV file. This file URL will be publicly available after publishing.",
"type": "files"
},
{ {
"name": "access", "name": "access",
"label": "Access Type", "label": "Access Type",

View File

@ -17,6 +17,8 @@ interface ButtonProps {
style?: 'primary' | 'ghost' | 'text' style?: 'primary' | 'ghost' | 'text'
type?: 'submit' type?: 'submit'
download?: boolean download?: boolean
target?: string
rel?: string
} }
export default function Button({ export default function Button({

View File

@ -23,7 +23,7 @@ export default function FilesInput(props: InputProps): ReactElement {
const newFileInfo = await getFileInfo(url) const newFileInfo = await getFileInfo(url)
newFileInfo && helpers.setValue([newFileInfo]) newFileInfo && helpers.setValue([newFileInfo])
} catch (error) { } catch (error) {
toast.error('Could not fetch file info. Please check url and try again') toast.error('Could not fetch file info. Please check URL and try again')
console.error(error.message) console.error(error.message)
} finally { } finally {
setIsLoading(false) setIsLoading(false)

View File

@ -1,10 +1,9 @@
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import shortid from 'shortid'
import { ListItem } from '../../atoms/Lists'
import MetaItem from './MetaItem' import MetaItem from './MetaItem'
import styles from './MetaSecondary.module.css' import styles from './MetaSecondary.module.css'
import { MetadataMarket } from '../../../@types/Metadata' import { MetadataMarket } from '../../../@types/Metadata'
import Tags from '../../atoms/Tags' import Tags from '../../atoms/Tags'
import Button from '../../atoms/Button'
export default function MetaSecondary({ export default function MetaSecondary({
metadata metadata
@ -15,18 +14,21 @@ export default function MetaSecondary({
return ( return (
<aside className={styles.metaSecondary}> <aside className={styles.metaSecondary}>
{links && ( {links && links.length && (
<div className={styles.samples}> <div className={styles.samples}>
<MetaItem <MetaItem
title="Sample Data" title="Sample Data"
content={ content={
<ul> <Button
{links?.map((link) => ( href={links[0].url}
<ListItem key={shortid.generate()}> target="_blank"
<a href={link.url}>{link.name}</a> rel="noreferrer"
</ListItem> download
))} style="text"
</ul> size="small"
>
Download Sample
</Button>
} }
/> />
</div> </div>

View File

@ -27,7 +27,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>
{categories && ( {categories && categories.length && (
<p> <p>
<Link to={`/search?categories=["${categories[0]}"]`}> <Link to={`/search?categories=["${categories[0]}"]`}>
{categories[0]} {categories[0]}

View File

@ -6,6 +6,7 @@ import MetaItem from '../../organisms/AssetContent/MetaItem'
import styles from './Preview.module.css' import styles from './Preview.module.css'
import File from '../../atoms/File' import File from '../../atoms/File'
import { MetadataPublishForm } from '../../../@types/MetaData' import { MetadataPublishForm } from '../../../@types/MetaData'
import Button from '../../atoms/Button'
export default function Preview({ export default function Preview({
values values
@ -18,13 +19,29 @@ export default function Preview({
<header> <header>
{values.name && <h3 className={styles.title}>{values.name}</h3>} {values.name && <h3 className={styles.title}>{values.name}</h3>}
{values.description && <Markdown text={values.description} />} {values.description && <Markdown text={values.description} />}
{values.files && values.files.length && ( {values.files &&
typeof values.files !== 'string' &&
values.files.length > 0 && (
<File <File
file={values.files[0] as FileMetadata} file={values.files[0] as FileMetadata}
className={styles.file} className={styles.file}
small small
/> />
)} )}
{values.links &&
typeof values.links !== 'string' &&
values.links.length && (
<Button
href={(values.links[0] as FileMetadata).url}
target="_blank"
rel="noreferrer"
download
style="text"
size="small"
>
Download Sample
</Button>
)}
{values.tags && <Tags items={values.tags.split(',')} />} {values.tags && <Tags items={values.tags.split(',')} />}
</header> </header>
@ -37,6 +54,7 @@ export default function Preview({
key.includes('description') || key.includes('description') ||
key.includes('tags') || key.includes('tags') ||
key.includes('files') || key.includes('files') ||
key.includes('links') ||
key.includes('termsAndConditions') || key.includes('termsAndConditions') ||
key.includes('price') || key.includes('price') ||
value === undefined || value === undefined ||

View File

@ -1,6 +1,6 @@
import React, { ReactElement, useEffect, FormEvent } from 'react' import React, { ReactElement, useEffect, FormEvent } from 'react'
import styles from './PublishForm.module.css' import styles from './PublishForm.module.css'
import { useOcean, usePublish } from '@oceanprotocol/react' import { useOcean } from '@oceanprotocol/react'
import { useFormikContext, Form, Field } from 'formik' import { useFormikContext, Form, Field } from 'formik'
import Input from '../../atoms/Input' import Input from '../../atoms/Input'
import Button from '../../atoms/Button' import Button from '../../atoms/Button'
@ -25,7 +25,6 @@ export default function PublishForm({
setErrors, setErrors,
setTouched, setTouched,
resetForm, resetForm,
setValues,
initialValues initialValues
} = useFormikContext() } = useFormikContext()
const formName = 'ocean-publish-form' const formName = 'ocean-publish-form'

View File

@ -27,12 +27,6 @@ export default function PublishPage({
values: MetadataPublishForm, values: MetadataPublishForm,
resetForm: () => void resetForm: () => void
): Promise<void> { ): Promise<void> {
// console.log(`
// Collected form values:
// ----------------------
// ${JSON.stringify(values, null, 2)}
// `)
const metadata = transformPublishFormToMetadata(values) const metadata = transformPublishFormToMetadata(values)
const { const {
tokensToMint, tokensToMint,
@ -42,13 +36,6 @@ export default function PublishPage({
} = values.price } = values.price
const serviceType = values.access === 'Download' ? 'access' : 'compute' const serviceType = values.access === 'Download' ? 'access' : 'compute'
// console.log(`
// Transformed metadata values:
// ----------------------
// ${JSON.stringify(metadata, null, 2)}
// Tokens to mint: ${tokensToMint}
// `)
try { try {
// mpAddress and mpFee are not yet implemented in ocean js so are not uset // mpAddress and mpFee are not yet implemented in ocean js so are not uset
const ddo = await publish( const ddo = await publish(

View File

@ -35,9 +35,7 @@ export function transformPublishFormToMetadata(
description, description,
copyrightHolder, copyrightHolder,
tags: tags?.split(','), tags: tags?.split(','),
// links: { links: typeof links !== 'string' && links,
// url: links
// },
termsAndConditions, termsAndConditions,
priceType: price.type priceType: price.type
} }

View File

@ -25,7 +25,7 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
// ---- optional fields ---- // ---- optional fields ----
copyrightHolder: Yup.string(), copyrightHolder: Yup.string(),
tags: Yup.string(), tags: Yup.string(),
links: Yup.object<FileMetadata[]>() links: Yup.object<FileMetadata[]>().nullable()
}) })
export const initialValues: MetadataPublishForm = { export const initialValues: MetadataPublishForm = {

View File

@ -50,7 +50,7 @@ export async function getFileInfo(url: string): Promise<FileMetadata> {
data: { url } data: { url }
}) })
if (response.status > 299 || !response.data.result) { if (response.status > 299 || !response.data) {
toast.error('Could not connect to File API') toast.error('Could not connect to File API')
return return
} }