mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
start data flow cleanup
This commit is contained in:
parent
cd88cb41e5
commit
b3e4940d08
@ -51,15 +51,13 @@
|
|||||||
{
|
{
|
||||||
"name": "copyrightHolder",
|
"name": "copyrightHolder",
|
||||||
"label": "Copyright Holder",
|
"label": "Copyright Holder",
|
||||||
"placeholder": "e.g. Marine Institute of Jellyfish",
|
"placeholder": "e.g. Marine Institute of Jellyfish"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "tags",
|
"name": "tags",
|
||||||
"label": "Tags",
|
"label": "Tags",
|
||||||
"placeholder": "e.g. logistics, ai",
|
"placeholder": "e.g. logistics, ai",
|
||||||
"help": "Separate tags with comma.",
|
"help": "Separate tags with comma."
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "license",
|
"name": "license",
|
||||||
|
20
src/@types/MetaData.d.ts
vendored
20
src/@types/MetaData.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { MetaData, AdditionalInformation } from '@oceanprotocol/squid'
|
import { File, MetaData, AdditionalInformation } from '@oceanprotocol/squid'
|
||||||
import { ServiceMetadata } from '@oceanprotocol/squid/dist/node/ddo/Service'
|
import { ServiceMetadata } from '@oceanprotocol/squid/dist/node/ddo/Service'
|
||||||
|
|
||||||
export interface Sample {
|
export interface Sample {
|
||||||
@ -13,13 +13,29 @@ export interface AdditionalInformationMarket extends AdditionalInformation {
|
|||||||
links?: Sample[] // redefine existing key, cause not specific enough in Squid
|
links?: Sample[] // redefine existing key, cause not specific enough in Squid
|
||||||
termsAndConditions: boolean
|
termsAndConditions: boolean
|
||||||
dateRange?: [string, string]
|
dateRange?: [string, string]
|
||||||
access: AccessType
|
access: AccessType | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MetaDataMarket extends MetaData {
|
export interface MetaDataMarket extends MetaData {
|
||||||
additionalInformation: AdditionalInformationMarket
|
additionalInformation: AdditionalInformationMarket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MetaDataPublishForm {
|
||||||
|
// ---- required fields ----
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
files: string
|
||||||
|
termsAndConditions: boolean
|
||||||
|
author: string
|
||||||
|
license: string
|
||||||
|
price: string
|
||||||
|
access: string
|
||||||
|
// ---- optional fields ----
|
||||||
|
copyrightHolder?: string
|
||||||
|
tags?: string
|
||||||
|
links?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface ServiceMetaDataMarket extends ServiceMetadata {
|
export interface ServiceMetaDataMarket extends ServiceMetadata {
|
||||||
attributes: MetaDataMarket
|
attributes: MetaDataMarket
|
||||||
}
|
}
|
||||||
|
@ -69,34 +69,10 @@
|
|||||||
|
|
||||||
.radioGroup {
|
.radioGroup {
|
||||||
margin-top: calc(var(--spacer) / 2);
|
margin-top: calc(var(--spacer) / 2);
|
||||||
margin-bottom: -2%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 40rem) {
|
|
||||||
.radioGroup {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.radioWrap {
|
.radioWrap {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: calc(var(--spacer) / 2);
|
|
||||||
text-align: center;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 2%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 40rem) {
|
|
||||||
.radioWrap {
|
|
||||||
flex: 0 0 49%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.radio:checked + label {
|
|
||||||
border-color: var(--brand-pink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.radioLabel {
|
.radioLabel {
|
||||||
@ -104,19 +80,8 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
font-weight: var(--font-weight-bold);
|
font-weight: var(--font-weight-bold);
|
||||||
font-size: var(--font-size-small);
|
font-size: var(--font-size-small);
|
||||||
line-height: 1.2;
|
|
||||||
border: 1px solid var(--brand-grey-lighter);
|
|
||||||
border-radius: 0.2rem;
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
color: var(--brand-grey);
|
color: var(--brand-grey);
|
||||||
text-align: left;
|
padding-left: 0.5rem;
|
||||||
padding-left: 2.5rem;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Size modifiers */
|
/* Size modifiers */
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import {
|
import * as Yup from 'yup'
|
||||||
initialValues,
|
|
||||||
validationSchema,
|
|
||||||
PublishFormData
|
|
||||||
} from '../../../models/PublishForm'
|
|
||||||
import { MetaData } from '@oceanprotocol/squid'
|
|
||||||
import { toStringNoMS } from '../../../utils'
|
import { toStringNoMS } from '../../../utils'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import styles from './PublishForm.module.css'
|
import styles from './PublishForm.module.css'
|
||||||
@ -18,6 +13,39 @@ import Input from '../../atoms/Input'
|
|||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
import { transformPublishFormToMetadata } from './utils'
|
import { transformPublishFormToMetadata } from './utils'
|
||||||
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
||||||
|
import { MetaDataPublishForm, AccessType } from '../../../@types/MetaData'
|
||||||
|
import AssetModel from '../../../models/Asset'
|
||||||
|
|
||||||
|
const validationSchema = Yup.object().shape<MetaDataPublishForm>({
|
||||||
|
// ---- required fields ----
|
||||||
|
name: Yup.string().required('Required'),
|
||||||
|
author: Yup.string().required('Required'),
|
||||||
|
price: Yup.string().required('Required'),
|
||||||
|
files: Yup.string().required('Required'),
|
||||||
|
description: Yup.string().required('Required'),
|
||||||
|
license: Yup.string().required('Required'),
|
||||||
|
access: Yup.string().required('Required'),
|
||||||
|
termsAndConditions: Yup.boolean().required('Required'),
|
||||||
|
|
||||||
|
// ---- optional fields ----
|
||||||
|
copyrightHolder: Yup.string(),
|
||||||
|
tags: Yup.string(),
|
||||||
|
links: Yup.string()
|
||||||
|
})
|
||||||
|
|
||||||
|
const initialValues: MetaDataPublishForm = {
|
||||||
|
name: undefined,
|
||||||
|
author: undefined,
|
||||||
|
price: undefined,
|
||||||
|
files: undefined,
|
||||||
|
description: undefined,
|
||||||
|
license: undefined,
|
||||||
|
access: undefined,
|
||||||
|
termsAndConditions: undefined,
|
||||||
|
copyrightHolder: undefined,
|
||||||
|
tags: undefined,
|
||||||
|
links: undefined
|
||||||
|
}
|
||||||
|
|
||||||
export default function PublishForm({
|
export default function PublishForm({
|
||||||
content
|
content
|
||||||
@ -26,46 +54,49 @@ export default function PublishForm({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean, account } = useOcean()
|
const { ocean, account } = useOcean()
|
||||||
|
|
||||||
async function handleSubmit(values: PublishFormData) {
|
async function handleSubmit(values: MetaDataPublishForm) {
|
||||||
const submittingToast = toast.info('submitting asset', {
|
const submittingToast = toast.info('submitting asset', {
|
||||||
className: styles.info
|
className: styles.info
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(values)
|
||||||
const metadata = transformPublishFormToMetadata(values)
|
const metadata = transformPublishFormToMetadata(values)
|
||||||
|
console.log(metadata)
|
||||||
|
|
||||||
// if services array stays empty, the default access service
|
// if services array stays empty, the default access service
|
||||||
// will be created by squid-js
|
// will be created by squid-js
|
||||||
let services: Service[] = []
|
// let services: Service[] = []
|
||||||
|
|
||||||
if (metadata.additionalInformation.access === 'Compute') {
|
// if (metadata.additionalInformation.access === 'Compute') {
|
||||||
const computeService: ServiceCompute = await ocean.compute.createComputeServiceAttributes(
|
// const computeService: ServiceCompute = await ocean.compute.createComputeServiceAttributes(
|
||||||
account,
|
// account,
|
||||||
metadata.main.price,
|
// metadata.main.price,
|
||||||
// Note: a hack without consequences.
|
// // Note: a hack without consequences.
|
||||||
// Will make metadata.main.datePublished (automatically created by Aquarius)
|
// // Will make metadata.main.datePublished (automatically created by Aquarius)
|
||||||
// go out of sync with this service.main.datePublished.
|
// // go out of sync with this service.main.datePublished.
|
||||||
toStringNoMS(new Date(Date.now()))
|
// toStringNoMS(new Date(Date.now()))
|
||||||
)
|
// )
|
||||||
services = [computeService]
|
// services = [computeService]
|
||||||
}
|
// }
|
||||||
try {
|
|
||||||
const asset = await ocean.assets.create(
|
|
||||||
(metadata as unknown) as MetaData,
|
|
||||||
account,
|
|
||||||
services
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: Reset the form to initial values
|
// try {
|
||||||
|
// const asset = await ocean.assets.create(
|
||||||
|
// (metadata as unknown) as MetaData,
|
||||||
|
// account,
|
||||||
|
// services
|
||||||
|
// )
|
||||||
|
|
||||||
// User feedback and redirect
|
// // TODO: Reset the form to initial values
|
||||||
toast.success('asset created successfully', {
|
|
||||||
className: styles.success
|
// // User feedback and redirect
|
||||||
})
|
// toast.success('asset created successfully', {
|
||||||
toast.dismiss(submittingToast)
|
// className: styles.success
|
||||||
// navigate(`/asset/${asset.id}`)
|
// })
|
||||||
} catch (e) {
|
// toast.dismiss(submittingToast)
|
||||||
console.error(e.message)
|
// // navigate(`/asset/${asset.id}`)
|
||||||
}
|
// } catch (e) {
|
||||||
|
// console.error(e.message)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -94,7 +125,7 @@ export default function PublishForm({
|
|||||||
!ocean ||
|
!ocean ||
|
||||||
!account ||
|
!account ||
|
||||||
isSubmitting ||
|
isSubmitting ||
|
||||||
!isValid ||
|
//! isValid ||
|
||||||
status === 'empty'
|
status === 'empty'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -2,11 +2,12 @@ import React, { ReactElement } from 'react'
|
|||||||
import PublishForm from './PublishForm'
|
import PublishForm from './PublishForm'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||||
|
import { FormContent } from '../../../@types/Form'
|
||||||
|
|
||||||
export default function PublishPage({
|
export default function PublishPage({
|
||||||
content
|
content
|
||||||
}: {
|
}: {
|
||||||
content: any
|
content: { form: FormContent }
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
return (
|
return (
|
||||||
<article className={styles.grid}>
|
<article className={styles.grid}>
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { PublishFormData } from '../../../models/PublishForm'
|
import { MetaDataMarket, MetaDataPublishForm } from '../../../@types/MetaData'
|
||||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
|
||||||
import { toStringNoMS } from '../../../utils'
|
import { toStringNoMS } from '../../../utils'
|
||||||
import AssetModel from '../../../models/Asset'
|
import AssetModel from '../../../models/Asset'
|
||||||
import web3Utils from 'web3-utils'
|
import web3Utils from 'web3-utils'
|
||||||
|
|
||||||
export function transformPublishFormToMetadata(
|
export function transformPublishFormToMetadata(
|
||||||
data: PublishFormData
|
data: MetaDataPublishForm
|
||||||
): MetaDataMarket {
|
): MetaDataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
|
|
||||||
@ -17,9 +16,9 @@ export function transformPublishFormToMetadata(
|
|||||||
description,
|
description,
|
||||||
copyrightHolder,
|
copyrightHolder,
|
||||||
tags,
|
tags,
|
||||||
|
links,
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
files,
|
files,
|
||||||
dateRange,
|
|
||||||
access
|
access
|
||||||
} = data
|
} = data
|
||||||
|
|
||||||
@ -27,35 +26,28 @@ export function transformPublishFormToMetadata(
|
|||||||
main: {
|
main: {
|
||||||
...AssetModel.main,
|
...AssetModel.main,
|
||||||
name,
|
name,
|
||||||
price: web3Utils.toWei(price.toString()),
|
price: `${web3Utils.toWei(price.toString())}`,
|
||||||
author,
|
author,
|
||||||
dateCreated: currentTime,
|
dateCreated: currentTime,
|
||||||
datePublished: currentTime,
|
datePublished: currentTime,
|
||||||
files,
|
// files: {
|
||||||
|
// url: files
|
||||||
|
// },
|
||||||
license
|
license
|
||||||
},
|
},
|
||||||
// ------- additional information -------
|
|
||||||
additionalInformation: {
|
additionalInformation: {
|
||||||
...AssetModel.additionalInformation,
|
...AssetModel.additionalInformation,
|
||||||
description,
|
description,
|
||||||
copyrightHolder,
|
copyrightHolder,
|
||||||
tags: tags?.split(','),
|
tags: tags?.split(','),
|
||||||
|
// links: {
|
||||||
|
// url: links
|
||||||
|
// },
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
access: access || 'Download'
|
access: access || 'Download'
|
||||||
},
|
},
|
||||||
// ------- curation -------
|
|
||||||
curation: AssetModel.curation
|
curation: AssetModel.curation
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dateRange) {
|
|
||||||
const newDateRange = JSON.parse(dateRange)
|
|
||||||
if (newDateRange.length > 1) {
|
|
||||||
metadata.additionalInformation.dateRange = JSON.parse(dateRange)
|
|
||||||
} else if (newDateRange.length === 1) {
|
|
||||||
// eslint-disable-next-line prefer-destructuring
|
|
||||||
metadata.main.dateCreated = newDateRange[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,11 @@ const AssetModel: MetaDataMarket = {
|
|||||||
additionalInformation: {
|
additionalInformation: {
|
||||||
description: '',
|
description: '',
|
||||||
copyrightHolder: '',
|
copyrightHolder: '',
|
||||||
tags: undefined,
|
tags: [],
|
||||||
// links: [],
|
links: [],
|
||||||
|
|
||||||
// custom items
|
// custom items
|
||||||
termsAndConditions: false,
|
termsAndConditions: false,
|
||||||
dateRange: undefined,
|
|
||||||
access: 'Download'
|
access: 'Download'
|
||||||
},
|
},
|
||||||
curation: {
|
curation: {
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
import * as Yup from 'yup'
|
|
||||||
import { AccessType } from '../@types/MetaData'
|
|
||||||
import { File } from '@oceanprotocol/squid'
|
|
||||||
|
|
||||||
export interface PublishFormData {
|
|
||||||
// ---- required fields ----
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
files: File[]
|
|
||||||
termsAndConditions: boolean
|
|
||||||
author: string
|
|
||||||
license: string
|
|
||||||
price: number
|
|
||||||
access?: AccessType
|
|
||||||
// ---- optional fields ----
|
|
||||||
dateRange?: string
|
|
||||||
copyrightHolder?: string
|
|
||||||
tags?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const validationSchema = Yup.object().shape({
|
|
||||||
name: Yup.string().required('Required'),
|
|
||||||
author: Yup.string().required('Required'),
|
|
||||||
price: Yup.string().required('Required'),
|
|
||||||
files: Yup.array().required('Required'),
|
|
||||||
summary: Yup.string().required('Required'),
|
|
||||||
license: Yup.string().required('Required'),
|
|
||||||
termsAndConditions: Yup.boolean().required('Required'),
|
|
||||||
dateRange: Yup.string().required('Required'),
|
|
||||||
copyrightHolder: Yup.string().required('Required'),
|
|
||||||
tags: Yup.string().required('Required')
|
|
||||||
})
|
|
||||||
|
|
||||||
export const initialValues: PublishFormData = {
|
|
||||||
author: '',
|
|
||||||
price: 0,
|
|
||||||
name: '',
|
|
||||||
files: [],
|
|
||||||
description: '',
|
|
||||||
license: '',
|
|
||||||
termsAndConditions: false,
|
|
||||||
dateRange: undefined,
|
|
||||||
copyrightHolder: undefined,
|
|
||||||
tags: undefined
|
|
||||||
}
|
|
@ -72,7 +72,6 @@ const ddo: Partial<DDO> = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
termsAndConditions: true,
|
termsAndConditions: true,
|
||||||
dateRange: ['2018-09-20T08:38:58', '2019-12-11T05:19:42'],
|
|
||||||
access: 'Download'
|
access: 'Download'
|
||||||
},
|
},
|
||||||
curation: {
|
curation: {
|
||||||
|
@ -4,10 +4,12 @@ const testFormData: PublishFormData = {
|
|||||||
author: '',
|
author: '',
|
||||||
files: [],
|
files: [],
|
||||||
license: '',
|
license: '',
|
||||||
price: 0,
|
price: '0',
|
||||||
title: '',
|
name: '',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
termsAndConditions: true
|
termsAndConditions: true,
|
||||||
|
access: 'Download',
|
||||||
|
links: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export default testFormData
|
export default testFormData
|
||||||
|
Loading…
Reference in New Issue
Block a user