1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-30 05:41:41 +02:00

Remove 'Forever' timeout on edit compute dataset (#795)

* add different options for compute asst timeout

* fix edit timeout options on dataset change
This commit is contained in:
claudiaHash 2021-08-20 18:05:06 +03:00 committed by GitHub
parent a545f723e9
commit 6e3a9bc8b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -41,19 +41,20 @@ function handleTimeoutCustomOption(
data[timeoutInputIndex].options[5] = values.timeout data[timeoutInputIndex].options[5] = values.timeout
} }
} }
export default function FormEditMetadata({ export default function FormEditMetadata({
data, data,
setShowEdit, setShowEdit,
setTimeoutStringValue, setTimeoutStringValue,
values, values,
showPrice showPrice,
isComputeDataset
}: { }: {
data: FormFieldProps[] data: FormFieldProps[]
setShowEdit: (show: boolean) => void setShowEdit: (show: boolean) => void
setTimeoutStringValue: (value: string) => void setTimeoutStringValue: (value: string) => void
values: Partial<MetadataPublishFormDataset> values: Partial<MetadataPublishFormDataset>
showPrice: boolean showPrice: boolean
isComputeDataset: boolean
}): ReactElement { }): ReactElement {
const { config } = useOcean() const { config } = useOcean()
const { const {
@ -70,12 +71,22 @@ export default function FormEditMetadata({
validateField(field.name) validateField(field.name)
setFieldValue(field.name, e.target.value) setFieldValue(field.name, e.target.value)
} }
// This component is handled by Formik so it's not rendered like a "normal" react component, // This component is handled by Formik so it's not rendered like a "normal" react component,
// so handleTimeoutCustomOption is called only once. // so handleTimeoutCustomOption is called only once.
// https://github.com/oceanprotocol/market/pull/324#discussion_r561132310 // https://github.com/oceanprotocol/market/pull/324#discussion_r561132310
if (data && values) handleTimeoutCustomOption(data, values) if (data && values) handleTimeoutCustomOption(data, values)
const timeoutOptionsArray = data.filter(
(field) => field.name === 'timeout'
)[0].options
if (isComputeDataset && timeoutOptionsArray.includes('Forever')) {
const foreverOptionIndex = timeoutOptionsArray.indexOf('Forever')
timeoutOptionsArray.splice(foreverOptionIndex, 1)
} else if (!isComputeDataset && !timeoutOptionsArray.includes('Forever')) {
timeoutOptionsArray.push('Forever')
}
return ( return (
<Form className={styles.form}> <Form className={styles.form}>
{data.map( {data.map(
@ -83,6 +94,11 @@ export default function FormEditMetadata({
(!showPrice && field.name === 'price') || ( (!showPrice && field.name === 'price') || (
<Field <Field
key={field.name} key={field.name}
options={
field.name === 'timeout' && isComputeDataset === true
? timeoutOptionsArray
: field.options
}
{...field} {...field}
component={Input} component={Input}
prefix={field.name === 'price' && config.oceanTokenSymbol} prefix={field.name === 'price' && config.oceanTokenSymbol}

View File

@ -55,9 +55,11 @@ const contentQuery = graphql`
` `
export default function Edit({ export default function Edit({
setShowEdit setShowEdit,
isComputeType
}: { }: {
setShowEdit: (show: boolean) => void setShowEdit: (show: boolean) => void
isComputeType?: boolean
}): ReactElement { }): ReactElement {
const data = useStaticQuery(contentQuery) const data = useStaticQuery(contentQuery)
const content = data.content.edges[0].node.childPagesJson const content = data.content.edges[0].node.childPagesJson
@ -201,6 +203,7 @@ export default function Edit({
setTimeoutStringValue={setTimeoutStringValue} setTimeoutStringValue={setTimeoutStringValue}
values={initialValues} values={initialValues}
showPrice={price.type === 'exchange'} showPrice={price.type === 'exchange'}
isComputeDataset={isComputeType}
/> />
<aside> <aside>

View File

@ -50,6 +50,7 @@ export default function AssetContent(props: AssetContentProps): ReactElement {
const { owner, isInPurgatory, purgatoryData, isAssetNetwork } = useAsset() const { owner, isInPurgatory, purgatoryData, isAssetNetwork } = useAsset()
const [showPricing, setShowPricing] = useState(false) const [showPricing, setShowPricing] = useState(false)
const [showEdit, setShowEdit] = useState<boolean>() const [showEdit, setShowEdit] = useState<boolean>()
const [isComputeType, setIsComputeType] = useState<boolean>(false)
const [showEditCompute, setShowEditCompute] = useState<boolean>() const [showEditCompute, setShowEditCompute] = useState<boolean>()
const [showEditAdvancedSettings, setShowEditAdvancedSettings] = const [showEditAdvancedSettings, setShowEditAdvancedSettings] =
useState<boolean>() useState<boolean>()
@ -63,7 +64,8 @@ export default function AssetContent(props: AssetContentProps): ReactElement {
const isOwner = accountId.toLowerCase() === owner.toLowerCase() const isOwner = accountId.toLowerCase() === owner.toLowerCase()
setIsOwner(isOwner) setIsOwner(isOwner)
setShowPricing(isOwner && price.type === '') setShowPricing(isOwner && price.type === '')
}, [accountId, price, owner]) setIsComputeType(Boolean(ddo.findServiceByType('compute')))
}, [accountId, price, owner, ddo])
function handleEditButton() { function handleEditButton() {
// move user's focus to top of screen // move user's focus to top of screen
@ -82,7 +84,7 @@ export default function AssetContent(props: AssetContentProps): ReactElement {
} }
return showEdit ? ( return showEdit ? (
<Edit setShowEdit={setShowEdit} /> <Edit setShowEdit={setShowEdit} isComputeType={isComputeType} />
) : showEditCompute ? ( ) : showEditCompute ? (
<EditComputeDataset setShowEdit={setShowEditCompute} /> <EditComputeDataset setShowEdit={setShowEditCompute} />
) : showEditAdvancedSettings ? ( ) : showEditAdvancedSettings ? (