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