diff --git a/content/pages/publish/form-algorithm.json b/content/pages/publish/form-algorithm.json index e6a62560c..505f6515d 100644 --- a/content/pages/publish/form-algorithm.json +++ b/content/pages/publish/form-algorithm.json @@ -56,6 +56,13 @@ "sortOptions": false, "required": true }, + { + "name": "dataTokenOptions", + "label": "Datatoken Name & Symbol", + "type": "datatoken", + "help": "The datatoken for this algorithm will be created with this name & symbol.", + "required": true + }, { "name": "entrypoint", "label": "Entrypoint", diff --git a/src/@types/MetaData.d.ts b/src/@types/MetaData.d.ts index 0d8d583d0..2481338b5 100644 --- a/src/@types/MetaData.d.ts +++ b/src/@types/MetaData.d.ts @@ -49,6 +49,7 @@ export interface MetadataPublishFormAlgorithm { dockerImage: string algorithmPrivacy: boolean timeout: string + dataTokenOptions: DataTokenOptions termsAndConditions: boolean // ---- optional fields ---- image: string diff --git a/src/components/molecules/MetadataPreview.tsx b/src/components/molecules/MetadataPreview.tsx index d22eb3737..a1a85c126 100644 --- a/src/components/molecules/MetadataPreview.tsx +++ b/src/components/molecules/MetadataPreview.tsx @@ -135,6 +135,11 @@ export function MetadataAlgorithmPreview({

Preview

{values.name &&

{values.name}

} + {values.dataTokenOptions?.name && ( +

{`${values.dataTokenOptions.name} — ${values.dataTokenOptions.symbol}`}

+ )} {values.description && }
diff --git a/src/components/pages/Publish/FormAlgoPublish.tsx b/src/components/pages/Publish/FormAlgoPublish.tsx index cb18512b6..5d90507be 100644 --- a/src/components/pages/Publish/FormAlgoPublish.tsx +++ b/src/components/pages/Publish/FormAlgoPublish.tsx @@ -62,12 +62,11 @@ export default function FormPublish(): ReactElement { const [selectedDockerImage, setSelectedDockerImage] = useState( initialValues.dockerImage ) + // reset form validation on every mount useEffect(() => { setErrors({}) setTouched({}) - - // setSubmitting(false) }, [setErrors, setTouched]) function handleImageSelectChange(imageSelected: string) { diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index 378d4869b..0de351ab3 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -95,9 +95,22 @@ export default function PublishPage({ const [publishType, setPublishType] = useState( 'dataset' ) - const hasFeedback = isLoading || error || success + const emptyAlgoDT = Object.values(algoInitialValues.dataTokenOptions).every( + (value) => value === '' + ) + const emptyDatasetDT = Object.values( + datasetInitialValues.dataTokenOptions + ).every((value) => value === '') + + if (emptyAlgoDT) { + algoInitialValues.dataTokenOptions = datasetInitialValues.dataTokenOptions + } else { + if (emptyDatasetDT) + datasetInitialValues.dataTokenOptions = algoInitialValues.dataTokenOptions + } + useEffect(() => { publishType === 'dataset' ? setTitle('Publishing Data Set') @@ -166,12 +179,12 @@ export default function PublishPage({ : true try { if (validDockerImage) { - Logger.log('Publish Algorithm with ', metadata) + Logger.log('Publish algorithm with ', metadata, values.dataTokenOptions) const ddo = await publish( (metadata as unknown) as Metadata, values.algorithmPrivacy === true ? 'compute' : 'access', - undefined, + values.dataTokenOptions, timeout ) diff --git a/src/models/FormAlgoPublish.ts b/src/models/FormAlgoPublish.ts index 415ca04ab..d6dd93907 100644 --- a/src/models/FormAlgoPublish.ts +++ b/src/models/FormAlgoPublish.ts @@ -11,6 +11,12 @@ export const validationSchema: Yup.SchemaOf = Yup. description: Yup.string().min(10).required('Required'), files: Yup.array().required('Required').nullable(), timeout: Yup.string().required('Required'), + dataTokenOptions: Yup.object() + .shape({ + name: Yup.string(), + symbol: Yup.string() + }) + .required('Required'), dockerImage: Yup.string() .matches(/node:latest|python:latest|custom image/g, { excludeEmptyString: true @@ -31,6 +37,10 @@ export const validationSchema: Yup.SchemaOf = Yup. export const initialValues: Partial = { name: '', author: '', + dataTokenOptions: { + name: '', + symbol: '' + }, dockerImage: 'node:latest', image: 'node', containerTag: 'latest',