mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Merge pull request #1655 from oceanprotocol/feature/issue-1244-edit-ui
adding UI for field files / links in edit form
This commit is contained in:
commit
508d615855
@ -31,6 +31,11 @@
|
|||||||
padding-right: calc(var(--spacer) / 2);
|
padding-right: calc(var(--spacer) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hideUrl {
|
||||||
|
filter: blur(0.2rem);
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
.warning {
|
.warning {
|
||||||
margin-top: calc(var(--spacer) / 3);
|
margin-top: calc(var(--spacer) / 3);
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
|
@ -15,9 +15,13 @@ export default function FileInfo({
|
|||||||
? cleanupContentType(file.contentType)
|
? cleanupContentType(file.contentType)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
const hideUrl = file.type === 'hidden' || false
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.info}>
|
<div className={`${styles.info}`}>
|
||||||
<h3 className={styles.url}>{file.url}</h3>
|
<h3 className={`${styles.url} ${hideUrl ? styles.hideUrl : null}`}>
|
||||||
|
{hideUrl ? 'https://oceanprotocol/placeholder' : file.url}
|
||||||
|
</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li className={styles.success}>✓ URL confirmed</li>
|
<li className={styles.success}>✓ URL confirmed</li>
|
||||||
{file.contentLength && <li>{prettySize(+file.contentLength)}</li>}
|
{file.contentLength && <li>{prettySize(+file.contentLength)}</li>}
|
||||||
|
@ -16,7 +16,7 @@ export default function FilesInput(props: InputProps): ReactElement {
|
|||||||
|
|
||||||
async function handleValidation(e: React.SyntheticEvent, url: string) {
|
async function handleValidation(e: React.SyntheticEvent, url: string) {
|
||||||
// File example 'https://oceanprotocol.com/tech-whitepaper.pdf'
|
// File example 'https://oceanprotocol.com/tech-whitepaper.pdf'
|
||||||
e.preventDefault()
|
e?.preventDefault()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const providerUrl = values?.services
|
const providerUrl = values?.services
|
||||||
@ -43,13 +43,14 @@ export default function FilesInput(props: InputProps): ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleClose() {
|
function handleClose() {
|
||||||
helpers.setValue(meta.initialValue)
|
|
||||||
helpers.setTouched(false)
|
helpers.setTouched(false)
|
||||||
|
helpers.setValue(meta.initialValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{field?.value?.[0]?.valid === true ? (
|
{field?.value?.[0]?.valid === true ||
|
||||||
|
field?.value?.[0]?.type === 'hidden' ? (
|
||||||
<FileInfo file={field.value[0]} handleClose={handleClose} />
|
<FileInfo file={field.value[0]} handleClose={handleClose} />
|
||||||
) : (
|
) : (
|
||||||
<UrlInput
|
<UrlInput
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useEffect } from 'react'
|
||||||
import { Field, Form } from 'formik'
|
import { Field, Form, useField, useFormikContext } from 'formik'
|
||||||
import Input, { InputProps } from '@shared/FormInput'
|
import Input, { InputProps } from '@shared/FormInput'
|
||||||
import FormActions from './FormActions'
|
import FormActions from './FormActions'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
|
import { FormPublishData } from 'src/components/Publish/_types'
|
||||||
|
import { getFileUrlInfo } from '@utils/provider'
|
||||||
|
|
||||||
export function checkIfTimeoutInPredefinedValues(
|
export function checkIfTimeoutInPredefinedValues(
|
||||||
timeout: string,
|
timeout: string,
|
||||||
@ -23,7 +25,8 @@ export default function FormEditMetadata({
|
|||||||
showPrice: boolean
|
showPrice: boolean
|
||||||
isComputeDataset: boolean
|
isComputeDataset: boolean
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { oceanConfig } = useAsset()
|
const { oceanConfig, asset } = useAsset()
|
||||||
|
const { values, setFieldValue } = useFormikContext<FormPublishData>()
|
||||||
|
|
||||||
// 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.
|
||||||
@ -41,6 +44,34 @@ export default function FormEditMetadata({
|
|||||||
timeoutOptionsArray.push('Forever')
|
timeoutOptionsArray.push('Forever')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// let's initiate files with empty url (we can't access the asset url) with type hidden (for UI frontend)
|
||||||
|
setFieldValue('files', [
|
||||||
|
{
|
||||||
|
url: '',
|
||||||
|
type: 'hidden'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
const providerUrl = values?.services
|
||||||
|
? values?.services[0].providerUrl.url
|
||||||
|
: asset.services[0].serviceEndpoint
|
||||||
|
// if we have a sample file, we need to get the files' info before setting defaults links value
|
||||||
|
asset?.metadata?.links?.[0] &&
|
||||||
|
getFileUrlInfo(asset.metadata.links[0], providerUrl).then(
|
||||||
|
(checkedFile) => {
|
||||||
|
console.log(checkedFile)
|
||||||
|
// initiate link with values from asset metadata
|
||||||
|
setFieldValue('links', [
|
||||||
|
{
|
||||||
|
url: asset.metadata.links[0],
|
||||||
|
...checkedFile[0]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
{data.map(
|
{data.map(
|
||||||
|
@ -11,7 +11,7 @@ export function getInitialValues(
|
|||||||
name: metadata?.name,
|
name: metadata?.name,
|
||||||
description: metadata?.description,
|
description: metadata?.description,
|
||||||
price,
|
price,
|
||||||
links: metadata?.links as any,
|
links: [{ url: '', type: '' }],
|
||||||
files: [{ url: '', type: '' }],
|
files: [{ url: '', type: '' }],
|
||||||
timeout: secondsToString(timeout),
|
timeout: secondsToString(timeout),
|
||||||
author: metadata?.author,
|
author: metadata?.author,
|
||||||
|
Loading…
Reference in New Issue
Block a user