1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Add datatoken to algo publish form (#531)

* datatoken added to algo publish form

* init datatoken option with non empty values

* remove hacks

* use nonempty data token initial values

Co-authored-by: claudia.holhos <claudia.holhos@hpm.ro>
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
claudiaHash 2021-04-26 14:43:58 +03:00 committed by GitHub
parent b89fcc99da
commit c0157dff21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 5 deletions

View File

@ -56,6 +56,13 @@
"sortOptions": false, "sortOptions": false,
"required": true "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", "name": "entrypoint",
"label": "Entrypoint", "label": "Entrypoint",

View File

@ -49,6 +49,7 @@ export interface MetadataPublishFormAlgorithm {
dockerImage: string dockerImage: string
algorithmPrivacy: boolean algorithmPrivacy: boolean
timeout: string timeout: string
dataTokenOptions: DataTokenOptions
termsAndConditions: boolean termsAndConditions: boolean
// ---- optional fields ---- // ---- optional fields ----
image: string image: string

View File

@ -135,6 +135,11 @@ export function MetadataAlgorithmPreview({
<h2 className={styles.previewTitle}>Preview</h2> <h2 className={styles.previewTitle}>Preview</h2>
<header> <header>
{values.name && <h3 className={styles.title}>{values.name}</h3>} {values.name && <h3 className={styles.title}>{values.name}</h3>}
{values.dataTokenOptions?.name && (
<p
className={styles.datatoken}
>{`${values.dataTokenOptions.name}${values.dataTokenOptions.symbol}`}</p>
)}
{values.description && <Description description={values.description} />} {values.description && <Description description={values.description} />}
<div className={styles.asset}> <div className={styles.asset}>

View File

@ -62,12 +62,11 @@ export default function FormPublish(): ReactElement {
const [selectedDockerImage, setSelectedDockerImage] = useState<string>( const [selectedDockerImage, setSelectedDockerImage] = useState<string>(
initialValues.dockerImage initialValues.dockerImage
) )
// reset form validation on every mount // reset form validation on every mount
useEffect(() => { useEffect(() => {
setErrors({}) setErrors({})
setTouched({}) setTouched({})
// setSubmitting(false)
}, [setErrors, setTouched]) }, [setErrors, setTouched])
function handleImageSelectChange(imageSelected: string) { function handleImageSelectChange(imageSelected: string) {

View File

@ -95,9 +95,22 @@ export default function PublishPage({
const [publishType, setPublishType] = useState<MetadataMain['type']>( const [publishType, setPublishType] = useState<MetadataMain['type']>(
'dataset' 'dataset'
) )
const hasFeedback = isLoading || error || success 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(() => { useEffect(() => {
publishType === 'dataset' publishType === 'dataset'
? setTitle('Publishing Data Set') ? setTitle('Publishing Data Set')
@ -166,12 +179,12 @@ export default function PublishPage({
: true : true
try { try {
if (validDockerImage) { if (validDockerImage) {
Logger.log('Publish Algorithm with ', metadata) Logger.log('Publish algorithm with ', metadata, values.dataTokenOptions)
const ddo = await publish( const ddo = await publish(
(metadata as unknown) as Metadata, (metadata as unknown) as Metadata,
values.algorithmPrivacy === true ? 'compute' : 'access', values.algorithmPrivacy === true ? 'compute' : 'access',
undefined, values.dataTokenOptions,
timeout timeout
) )

View File

@ -11,6 +11,12 @@ export const validationSchema: Yup.SchemaOf<MetadataPublishFormAlgorithm> = Yup.
description: Yup.string().min(10).required('Required'), description: Yup.string().min(10).required('Required'),
files: Yup.array<FileMetadata>().required('Required').nullable(), files: Yup.array<FileMetadata>().required('Required').nullable(),
timeout: Yup.string().required('Required'), timeout: Yup.string().required('Required'),
dataTokenOptions: Yup.object()
.shape({
name: Yup.string(),
symbol: Yup.string()
})
.required('Required'),
dockerImage: Yup.string() dockerImage: Yup.string()
.matches(/node:latest|python:latest|custom image/g, { .matches(/node:latest|python:latest|custom image/g, {
excludeEmptyString: true excludeEmptyString: true
@ -31,6 +37,10 @@ export const validationSchema: Yup.SchemaOf<MetadataPublishFormAlgorithm> = Yup.
export const initialValues: Partial<MetadataPublishFormAlgorithm> = { export const initialValues: Partial<MetadataPublishFormAlgorithm> = {
name: '', name: '',
author: '', author: '',
dataTokenOptions: {
name: '',
symbol: ''
},
dockerImage: 'node:latest', dockerImage: 'node:latest',
image: 'node', image: 'node',
containerTag: 'latest', containerTag: 'latest',