1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-23 01:36:47 +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
}
}
export default function FormEditMetadata({
data,
setShowEdit,
setTimeoutStringValue,
values,
showPrice
showPrice,
isComputeDataset
}: {
data: FormFieldProps[]
setShowEdit: (show: boolean) => void
setTimeoutStringValue: (value: string) => void
values: Partial<MetadataPublishFormDataset>
showPrice: boolean
isComputeDataset: boolean
}): ReactElement {
const { config } = useOcean()
const {
@ -70,12 +71,22 @@ export default function FormEditMetadata({
validateField(field.name)
setFieldValue(field.name, e.target.value)
}
// This component is handled by Formik so it's not rendered like a "normal" react component,
// so handleTimeoutCustomOption is called only once.
// https://github.com/oceanprotocol/market/pull/324#discussion_r561132310
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 (
<Form className={styles.form}>
{data.map(
@ -83,6 +94,11 @@ export default function FormEditMetadata({
(!showPrice && field.name === 'price') || (
<Field
key={field.name}
options={
field.name === 'timeout' && isComputeDataset === true
? timeoutOptionsArray
: field.options
}
{...field}
component={Input}
prefix={field.name === 'price' && config.oceanTokenSymbol}

View File

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

View File

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