mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-14 09:14:52 +01:00
refactor metadata types for publish forms
This commit is contained in:
parent
5112a35524
commit
2f1bd399f8
4
src/@types/MetaData.d.ts
vendored
4
src/@types/MetaData.d.ts
vendored
@ -24,7 +24,7 @@ export interface PriceOptionsMarket extends PriceOptions {
|
|||||||
swapFee: number
|
swapFee: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MetadataPublishForm {
|
export interface MetadataPublishFormDataset {
|
||||||
// ---- required fields ----
|
// ---- required fields ----
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
@ -39,7 +39,7 @@ export interface MetadataPublishForm {
|
|||||||
links?: string | File[]
|
links?: string | File[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AlgorithmPublishForm {
|
export interface MetadataPublishFormAlgorithm {
|
||||||
// ---- required fields ----
|
// ---- required fields ----
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
|
@ -6,8 +6,8 @@ import MetaItem from '../organisms/AssetContent/MetaItem'
|
|||||||
import styles from './MetadataPreview.module.css'
|
import styles from './MetadataPreview.module.css'
|
||||||
import File from '../atoms/File'
|
import File from '../atoms/File'
|
||||||
import {
|
import {
|
||||||
MetadataPublishForm,
|
MetadataPublishFormDataset,
|
||||||
AlgorithmPublishForm
|
MetadataPublishFormAlgorithm
|
||||||
} from '../../@types/MetaData'
|
} from '../../@types/MetaData'
|
||||||
import Button from '../atoms/Button'
|
import Button from '../atoms/Button'
|
||||||
import { transformTags } from '../../utils/metadata'
|
import { transformTags } from '../../utils/metadata'
|
||||||
@ -45,7 +45,7 @@ function Description({ description }: { description: string }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function MetaFull({ values }: { values: Partial<MetadataPublishForm> }) {
|
function MetaFull({ values }: { values: Partial<MetadataPublishFormDataset> }) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.metaFull}>
|
<div className={styles.metaFull}>
|
||||||
{Object.entries(values)
|
{Object.entries(values)
|
||||||
@ -90,7 +90,7 @@ function Sample({ url }: { url: string }) {
|
|||||||
export function MetadataPreview({
|
export function MetadataPreview({
|
||||||
values
|
values
|
||||||
}: {
|
}: {
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishFormDataset>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
return (
|
return (
|
||||||
<div className={styles.preview}>
|
<div className={styles.preview}>
|
||||||
@ -128,7 +128,7 @@ export function MetadataPreview({
|
|||||||
export function MetadataAlgorithmPreview({
|
export function MetadataAlgorithmPreview({
|
||||||
values
|
values
|
||||||
}: {
|
}: {
|
||||||
values: Partial<AlgorithmPublishForm>
|
values: Partial<MetadataPublishFormAlgorithm>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
return (
|
return (
|
||||||
<div className={styles.preview}>
|
<div className={styles.preview}>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { DDO } from '@oceanprotocol/lib'
|
import { DDO } from '@oceanprotocol/lib'
|
||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { MetadataPublishForm } from '../../../../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../../@types/MetaData'
|
||||||
import { transformPublishFormToMetadata } from '../../../../utils/metadata'
|
import { transformPublishFormToMetadata } from '../../../../utils/metadata'
|
||||||
import DebugOutput from '../../../atoms/DebugOutput'
|
import DebugOutput from '../../../atoms/DebugOutput'
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ export default function Debug({
|
|||||||
values,
|
values,
|
||||||
ddo
|
ddo
|
||||||
}: {
|
}: {
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishFormDataset>
|
||||||
ddo: DDO
|
ddo: DDO
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const newDdo = {
|
const newDdo = {
|
||||||
|
@ -5,12 +5,12 @@ import Button from '../../../atoms/Button'
|
|||||||
import Input from '../../../atoms/Input'
|
import Input from '../../../atoms/Input'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import { FormFieldProps } from '../../../../@types/Form'
|
import { FormFieldProps } from '../../../../@types/Form'
|
||||||
import { MetadataPublishForm } from '../../../../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../../@types/MetaData'
|
||||||
import { checkIfTimeoutInPredefinedValues } from '../../../../utils/metadata'
|
import { checkIfTimeoutInPredefinedValues } from '../../../../utils/metadata'
|
||||||
|
|
||||||
function handleTimeoutCustomOption(
|
function handleTimeoutCustomOption(
|
||||||
data: FormFieldProps[],
|
data: FormFieldProps[],
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishFormDataset>
|
||||||
) {
|
) {
|
||||||
const timeoutFieldContent = data.filter(
|
const timeoutFieldContent = data.filter(
|
||||||
(field) => field.name === 'timeout'
|
(field) => field.name === 'timeout'
|
||||||
@ -51,14 +51,14 @@ export default function FormEditMetadata({
|
|||||||
data: FormFieldProps[]
|
data: FormFieldProps[]
|
||||||
setShowEdit: (show: boolean) => void
|
setShowEdit: (show: boolean) => void
|
||||||
setTimeoutStringValue: (value: string) => void
|
setTimeoutStringValue: (value: string) => void
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishFormDataset>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean, accountId } = useOcean()
|
const { ocean, accountId } = useOcean()
|
||||||
const {
|
const {
|
||||||
isValid,
|
isValid,
|
||||||
validateField,
|
validateField,
|
||||||
setFieldValue
|
setFieldValue
|
||||||
}: FormikContextType<Partial<MetadataPublishForm>> = useFormikContext()
|
}: FormikContextType<Partial<MetadataPublishFormDataset>> = useFormikContext()
|
||||||
|
|
||||||
// Manually handle change events instead of using `handleChange` from Formik.
|
// Manually handle change events instead of using `handleChange` from Formik.
|
||||||
// Workaround for default `validateOnChange` not kicking in
|
// Workaround for default `validateOnChange` not kicking in
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import { Formik } from 'formik'
|
import { Formik } from 'formik'
|
||||||
import React, { ReactElement, useState } from 'react'
|
import React, { ReactElement, useState } from 'react'
|
||||||
import { MetadataPublishForm } from '../../../../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../../@types/MetaData'
|
||||||
import {
|
import {
|
||||||
validationSchema,
|
validationSchema,
|
||||||
getInitialValues
|
getInitialValues
|
||||||
@ -66,7 +66,7 @@ export default function Edit({
|
|||||||
const hasFeedback = error || success
|
const hasFeedback = error || success
|
||||||
|
|
||||||
async function handleSubmit(
|
async function handleSubmit(
|
||||||
values: Partial<MetadataPublishForm>,
|
values: Partial<MetadataPublishFormDataset>,
|
||||||
resetForm: () => void
|
resetForm: () => void
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { MetadataPublishForm } from '../../../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../@types/MetaData'
|
||||||
import DebugOutput from '../../atoms/DebugOutput'
|
import DebugOutput from '../../atoms/DebugOutput'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import { transformPublishFormToMetadata } from '../../../utils/metadata'
|
import { transformPublishFormToMetadata } from '../../../utils/metadata'
|
||||||
@ -7,7 +7,7 @@ import { transformPublishFormToMetadata } from '../../../utils/metadata'
|
|||||||
export default function Debug({
|
export default function Debug({
|
||||||
values
|
values
|
||||||
}: {
|
}: {
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishFormDataset>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const ddo = {
|
const ddo = {
|
||||||
'@context': 'https://w3id.org/did/v1',
|
'@context': 'https://w3id.org/did/v1',
|
||||||
|
@ -6,7 +6,7 @@ import { useFormikContext, Field, Form, FormikContextType } from 'formik'
|
|||||||
import Input from '../../atoms/Input'
|
import Input from '../../atoms/Input'
|
||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
||||||
import { AlgorithmPublishForm } from '../../../@types/MetaData'
|
import { MetadataPublishFormAlgorithm } from '../../../@types/MetaData'
|
||||||
|
|
||||||
const query = graphql`
|
const query = graphql`
|
||||||
query {
|
query {
|
||||||
@ -50,7 +50,7 @@ export default function FormPublish(): ReactElement {
|
|||||||
initialValues,
|
initialValues,
|
||||||
validateField,
|
validateField,
|
||||||
setFieldValue
|
setFieldValue
|
||||||
}: FormikContextType<AlgorithmPublishForm> = useFormikContext()
|
}: FormikContextType<MetadataPublishFormAlgorithm> = useFormikContext()
|
||||||
|
|
||||||
// reset form validation on every mount
|
// reset form validation on every mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -6,7 +6,7 @@ import { useFormikContext, Field, Form, FormikContextType } from 'formik'
|
|||||||
import Input from '../../atoms/Input'
|
import Input from '../../atoms/Input'
|
||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
||||||
import { MetadataPublishForm } from '../../../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../@types/MetaData'
|
||||||
|
|
||||||
const query = graphql`
|
const query = graphql`
|
||||||
query {
|
query {
|
||||||
@ -50,7 +50,7 @@ export default function FormPublish(): ReactElement {
|
|||||||
initialValues,
|
initialValues,
|
||||||
validateField,
|
validateField,
|
||||||
setFieldValue
|
setFieldValue
|
||||||
}: FormikContextType<MetadataPublishForm> = useFormikContext()
|
}: FormikContextType<MetadataPublishFormDataset> = useFormikContext()
|
||||||
|
|
||||||
// reset form validation on every mount
|
// reset form validation on every mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -23,8 +23,8 @@ import {
|
|||||||
MetadataAlgorithmPreview
|
MetadataAlgorithmPreview
|
||||||
} from '../../molecules/MetadataPreview'
|
} from '../../molecules/MetadataPreview'
|
||||||
import {
|
import {
|
||||||
MetadataPublishForm,
|
MetadataPublishFormDataset,
|
||||||
AlgorithmPublishForm
|
MetadataPublishFormAlgorithm
|
||||||
} from '../../../@types/MetaData'
|
} from '../../../@types/MetaData'
|
||||||
import { useUserPreferences } from '../../../providers/UserPreferences'
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
||||||
import { Logger, Metadata } from '@oceanprotocol/lib'
|
import { Logger, Metadata } from '@oceanprotocol/lib'
|
||||||
@ -59,7 +59,7 @@ export default function PublishPage({
|
|||||||
}, [publishType])
|
}, [publishType])
|
||||||
|
|
||||||
async function handleSubmit(
|
async function handleSubmit(
|
||||||
values: Partial<MetadataPublishForm>,
|
values: Partial<MetadataPublishFormDataset>,
|
||||||
resetForm: () => void
|
resetForm: () => void
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const metadata = transformPublishFormToMetadata(values)
|
const metadata = transformPublishFormToMetadata(values)
|
||||||
@ -102,7 +102,7 @@ export default function PublishPage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleAlgorithmSubmit(
|
async function handleAlgorithmSubmit(
|
||||||
values: Partial<AlgorithmPublishForm>,
|
values: Partial<MetadataPublishFormAlgorithm>,
|
||||||
resetForm: () => void
|
resetForm: () => void
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const metadata = transformPublishAlgorithmFormToMetadata(values)
|
const metadata = transformPublishAlgorithmFormToMetadata(values)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { AlgorithmPublishForm } from '../@types/MetaData'
|
import { MetadataPublishFormAlgorithm } from '../@types/MetaData'
|
||||||
import { File as FileMetadata } from '@oceanprotocol/lib'
|
import { File as FileMetadata } from '@oceanprotocol/lib'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
export const validationSchema: Yup.SchemaOf<AlgorithmPublishForm> = Yup.object()
|
export const validationSchema: Yup.SchemaOf<MetadataPublishFormAlgorithm> = Yup.object()
|
||||||
.shape({
|
.shape({
|
||||||
// ---- required fields ----
|
// ---- required fields ----
|
||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
@ -27,7 +27,7 @@ export const validationSchema: Yup.SchemaOf<AlgorithmPublishForm> = Yup.object()
|
|||||||
})
|
})
|
||||||
.defined()
|
.defined()
|
||||||
|
|
||||||
export const initialValues: Partial<AlgorithmPublishForm> = {
|
export const initialValues: Partial<MetadataPublishFormAlgorithm> = {
|
||||||
name: '',
|
name: '',
|
||||||
author: '',
|
author: '',
|
||||||
dockerImage: '',
|
dockerImage: '',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MetadataMarket, MetadataPublishForm } from '../@types/MetaData'
|
import { MetadataMarket, MetadataPublishFormDataset } from '../@types/MetaData'
|
||||||
import { secondsToString } from '../utils/metadata'
|
import { secondsToString } from '../utils/metadata'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ export const validationSchema = Yup.object().shape({
|
|||||||
export function getInitialValues(
|
export function getInitialValues(
|
||||||
metadata: MetadataMarket,
|
metadata: MetadataMarket,
|
||||||
timeout: number
|
timeout: number
|
||||||
): Partial<MetadataPublishForm> {
|
): Partial<MetadataPublishFormDataset> {
|
||||||
return {
|
return {
|
||||||
name: metadata.main.name,
|
name: metadata.main.name,
|
||||||
description: metadata.additionalInformation.description,
|
description: metadata.additionalInformation.description,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { MetadataPublishForm } from '../@types/MetaData'
|
import { MetadataPublishFormDataset } from '../@types/MetaData'
|
||||||
import { File as FileMetadata } from '@oceanprotocol/lib'
|
import { File as FileMetadata } from '@oceanprotocol/lib'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
export const validationSchema: Yup.SchemaOf<MetadataPublishForm> = Yup.object()
|
export const validationSchema: Yup.SchemaOf<MetadataPublishFormDataset> = Yup.object()
|
||||||
.shape({
|
.shape({
|
||||||
// ---- required fields ----
|
// ---- required fields ----
|
||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
@ -29,7 +29,7 @@ export const validationSchema: Yup.SchemaOf<MetadataPublishForm> = Yup.object()
|
|||||||
})
|
})
|
||||||
.defined()
|
.defined()
|
||||||
|
|
||||||
export const initialValues: Partial<MetadataPublishForm> = {
|
export const initialValues: Partial<MetadataPublishFormDataset> = {
|
||||||
name: '',
|
name: '',
|
||||||
author: '',
|
author: '',
|
||||||
dataTokenOptions: {
|
dataTokenOptions: {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
MetadataMarket,
|
MetadataMarket,
|
||||||
MetadataPublishForm,
|
MetadataPublishFormDataset,
|
||||||
AlgorithmPublishForm
|
MetadataPublishFormAlgorithm
|
||||||
} from '../@types/MetaData'
|
} from '../@types/MetaData'
|
||||||
import { toStringNoMS } from '.'
|
import { toStringNoMS } from '.'
|
||||||
import AssetModel from '../models/Asset'
|
import AssetModel from '../models/Asset'
|
||||||
@ -102,7 +102,7 @@ export function transformPublishFormToMetadata(
|
|||||||
links,
|
links,
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
files
|
files
|
||||||
}: Partial<MetadataPublishForm>,
|
}: Partial<MetadataPublishFormDataset>,
|
||||||
ddo?: DDO
|
ddo?: DDO
|
||||||
): MetadataMarket {
|
): MetadataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
@ -140,7 +140,7 @@ export function transformPublishAlgorithmFormToMetadata(
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
files
|
files
|
||||||
}: Partial<AlgorithmPublishForm>,
|
}: Partial<MetadataPublishFormAlgorithm>,
|
||||||
ddo?: DDO
|
ddo?: DDO
|
||||||
): MetadataMarket {
|
): MetadataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { MetadataPublishForm } from '../../../src/@types/MetaData'
|
import { MetadataPublishFormDataset } from '../../../src/@types/MetaData'
|
||||||
|
|
||||||
const testFormData: MetadataPublishForm = {
|
const testFormData: MetadataPublishFormDataset = {
|
||||||
author: '',
|
author: '',
|
||||||
files: [],
|
files: [],
|
||||||
dataTokenOptions: {
|
dataTokenOptions: {
|
||||||
|
@ -3,7 +3,7 @@ import { render } from '@testing-library/react'
|
|||||||
import { transformPublishFormToMetadata } from '../../../src/utils/metadata'
|
import { transformPublishFormToMetadata } from '../../../src/utils/metadata'
|
||||||
import {
|
import {
|
||||||
MetadataMarket,
|
MetadataMarket,
|
||||||
MetadataPublishForm
|
MetadataPublishFormDataset
|
||||||
} from '../../../src/@types/MetaData'
|
} from '../../../src/@types/MetaData'
|
||||||
import PublishForm from '../../../src/components/pages/Publish/FormPublish'
|
import PublishForm from '../../../src/components/pages/Publish/FormPublish'
|
||||||
import publishFormData from '../__fixtures__/testFormData'
|
import publishFormData from '../__fixtures__/testFormData'
|
||||||
@ -15,7 +15,7 @@ describe('PublishForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// it('Form data is correctly transformed to asset Metadata', () => {
|
// it('Form data is correctly transformed to asset Metadata', () => {
|
||||||
// const data: MetadataPublishForm = publishFormData
|
// const data: MetadataPublishFormDataset = publishFormData
|
||||||
// let metadata: MetadataMarket = transformPublishFormToMetadata(data)
|
// let metadata: MetadataMarket = transformPublishFormToMetadata(data)
|
||||||
|
|
||||||
// expect(metadata.additionalInformation).toBeDefined()
|
// expect(metadata.additionalInformation).toBeDefined()
|
||||||
|
Loading…
Reference in New Issue
Block a user