From 2f1bd399f8ba0729314fbfc6adcdc1422300f467 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 19 Feb 2021 17:51:40 +0200 Subject: [PATCH] refactor metadata types for publish forms --- src/@types/MetaData.d.ts | 4 ++-- src/components/molecules/MetadataPreview.tsx | 10 +++++----- src/components/organisms/AssetActions/Edit/Debug.tsx | 4 ++-- .../organisms/AssetActions/Edit/FormEditMetadata.tsx | 8 ++++---- src/components/organisms/AssetActions/Edit/index.tsx | 4 ++-- src/components/pages/Publish/Debug.tsx | 4 ++-- src/components/pages/Publish/FormAlgoPublish.tsx | 4 ++-- src/components/pages/Publish/FormPublish.tsx | 4 ++-- src/components/pages/Publish/index.tsx | 8 ++++---- src/models/FormAlgoPublish.ts | 6 +++--- src/models/FormEditMetadata.ts | 4 ++-- src/models/FormPublish.ts | 6 +++--- src/utils/metadata.ts | 8 ++++---- tests/unit/__fixtures__/testFormData.ts | 4 ++-- tests/unit/components/PublishForm.test.tsx | 4 ++-- 15 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/@types/MetaData.d.ts b/src/@types/MetaData.d.ts index 76c3ca8fb..6b3dc1812 100644 --- a/src/@types/MetaData.d.ts +++ b/src/@types/MetaData.d.ts @@ -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 diff --git a/src/components/molecules/MetadataPreview.tsx b/src/components/molecules/MetadataPreview.tsx index d2330cd31..420c3603b 100644 --- a/src/components/molecules/MetadataPreview.tsx +++ b/src/components/molecules/MetadataPreview.tsx @@ -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 }) { +function MetaFull({ values }: { values: Partial }) { return (
{Object.entries(values) @@ -90,7 +90,7 @@ function Sample({ url }: { url: string }) { export function MetadataPreview({ values }: { - values: Partial + values: Partial }): ReactElement { return (
@@ -128,7 +128,7 @@ export function MetadataPreview({ export function MetadataAlgorithmPreview({ values }: { - values: Partial + values: Partial }): ReactElement { return (
diff --git a/src/components/organisms/AssetActions/Edit/Debug.tsx b/src/components/organisms/AssetActions/Edit/Debug.tsx index f8a973dbd..b08f584d0 100644 --- a/src/components/organisms/AssetActions/Edit/Debug.tsx +++ b/src/components/organisms/AssetActions/Edit/Debug.tsx @@ -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 + values: Partial ddo: DDO }): ReactElement { const newDdo = { diff --git a/src/components/organisms/AssetActions/Edit/FormEditMetadata.tsx b/src/components/organisms/AssetActions/Edit/FormEditMetadata.tsx index 238b4cd24..5e62b59f2 100644 --- a/src/components/organisms/AssetActions/Edit/FormEditMetadata.tsx +++ b/src/components/organisms/AssetActions/Edit/FormEditMetadata.tsx @@ -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 + values: Partial ) { 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 + values: Partial }): ReactElement { const { ocean, accountId } = useOcean() const { isValid, validateField, setFieldValue - }: FormikContextType> = useFormikContext() + }: FormikContextType> = useFormikContext() // Manually handle change events instead of using `handleChange` from Formik. // Workaround for default `validateOnChange` not kicking in diff --git a/src/components/organisms/AssetActions/Edit/index.tsx b/src/components/organisms/AssetActions/Edit/index.tsx index d70a1343b..77cf23acc 100644 --- a/src/components/organisms/AssetActions/Edit/index.tsx +++ b/src/components/organisms/AssetActions/Edit/index.tsx @@ -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, + values: Partial, resetForm: () => void ) { try { diff --git a/src/components/pages/Publish/Debug.tsx b/src/components/pages/Publish/Debug.tsx index 31e5404ac..2aa2375e4 100644 --- a/src/components/pages/Publish/Debug.tsx +++ b/src/components/pages/Publish/Debug.tsx @@ -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 + values: Partial }): ReactElement { const ddo = { '@context': 'https://w3id.org/did/v1', diff --git a/src/components/pages/Publish/FormAlgoPublish.tsx b/src/components/pages/Publish/FormAlgoPublish.tsx index f45845fe1..6757c800e 100644 --- a/src/components/pages/Publish/FormAlgoPublish.tsx +++ b/src/components/pages/Publish/FormAlgoPublish.tsx @@ -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 = useFormikContext() + }: FormikContextType = useFormikContext() // reset form validation on every mount useEffect(() => { diff --git a/src/components/pages/Publish/FormPublish.tsx b/src/components/pages/Publish/FormPublish.tsx index ce2887012..189f2bc26 100644 --- a/src/components/pages/Publish/FormPublish.tsx +++ b/src/components/pages/Publish/FormPublish.tsx @@ -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 = useFormikContext() + }: FormikContextType = useFormikContext() // reset form validation on every mount useEffect(() => { diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index 42418ecb7..accbdd865 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -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, + values: Partial, resetForm: () => void ): Promise { const metadata = transformPublishFormToMetadata(values) @@ -102,7 +102,7 @@ export default function PublishPage({ } async function handleAlgorithmSubmit( - values: Partial, + values: Partial, resetForm: () => void ): Promise { const metadata = transformPublishAlgorithmFormToMetadata(values) diff --git a/src/models/FormAlgoPublish.ts b/src/models/FormAlgoPublish.ts index 826721026..8831e7d9a 100644 --- a/src/models/FormAlgoPublish.ts +++ b/src/models/FormAlgoPublish.ts @@ -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 = Yup.object() +export const validationSchema: Yup.SchemaOf = Yup.object() .shape({ // ---- required fields ---- name: Yup.string() @@ -27,7 +27,7 @@ export const validationSchema: Yup.SchemaOf = Yup.object() }) .defined() -export const initialValues: Partial = { +export const initialValues: Partial = { name: '', author: '', dockerImage: '', diff --git a/src/models/FormEditMetadata.ts b/src/models/FormEditMetadata.ts index b98b6c488..1ddf93b09 100644 --- a/src/models/FormEditMetadata.ts +++ b/src/models/FormEditMetadata.ts @@ -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 { +): Partial { return { name: metadata.main.name, description: metadata.additionalInformation.description, diff --git a/src/models/FormPublish.ts b/src/models/FormPublish.ts index 64bd63ee1..c6387eab0 100644 --- a/src/models/FormPublish.ts +++ b/src/models/FormPublish.ts @@ -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 = Yup.object() +export const validationSchema: Yup.SchemaOf = Yup.object() .shape({ // ---- required fields ---- name: Yup.string() @@ -29,7 +29,7 @@ export const validationSchema: Yup.SchemaOf = Yup.object() }) .defined() -export const initialValues: Partial = { +export const initialValues: Partial = { name: '', author: '', dataTokenOptions: { diff --git a/src/utils/metadata.ts b/src/utils/metadata.ts index a1fa323ab..fb9fcaadf 100644 --- a/src/utils/metadata.ts +++ b/src/utils/metadata.ts @@ -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, + }: Partial, ddo?: DDO ): MetadataMarket { const currentTime = toStringNoMS(new Date()) @@ -140,7 +140,7 @@ export function transformPublishAlgorithmFormToMetadata( entrypoint, termsAndConditions, files - }: Partial, + }: Partial, ddo?: DDO ): MetadataMarket { const currentTime = toStringNoMS(new Date()) diff --git a/tests/unit/__fixtures__/testFormData.ts b/tests/unit/__fixtures__/testFormData.ts index 35d5b5439..8ff2d7342 100644 --- a/tests/unit/__fixtures__/testFormData.ts +++ b/tests/unit/__fixtures__/testFormData.ts @@ -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: { diff --git a/tests/unit/components/PublishForm.test.tsx b/tests/unit/components/PublishForm.test.tsx index 44e5d469b..f520481f0 100644 --- a/tests/unit/components/PublishForm.test.tsx +++ b/tests/unit/components/PublishForm.test.tsx @@ -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()