mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
hide image/tag/entrypoint when pre-defined docker image is selected
This commit is contained in:
parent
e92f759898
commit
7ef538818a
@ -36,7 +36,6 @@
|
|||||||
"name": "image",
|
"name": "image",
|
||||||
"label": "Image URL",
|
"label": "Image URL",
|
||||||
"placeholder": "e.g. oceanprotocol/algo_dockers or https://example.com/image_path",
|
"placeholder": "e.g. oceanprotocol/algo_dockers or https://example.com/image_path",
|
||||||
"disabled": true,
|
|
||||||
"help": "Provide the name of a public docker image or the full url if you have it hosted in a 3rd party repo",
|
"help": "Provide the name of a public docker image or the full url if you have it hosted in a 3rd party repo",
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
@ -45,7 +44,6 @@
|
|||||||
"label": "Docker Image Tag",
|
"label": "Docker Image Tag",
|
||||||
"placeholder": "e.g. latest",
|
"placeholder": "e.g. latest",
|
||||||
"help": "Provide the tag for your docker image.",
|
"help": "Provide the tag for your docker image.",
|
||||||
"disabled": true,
|
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -53,7 +51,6 @@
|
|||||||
"label": "Entrypoint",
|
"label": "Entrypoint",
|
||||||
"placeholder": "e.g. python $ALGO",
|
"placeholder": "e.g. python $ALGO",
|
||||||
"help": "Provide the entrypoint for your algorithm.",
|
"help": "Provide the entrypoint for your algorithm.",
|
||||||
"disabled": true,
|
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import React, { ReactElement, useEffect, FormEvent, ChangeEvent } from 'react'
|
import React, {
|
||||||
|
ReactElement,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
FormEvent,
|
||||||
|
ChangeEvent
|
||||||
|
} from 'react'
|
||||||
import { useStaticQuery, graphql } from 'gatsby'
|
import { useStaticQuery, graphql } from 'gatsby'
|
||||||
import styles from './FormPublish.module.css'
|
import styles from './FormPublish.module.css'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
@ -25,7 +31,6 @@ const query = graphql`
|
|||||||
help
|
help
|
||||||
type
|
type
|
||||||
required
|
required
|
||||||
disabled
|
|
||||||
sortOptions
|
sortOptions
|
||||||
options
|
options
|
||||||
}
|
}
|
||||||
@ -52,7 +57,9 @@ export default function FormPublish(): ReactElement {
|
|||||||
validateField,
|
validateField,
|
||||||
setFieldValue
|
setFieldValue
|
||||||
}: FormikContextType<MetadataPublishFormAlgorithm> = useFormikContext()
|
}: FormikContextType<MetadataPublishFormAlgorithm> = useFormikContext()
|
||||||
|
const [selectedDockerImage, setSelectedDockerImage] = useState<string>(
|
||||||
|
initialValues.dockerImage
|
||||||
|
)
|
||||||
// reset form validation on every mount
|
// reset form validation on every mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setErrors({})
|
setErrors({})
|
||||||
@ -61,33 +68,21 @@ export default function FormPublish(): ReactElement {
|
|||||||
// setSubmitting(false)
|
// setSubmitting(false)
|
||||||
}, [setErrors, setTouched])
|
}, [setErrors, setTouched])
|
||||||
|
|
||||||
function setDisableFlag(flag: boolean) {
|
|
||||||
content.data.forEach((field) => {
|
|
||||||
if (field.disabled !== null) field.disabled = flag
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleImageSelectChange(imageSelected: string) {
|
function handleImageSelectChange(imageSelected: string) {
|
||||||
switch (imageSelected) {
|
switch (imageSelected) {
|
||||||
case 'node:pre-defined': {
|
case 'node:pre-defined': {
|
||||||
setFieldValue('dockerImage', imageSelected)
|
|
||||||
setDisableFlag(true)
|
|
||||||
setFieldValue('image', 'node')
|
setFieldValue('image', 'node')
|
||||||
setFieldValue('containerTag', '10')
|
setFieldValue('containerTag', '10')
|
||||||
setFieldValue('entrypoint', 'node $ALGO')
|
setFieldValue('entrypoint', 'node $ALGO')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'python:pre-defined': {
|
case 'python:pre-defined': {
|
||||||
setFieldValue('dockerImage', imageSelected)
|
|
||||||
setDisableFlag(true)
|
|
||||||
setFieldValue('image', 'oceanprotocol/algo_dockers')
|
setFieldValue('image', 'oceanprotocol/algo_dockers')
|
||||||
setFieldValue('containerTag', 'python-panda')
|
setFieldValue('containerTag', 'python-panda')
|
||||||
setFieldValue('entrypoint', 'python $ALGO')
|
setFieldValue('entrypoint', 'python $ALGO')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
setFieldValue('dockerImage', imageSelected)
|
|
||||||
setDisableFlag(false)
|
|
||||||
setFieldValue('image', '')
|
setFieldValue('image', '')
|
||||||
setFieldValue('containerTag', '')
|
setFieldValue('containerTag', '')
|
||||||
setFieldValue('entrypoint', '')
|
setFieldValue('entrypoint', '')
|
||||||
@ -105,12 +100,11 @@ export default function FormPublish(): ReactElement {
|
|||||||
const value =
|
const value =
|
||||||
field.type === 'checkbox' ? !JSON.parse(e.target.value) : e.target.value
|
field.type === 'checkbox' ? !JSON.parse(e.target.value) : e.target.value
|
||||||
if (field.name === 'dockerImage') {
|
if (field.name === 'dockerImage') {
|
||||||
validateField(field.name)
|
setSelectedDockerImage(e.target.value)
|
||||||
handleImageSelectChange(e.target.value)
|
handleImageSelectChange(e.target.value)
|
||||||
} else {
|
|
||||||
validateField(field.name)
|
|
||||||
setFieldValue(field.name, value)
|
|
||||||
}
|
}
|
||||||
|
validateField(field.name)
|
||||||
|
setFieldValue(field.name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetFormAndClearStorage = (e: FormEvent<Element>) => {
|
const resetFormAndClearStorage = (e: FormEvent<Element>) => {
|
||||||
@ -126,17 +120,23 @@ export default function FormPublish(): ReactElement {
|
|||||||
onChange={() => status === 'empty' && setStatus(null)}
|
onChange={() => status === 'empty' && setStatus(null)}
|
||||||
>
|
>
|
||||||
<h2 className={stylesIndex.formTitle}>{content.title}</h2>
|
<h2 className={stylesIndex.formTitle}>{content.title}</h2>
|
||||||
{content.data.map((field: FormFieldProps) => (
|
{content.data.map(
|
||||||
<Field
|
(field: FormFieldProps) =>
|
||||||
key={field.name}
|
((field.name !== 'entrypoint' &&
|
||||||
{...field}
|
field.name !== 'image' &&
|
||||||
disabled={field.disabled}
|
field.name !== 'containerTag') ||
|
||||||
component={Input}
|
selectedDockerImage === 'custom image') && (
|
||||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
<Field
|
||||||
handleFieldChange(e, field)
|
key={field.name}
|
||||||
}
|
{...field}
|
||||||
/>
|
disabled={field.disabled}
|
||||||
))}
|
component={Input}
|
||||||
|
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
handleFieldChange(e, field)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
<footer className={styles.actions}>
|
<footer className={styles.actions}>
|
||||||
<Button
|
<Button
|
||||||
|
@ -25,7 +25,6 @@ const query = graphql`
|
|||||||
help
|
help
|
||||||
type
|
type
|
||||||
required
|
required
|
||||||
disabled
|
|
||||||
sortOptions
|
sortOptions
|
||||||
options
|
options
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user