mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
add outline when an input has changed
This commit is contained in:
parent
c3c681c9ff
commit
3ec3d8545b
@ -24,6 +24,7 @@ import { useAsset } from '@context/Asset'
|
|||||||
import { setNftMetadata } from '@utils/nft'
|
import { setNftMetadata } from '@utils/nft'
|
||||||
import { sanitizeUrl } from '@utils/url'
|
import { sanitizeUrl } from '@utils/url'
|
||||||
import { getEncryptedFiles } from '@utils/provider'
|
import { getEncryptedFiles } from '@utils/provider'
|
||||||
|
import { initialValues } from 'src/components/Publish/_constants'
|
||||||
|
|
||||||
export default function Edit({
|
export default function Edit({
|
||||||
asset
|
asset
|
||||||
@ -139,14 +140,16 @@ export default function Edit({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const initialValues = getInitialValues(
|
||||||
<Formik
|
|
||||||
enableReinitialize
|
|
||||||
initialValues={getInitialValues(
|
|
||||||
asset?.metadata,
|
asset?.metadata,
|
||||||
asset?.services[0]?.timeout,
|
asset?.services[0]?.timeout,
|
||||||
asset?.accessDetails?.price
|
asset?.accessDetails?.price
|
||||||
)}
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Formik
|
||||||
|
enableReinitialize
|
||||||
|
initialValues={initialValues}
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
onSubmit={async (values, { resetForm }) => {
|
onSubmit={async (values, { resetForm }) => {
|
||||||
// move user's focus to top of screen
|
// move user's focus to top of screen
|
||||||
@ -176,6 +179,8 @@ export default function Edit({
|
|||||||
data={content.form.data}
|
data={content.form.data}
|
||||||
showPrice={asset?.accessDetails?.type === 'fixed'}
|
showPrice={asset?.accessDetails?.type === 'fixed'}
|
||||||
isComputeDataset={isComputeType}
|
isComputeDataset={isComputeType}
|
||||||
|
initialValues={initialValues}
|
||||||
|
currentValues={values}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Web3Feedback
|
<Web3Feedback
|
||||||
|
5
src/components/Asset/Edit/FormEditMetadata.module.css
Normal file
5
src/components/Asset/Edit/FormEditMetadata.module.css
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.inputChanged input,
|
||||||
|
.inputChanged textarea,
|
||||||
|
.inputChanged select {
|
||||||
|
border: 1px solid var(--color-primary);
|
||||||
|
}
|
@ -3,6 +3,7 @@ import { Field, Form } 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 styles from './FormEditMetadata.module.css'
|
||||||
|
|
||||||
export function checkIfTimeoutInPredefinedValues(
|
export function checkIfTimeoutInPredefinedValues(
|
||||||
timeout: string,
|
timeout: string,
|
||||||
@ -17,14 +18,28 @@ export function checkIfTimeoutInPredefinedValues(
|
|||||||
export default function FormEditMetadata({
|
export default function FormEditMetadata({
|
||||||
data,
|
data,
|
||||||
showPrice,
|
showPrice,
|
||||||
isComputeDataset
|
isComputeDataset,
|
||||||
|
initialValues,
|
||||||
|
currentValues
|
||||||
}: {
|
}: {
|
||||||
data: InputProps[]
|
data: InputProps[]
|
||||||
showPrice: boolean
|
showPrice: boolean
|
||||||
isComputeDataset: boolean
|
isComputeDataset: boolean
|
||||||
|
initialValues: any
|
||||||
|
currentValues: any
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { oceanConfig } = useAsset()
|
const { oceanConfig } = useAsset()
|
||||||
|
|
||||||
|
// get diff between initial value and current value to get inputs changed
|
||||||
|
// we'll add an outline when an input has changed
|
||||||
|
const getDifference = (a: any, b: any) =>
|
||||||
|
Object.entries(a).reduce(
|
||||||
|
(ac, [k, v]) => (b[k] && b[k] !== v ? ((ac[k] = b[k]), ac) : ac),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
const diff = getDifference(initialValues, currentValues)
|
||||||
|
|
||||||
// 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
|
||||||
@ -43,9 +58,11 @@ export default function FormEditMetadata({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
{data.map(
|
{data.map((field: InputProps) => {
|
||||||
(field: InputProps) =>
|
const fieldHasChanged = Object.keys(diff).includes(field.name)
|
||||||
|
return (
|
||||||
(!showPrice && field.name === 'price') || (
|
(!showPrice && field.name === 'price') || (
|
||||||
|
<span className={fieldHasChanged ? styles.inputChanged : null}>
|
||||||
<Field
|
<Field
|
||||||
key={field.name}
|
key={field.name}
|
||||||
options={
|
options={
|
||||||
@ -57,8 +74,10 @@ export default function FormEditMetadata({
|
|||||||
component={Input}
|
component={Input}
|
||||||
prefix={field.name === 'price' && oceanConfig?.oceanTokenSymbol}
|
prefix={field.name === 'price' && oceanConfig?.oceanTokenSymbol}
|
||||||
/>
|
/>
|
||||||
|
</span>
|
||||||
)
|
)
|
||||||
)}
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
<FormActions />
|
<FormActions />
|
||||||
</Form>
|
</Form>
|
||||||
|
Loading…
Reference in New Issue
Block a user