diff --git a/client/src/routes/Publish/Files/index.test.tsx b/client/src/routes/Publish/Files/index.test.tsx index dd6c231..9abee6e 100644 --- a/client/src/routes/Publish/Files/index.test.tsx +++ b/client/src/routes/Publish/Files/index.test.tsx @@ -6,7 +6,6 @@ const onChange = jest.fn() const files = [ { - found: true, url: 'https://hello.com', checksum: 'cccccc', checksumType: 'MD5', @@ -14,7 +13,8 @@ const files = [ contentType: 'application/zip', resourceId: 'xxx', encoding: 'UTF-8', - compression: 'zip' + compression: 'zip', + found: true } ] diff --git a/client/src/routes/Publish/Files/index.tsx b/client/src/routes/Publish/Files/index.tsx index 4fe22c6..c910588 100644 --- a/client/src/routes/Publish/Files/index.tsx +++ b/client/src/routes/Publish/Files/index.tsx @@ -8,17 +8,18 @@ import styles from './index.module.scss' import { serviceUri } from '../../../config' import cleanupContentType from '../../../utils/cleanupContentType' +import { Logger } from '@oceanprotocol/squid' -interface File { +export interface File { url: string - found: boolean + contentType: string checksum?: string checksumType?: string contentLength?: number - contentType?: string resourceId?: string encoding?: string compression?: string + found: boolean // non-standard } interface FilesProps { @@ -51,20 +52,10 @@ export default class Files extends PureComponent { } private addItem = async (value: string) => { - let res: { - result: { - contentLength: number - contentType: string - found: boolean - } - } - let file: File = { url: value, - found: false, - contentLength: 0, contentType: '', - compression: '' + found: false // non-standard } try { @@ -75,13 +66,16 @@ export default class Files extends PureComponent { 'Content-Type': 'application/json' } }) - res = await response.json() - file.contentLength = res.result.contentLength - file.contentType = res.result.contentType - file.compression = await cleanupContentType(res.result.contentType) - file.found = res.result.found + + const json = await response.json() + const { contentLength, contentType, found } = json.result + + file.contentLength = contentLength + file.contentType = contentType + file.compression = await cleanupContentType(contentType) + file.found = found } catch (error) { - // error + Logger.error(error.message) } this.props.files.push(file) diff --git a/client/src/routes/Publish/index.tsx b/client/src/routes/Publish/index.tsx index c78f009..cd3d825 100644 --- a/client/src/routes/Publish/index.tsx +++ b/client/src/routes/Publish/index.tsx @@ -11,27 +11,28 @@ import ReactGA from 'react-ga' import { steps } from '../../data/form-publish.json' import Content from '../../components/atoms/Content' +import { File } from './Files' type AssetType = 'dataset' | 'algorithm' | 'container' | 'workflow' | 'other' interface PublishState { name?: string dateCreated?: string - description?: string - files?: string[] price?: string author?: string - type?: AssetType license?: string + description?: string + files?: File[] + type?: AssetType copyrightHolder?: string - categories?: string - tags?: string[] + categories?: string[] + + currentStep?: number + publishingStep?: number isPublishing?: boolean isPublished?: boolean publishedDid?: string publishingError?: string - publishingStep?: number - currentStep?: number validationStatus?: any } @@ -39,7 +40,6 @@ export default class Publish extends Component<{}, PublishState> { public static contextType = User public state = { - currentStep: 1, name: '', dateCreated: new Date().toISOString(), description: '', @@ -49,7 +49,9 @@ export default class Publish extends Component<{}, PublishState> { type: 'dataset' as AssetType, license: '', copyrightHolder: '', - categories: '', + categories: [], + + currentStep: 1, isPublishing: false, isPublished: false, publishedDid: '', @@ -127,7 +129,7 @@ export default class Publish extends Component<{}, PublishState> { type: 'dataset' as AssetType, license: '', copyrightHolder: '', - categories: '', + categories: [], isPublishing: false, isPublished: false, publishingStep: 0, @@ -267,6 +269,14 @@ export default class Publish extends Component<{}, PublishState> { const { ocean } = this.context const account = await ocean.accounts.list() + + // remove `found` attribute from all objects + // and use new array for hidden input + // eslint-disable-next-line @typescript-eslint/no-unused-vars + // const filesStandard = this.state.files.map( + // ({ found, ...keepAttrs }) => keepAttrs // eslint-disable-line + // ) + const newAsset = { // OEP-08 Attributes // https://github.com/oceanprotocol/OEPs/tree/master/8 @@ -280,10 +290,7 @@ export default class Publish extends Component<{}, PublishState> { files: this.state.files, price: this.state.price, type: this.state.type, - categories: [this.state.categories], - workExample: undefined, - inLanguage: undefined, - tags: '' + categories: [this.state.categories] }), curation: Object.assign(AssetModel.curation), additionalInformation: Object.assign(