mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01: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:
parent
a545f723e9
commit
6e3a9bc8b6
@ -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}
|
||||
|
@ -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>
|
||||
|
@ -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 ? (
|
||||
|
Loading…
Reference in New Issue
Block a user