From 778abc8aeb8527f577678b917e6ccb80ce69d705 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 28 Oct 2021 11:33:29 +0100 Subject: [PATCH] more fields, more custom onChange handler removals --- content/publish/form.json | 21 +++++++++- .../@shared/Form/FormFields/BoxSelection.tsx | 22 +++++----- .../@shared/Form/FormFields/Terms.module.css | 25 ----------- .../@shared/Form/FormFields/Terms.tsx | 17 -------- .../@shared/Form/Input/InputElement.tsx | 11 +++-- src/components/@shared/Form/Input/index.tsx | 30 +++++++++++++- .../Publish/FormPublish/Metadata/index.tsx | 16 +++++++- .../Publish/FormPublish/Preview/index.tsx | 10 ++--- .../Publish/FormPublish/Services/index.tsx | 41 ++++++++++++++++--- src/components/Publish/FormPublish/index.tsx | 13 ++++++ src/components/Publish/_constants.ts | 3 +- 11 files changed, 133 insertions(+), 76 deletions(-) delete mode 100644 src/components/@shared/Form/FormFields/Terms.module.css delete mode 100644 src/components/@shared/Form/FormFields/Terms.tsx diff --git a/content/publish/form.json b/content/publish/form.json index 316eecde9..dc14d284b 100644 --- a/content/publish/form.json +++ b/content/publish/form.json @@ -31,7 +31,7 @@ { "name": "termsAndConditions", "label": "Terms & Conditions", - "type": "terms", + "type": "checkbox", "options": ["I agree to these Terms and Conditions"], "required": true } @@ -40,6 +40,20 @@ "services": { "title": "Access", "fields": [ + { + "name": "type", + "label": "Asset Type", + "type": "boxSelection", + "options": ["Dataset", "Algorithm"], + "required": true + }, + { + "name": "dataTokenOptions", + "label": "Datatoken Name & Symbol", + "type": "datatoken", + "help": "The datatoken for this data set will be created with this name & symbol.", + "required": true + }, { "name": "dataTokenOptions", "label": "Datatoken Name & Symbol", @@ -95,8 +109,11 @@ "title": "Pricing", "fields": [ { - "name": "dummy content, as content is defined under 'create' key in ../price.json" + "name": "dummy content, actual content is defined under 'create' key in ../price.json" } ] + }, + "preview": { + "title": "Preview" } } diff --git a/src/components/@shared/Form/FormFields/BoxSelection.tsx b/src/components/@shared/Form/FormFields/BoxSelection.tsx index f1935cf8d..7cab79509 100644 --- a/src/components/@shared/Form/FormFields/BoxSelection.tsx +++ b/src/components/@shared/Form/FormFields/BoxSelection.tsx @@ -40,27 +40,27 @@ export default function BoxSelection({ {!options ? ( ) : ( - options.map((value: BoxSelectionOption) => ( -
+ options.map((option: BoxSelectionOption) => ( +
handleChange(event)} + defaultChecked={option.checked} + onChange={(event) => handleChange(event)} {...props} disabled={disabled} - value={value.name} + value={option.name} name={name} />
)) diff --git a/src/components/@shared/Form/FormFields/Terms.module.css b/src/components/@shared/Form/FormFields/Terms.module.css deleted file mode 100644 index ffadc2c19..000000000 --- a/src/components/@shared/Form/FormFields/Terms.module.css +++ /dev/null @@ -1,25 +0,0 @@ -.terms { - composes: content from '@shared/Page/PageMarkdown.module.css'; - - padding: calc(var(--spacer) / 2); - border: 1px solid var(--border-color); - background-color: var(--background-highlight); - border-radius: var(--border-radius); - margin-bottom: calc(var(--spacer) / 2); - font-size: var(--font-size-small); - - max-height: 250px; - /* smooth overflow scrolling for pre-iOS 13 */ - overflow: auto; - -webkit-overflow-scrolling: touch; -} - -.terms h1 { - font-size: var(--font-size-base); - margin-bottom: calc(var(--spacer) / 2); -} - -.terms h2 { - font-size: var(--font-size-small); - margin-bottom: calc(var(--spacer) / 2); -} diff --git a/src/components/@shared/Form/FormFields/Terms.tsx b/src/components/@shared/Form/FormFields/Terms.tsx deleted file mode 100644 index 2a6d437da..000000000 --- a/src/components/@shared/Form/FormFields/Terms.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React, { ReactElement } from 'react' -import { InputProps } from '@shared/Form/Input' -import InputElement from '@shared/Form/Input/InputElement' -import styles from './Terms.module.css' - -export default function Terms(props: InputProps): ReactElement { - const termsProps: InputProps = { - ...props, - defaultChecked: props.value?.toString() === 'true' - } - - return ( - <> - - - ) -} diff --git a/src/components/@shared/Form/Input/InputElement.tsx b/src/components/@shared/Form/Input/InputElement.tsx index fbbb0d514..7f964f015 100644 --- a/src/components/@shared/Form/Input/InputElement.tsx +++ b/src/components/@shared/Form/Input/InputElement.tsx @@ -4,7 +4,6 @@ import styles from './InputElement.module.css' import { InputProps } from '.' import FilesInput from '../FormFields/FilesInput' import CustomProvider from '../FormFields/CustomProvider' -import Terms from '../FormFields/Terms' import BoxSelection, { BoxSelectionOption } from '../FormFields/BoxSelection' import Datatoken from '../FormFields/Datatoken' import classNames from 'classnames/bind' @@ -54,7 +53,9 @@ export default function InputElement({ const sortedOptions = !sortOptions && sortOptions === false ? options - : options.sort((a: string, b: string) => a.localeCompare(b)) + : (options as string[]).sort((a: string, b: string) => + a.localeCompare(b) + ) return ( case 'datatoken': return - case 'terms': - return case 'boxSelection': return ( { +export interface InputProps { + name: string label?: string | ReactNode placeholder?: string required?: boolean @@ -20,7 +29,23 @@ export interface InputProps extends FieldInputProps { options?: string[] sortOptions?: boolean additionalComponent?: ReactElement + value?: string + onChange?( + e: + | FormEvent + | ChangeEvent + | ChangeEvent + | ChangeEvent + ): void + onKeyPress?( + e: + | KeyboardEvent + | KeyboardEvent + | KeyboardEvent + | KeyboardEvent + ): void rows?: number + multiple?: boolean pattern?: string min?: string max?: string @@ -34,6 +59,7 @@ export interface InputProps extends FieldInputProps { defaultChecked?: boolean size?: 'mini' | 'small' | 'large' | 'default' className?: string + checked?: boolean disclaimer?: string disclaimerValues?: string[] } diff --git a/src/components/Publish/FormPublish/Metadata/index.tsx b/src/components/Publish/FormPublish/Metadata/index.tsx index adda032d9..a29892158 100644 --- a/src/components/Publish/FormPublish/Metadata/index.tsx +++ b/src/components/Publish/FormPublish/Metadata/index.tsx @@ -1,10 +1,14 @@ import Input from '@shared/Form/Input' -import { Field } from 'formik' +import { Field, useFormikContext } from 'formik' import React, { ReactElement } from 'react' import content from '../../../../../content/publish/form.json' +import { FormPublishData } from '../../_types' import { getFieldContent } from '../../_utils' export default function MetadataFields(): ReactElement { + // connect with Form state, use for conditional field rendering + const { values } = useFormikContext() + return ( <> + +
+ Fancy NFT display +

+ Place to show that metadata becomes part of a NFT. Plan is to + autogenerate some graphic, display it here, and pass that graphic to + the publish methods. +

+
+ (false) @@ -87,13 +88,10 @@ function Sample({ url }: { url: string }) { ) } -export function MetadataPreview({ - values -}: { - values: Partial -}): ReactElement { +export default function Preview(): ReactElement { const { networkId } = useWeb3() const { isAssetNetwork } = useAsset() + const { values } = useFormikContext() return (
diff --git a/src/components/Publish/FormPublish/Services/index.tsx b/src/components/Publish/FormPublish/Services/index.tsx index c10d309d1..c586ab521 100644 --- a/src/components/Publish/FormPublish/Services/index.tsx +++ b/src/components/Publish/FormPublish/Services/index.tsx @@ -1,27 +1,58 @@ import Input from '@shared/Form/Input' -import { Field } from 'formik' +import { Field, useFormikContext } from 'formik' import React, { ReactElement } from 'react' import IconDownload from '@images/download.svg' import IconCompute from '@images/compute.svg' import content from '../../../../../content/publish/form.json' import { getFieldContent } from '../../_utils' +import { FormPublishData } from '../../_types' + +const accessTypeOptionsTitles = getFieldContent( + 'access', + content.services.fields +).options const accessTypeOptions = [ { - name: 'Download', - title: 'Download', + name: accessTypeOptionsTitles[0].toLowerCase(), + title: accessTypeOptionsTitles[0], icon: }, { - name: 'Compute', - title: 'Compute', + name: accessTypeOptionsTitles[1].toLowerCase(), + title: accessTypeOptionsTitles[1], icon: } ] +const assetTypeOptionsTitles = getFieldContent( + 'type', + content.services.fields +).options + +const assetTypeOptions = [ + { + name: assetTypeOptionsTitles[0].toLowerCase(), + title: assetTypeOptionsTitles[0] + }, + { + name: assetTypeOptionsTitles[1].toLowerCase(), + title: assetTypeOptionsTitles[1] + } +] + export default function ServicesFields(): ReactElement { + // connect with Form state, use for conditional field rendering + const { values } = useFormikContext() + return ( <> + = @@ -68,6 +69,18 @@ export default function FormPublish(): ReactElement { /> ) + }, + { + title: content.preview.title, + content: ( + <> + + + + ) } ] diff --git a/src/components/Publish/_constants.ts b/src/components/Publish/_constants.ts index d9b95e7b2..1be75eddd 100644 --- a/src/components/Publish/_constants.ts +++ b/src/components/Publish/_constants.ts @@ -1,9 +1,10 @@ import { File as FileMetadata } from '@oceanprotocol/lib' import * as Yup from 'yup' -import { allowDynamicPricing, allowFixedPricing } from '../../../app.config' +import { allowDynamicPricing, allowFixedPricing } from '../../../app.config.js' import { FormPublishData } from './_types' export const initialValues: Partial = { + type: 'dataset', metadata: { name: '', author: '',