From 960c5b32345f0de161e075ee8bc7965dadf1ddec Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 10 Dec 2020 14:30:40 +0100 Subject: [PATCH] Update metadata, the proper way (#292) * prototype view switching * refactor, more UI * formik form setup & data flow * debug output, fixes, refactor * description preview refactor * publish/update date changes * output created & updated date at top of asset * use ddo.created & ddo.updated everywhere * stop pushing metadata.main.datePublished * owner check for edit link * all the feedback states and switching between them: loading, error, success * refactor feedback, one component for publish & edit * action & date output fixes * move all content, iterate form fields from it * UI updates * styling tweaks * ddo dataflow refactor, more useAsset usage * more useAsset usage * form actions styling * prepare edit history component * metadata output tweaks * copy * safeguard against profile urls without protocol defined * refetch ddo after edit Signed-off-by: mihaisc * switch author for dataTokenOptions in metadata preview * refactor * copy * showPricing fix * validation: minimum characters for title & description * disable submit button when validation fails * form validation fixes * manually trigger onChange validation in publish & edit forms Co-authored-by: mihaisc --- content/pages/edit.json | 25 ++++ src/components/atoms/DebugOutput.tsx | 18 +++ src/components/atoms/Input/index.tsx | 12 +- src/components/atoms/Markdown.module.css | 8 + .../atoms/Publisher/PublisherLinks.tsx | 4 +- src/components/atoms/Time.tsx | 9 +- .../molecules/FormFields/FilesInput/Info.tsx | 28 ++-- .../molecules/FormFields/FilesInput/index.tsx | 10 +- .../MetadataFeedback.module.css} | 2 +- src/components/molecules/MetadataFeedback.tsx | 78 ++++++++++ .../MetadataPreview.module.css} | 3 +- src/components/molecules/MetadataPreview.tsx | 121 +++++++++++++++ .../organisms/AssetActions/Compute.tsx | 1 - .../organisms/AssetActions/Consume.tsx | 20 ++- .../organisms/AssetActions/Edit/Debug.tsx | 31 ++++ .../Edit/FormEditMetadata.module.css | 24 +++ .../AssetActions/Edit/FormEditMetadata.tsx | 57 +++++++ .../AssetActions/Edit/index.module.css | 10 ++ .../organisms/AssetActions/Edit/index.tsx | 139 ++++++++++++++++++ .../organisms/AssetActions/Pool/Add/index.tsx | 7 +- .../organisms/AssetActions/Pool/index.tsx | 19 ++- .../organisms/AssetActions/Trade/index.tsx | 5 +- .../organisms/AssetActions/index.tsx | 17 +-- .../AssetContent/EditHistory.module.css | 41 ++++++ .../organisms/AssetContent/EditHistory.tsx | 59 ++++++++ .../AssetContent/MetaFull.module.css | 6 +- .../organisms/AssetContent/MetaFull.tsx | 36 ++--- .../AssetContent/MetaItem.module.css | 4 + .../AssetContent/MetaMain.module.css | 13 ++ .../organisms/AssetContent/MetaMain.tsx | 34 +++++ .../AssetContent/MetaSecondary.module.css | 4 - .../organisms/AssetContent/MetaSecondary.tsx | 41 +++--- .../Pricing/FormPricing/Dynamic.tsx | 7 +- .../organisms/AssetContent/index.module.css | 30 ++-- .../organisms/AssetContent/index.tsx | 98 +++++------- src/components/pages/Publish/Debug.tsx | 16 +- src/components/pages/Publish/Feedback.tsx | 57 ------- src/components/pages/Publish/FormPublish.tsx | 30 +++- src/components/pages/Publish/Preview.tsx | 103 ------------- src/components/pages/Publish/index.tsx | 27 ++-- src/components/templates/PageAssetDetails.tsx | 29 ++-- src/models/FormEditMetadata.ts | 20 +++ src/models/FormPublish.ts | 6 +- src/providers/Asset.tsx | 60 +++++--- .../Publish/utils.ts => utils/metadata.ts} | 21 ++- tests/unit/components/PublishForm.test.tsx | 2 +- 46 files changed, 952 insertions(+), 440 deletions(-) create mode 100644 content/pages/edit.json create mode 100644 src/components/atoms/DebugOutput.tsx rename src/components/{pages/Publish/Feedback.module.css => molecules/MetadataFeedback.module.css} (91%) create mode 100644 src/components/molecules/MetadataFeedback.tsx rename src/components/{pages/Publish/Preview.module.css => molecules/MetadataPreview.module.css} (94%) create mode 100644 src/components/molecules/MetadataPreview.tsx create mode 100644 src/components/organisms/AssetActions/Edit/Debug.tsx create mode 100644 src/components/organisms/AssetActions/Edit/FormEditMetadata.module.css create mode 100644 src/components/organisms/AssetActions/Edit/FormEditMetadata.tsx create mode 100644 src/components/organisms/AssetActions/Edit/index.module.css create mode 100644 src/components/organisms/AssetActions/Edit/index.tsx create mode 100644 src/components/organisms/AssetContent/EditHistory.module.css create mode 100644 src/components/organisms/AssetContent/EditHistory.tsx create mode 100644 src/components/organisms/AssetContent/MetaMain.module.css create mode 100644 src/components/organisms/AssetContent/MetaMain.tsx delete mode 100644 src/components/pages/Publish/Feedback.tsx delete mode 100644 src/components/pages/Publish/Preview.tsx create mode 100644 src/models/FormEditMetadata.ts rename src/{components/pages/Publish/utils.ts => utils/metadata.ts} (75%) diff --git a/content/pages/edit.json b/content/pages/edit.json new file mode 100644 index 000000000..989be0e34 --- /dev/null +++ b/content/pages/edit.json @@ -0,0 +1,25 @@ +{ + "description": "Update selected metadata of this data set. Updating metadata will create an on-chain transaction you have to approve in your wallet.", + "form": { + "success": "🎉 Successfully updated. 🎉", + "successAction": "Close", + "error": "Updating DDO failed.", + "data": [ + { + "name": "name", + "label": "New Title", + "placeholder": "e.g. Shapes of Desert Plants", + "help": "Enter a concise title.", + "required": true + }, + { + "name": "description", + "label": "New Description", + "help": "Add a thorough description with as much detail as possible. You can use [Markdown](https://daringfireball.net/projects/markdown/basics).", + "type": "textarea", + "rows": 10, + "required": true + } + ] + } +} diff --git a/src/components/atoms/DebugOutput.tsx b/src/components/atoms/DebugOutput.tsx new file mode 100644 index 000000000..282e6e9b1 --- /dev/null +++ b/src/components/atoms/DebugOutput.tsx @@ -0,0 +1,18 @@ +import React, { ReactElement } from 'react' + +export default function DebugOutput({ + title, + output +}: { + title: string + output: any +}): ReactElement { + return ( +
+
{title}
+
+        {JSON.stringify(output, null, 2)}
+      
+
+ ) +} diff --git a/src/components/atoms/Input/index.tsx b/src/components/atoms/Input/index.tsx index 85d5ca3c5..55228fb33 100644 --- a/src/components/atoms/Input/index.tsx +++ b/src/components/atoms/Input/index.tsx @@ -44,15 +44,7 @@ export interface InputProps { } export default function Input(props: Partial): ReactElement { - const { - required, - name, - label, - help, - additionalComponent, - size, - field - } = props + const { label, help, additionalComponent, size, field } = props const hasError = props.form?.touched[field.name] && props.form?.errors[field.name] @@ -67,7 +59,7 @@ export default function Input(props: Partial): ReactElement { className={styleClasses} data-is-submitting={props.form?.isSubmitting ? true : null} > -