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",
"label": "Files",
"label": "File",
"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",
"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",
"label": "Access Type",

View File

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

View File

@ -23,7 +23,7 @@ export default function FilesInput(props: InputProps): ReactElement {
const newFileInfo = await getFileInfo(url)
newFileInfo && helpers.setValue([newFileInfo])
} 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)
} finally {
setIsLoading(false)

View File

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

View File

@ -27,7 +27,7 @@ export default function AssetContent({
<div className={styles.content}>
<aside className={styles.meta}>
<p>{datePublished && <Time date={datePublished} />}</p>
{categories && (
{categories && categories.length && (
<p>
<Link to={`/search?categories=["${categories[0]}"]`}>
{categories[0]}

View File

@ -6,6 +6,7 @@ import MetaItem from '../../organisms/AssetContent/MetaItem'
import styles from './Preview.module.css'
import File from '../../atoms/File'
import { MetadataPublishForm } from '../../../@types/MetaData'
import Button from '../../atoms/Button'
export default function Preview({
values
@ -18,13 +19,29 @@ export default function Preview({
<header>
{values.name && <h3 className={styles.title}>{values.name}</h3>}
{values.description && <Markdown text={values.description} />}
{values.files && values.files.length && (
<File
file={values.files[0] as FileMetadata}
className={styles.file}
small
/>
)}
{values.files &&
typeof values.files !== 'string' &&
values.files.length > 0 && (
<File
file={values.files[0] as FileMetadata}
className={styles.file}
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(',')} />}
</header>
@ -37,6 +54,7 @@ export default function Preview({
key.includes('description') ||
key.includes('tags') ||
key.includes('files') ||
key.includes('links') ||
key.includes('termsAndConditions') ||
key.includes('price') ||
value === undefined ||

View File

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

View File

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

View File

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

View File

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

View File

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