From 30108ab2c003f0dccee4a520c0110863209b6c0a Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 12 Nov 2024 00:14:41 +0930 Subject: [PATCH 01/29] feat: Support Markdown field ref: #26 #27 nofusscomputing/centurion_erp#248 nofusscomputing/centurion_erp#388 --- src/components/page/detail/DoubleColumn.jsx | 95 +++++++++++---------- src/components/page/detail/Section.jsx | 8 ++ src/components/page/detail/SingleColumn.jsx | 6 +- src/functions/FieldData.js | 23 ++--- src/layout/ModelForm.jsx | 13 ++- 5 files changed, 82 insertions(+), 63 deletions(-) diff --git a/src/components/page/detail/DoubleColumn.jsx b/src/components/page/detail/DoubleColumn.jsx index 42b31909..b031bd4d 100644 --- a/src/components/page/detail/DoubleColumn.jsx +++ b/src/components/page/detail/DoubleColumn.jsx @@ -6,7 +6,8 @@ const DoubleColumn = ({ data, metadata, left = [], - right = [] + right = [], + textarea_fields = [] }) => { @@ -15,7 +16,7 @@ const DoubleColumn = ({
{left.map((field) => ( ( - field != "model_notes" ? + ( ! textarea_fields.includes(String(metadata.fields[field].type).toLowerCase()) ) ?
- {right.map((field) => ( - ( - field != "model_notes" ? -
- - - - -
: -
- -
- -
-
- ) - ))} + {right.map((field) => { + + if( field in metadata.fields ) { + return ( + + ( ! textarea_fields.includes(String(metadata.fields[field].type).toLowerCase()) ) ? +
+ + + + +
: +
+ +
+ +
+
+ ) + } + })}
); diff --git a/src/components/page/detail/Section.jsx b/src/components/page/detail/Section.jsx index a722ae79..b01d3c6d 100644 --- a/src/components/page/detail/Section.jsx +++ b/src/components/page/detail/Section.jsx @@ -24,6 +24,12 @@ const Section = ({ let column + + let textarea_fields = [ + 'json', + 'markdown' + ] + if( layout.layout === 'double' ) { column = ( @@ -32,6 +38,7 @@ const Section = ({ metadata={metadata} left={layout.left} right={layout.right} + textarea_fields = {textarea_fields} /> ) @@ -42,6 +49,7 @@ const Section = ({ data={data} metadata={metadata} fields={layout.fields} + textarea_fields = {textarea_fields} /> ) diff --git a/src/components/page/detail/SingleColumn.jsx b/src/components/page/detail/SingleColumn.jsx index 968522da..b2141eff 100644 --- a/src/components/page/detail/SingleColumn.jsx +++ b/src/components/page/detail/SingleColumn.jsx @@ -5,7 +5,8 @@ import FieldData from "../../../functions/FieldData"; const SingleColumn = ({ data, metadata, - fields = [] + fields = [], + textarea_fields = [] }) => { let fieldClass = 'text' @@ -16,8 +17,7 @@ const SingleColumn = ({ {fields.map((field) => { if( - field == "model_notes" - || String(metadata.fields[field].type).toLowerCase() == "json" + ( textarea_fields.includes(String(metadata.fields[field].type).toLowerCase()) ) ) { return( diff --git a/src/functions/FieldData.js b/src/functions/FieldData.js index 19478a94..f80504fd 100644 --- a/src/functions/FieldData.js +++ b/src/functions/FieldData.js @@ -200,6 +200,15 @@ export default function FieldData({ break; + case 'Markdown': + + field_data = ( + + {data_field} + + ) + + break; default: if( @@ -227,20 +236,6 @@ export default function FieldData({ } - if( - - field_name == 'description' || field_name == 'body' || field_name == 'model_notes' - - ) { - - field_data = ( - - {field_data} - - ) - - } - return field_data; } diff --git a/src/layout/ModelForm.jsx b/src/layout/ModelForm.jsx index 9e0d66d0..3f559673 100644 --- a/src/layout/ModelForm.jsx +++ b/src/layout/ModelForm.jsx @@ -198,7 +198,18 @@ const ModelForm = ({ case 'JSON': return ( {error_text} From 6a4946862fdd63fb2786fb0f5f94dc6f784930ce Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 13 Nov 2024 17:07:55 +0930 Subject: [PATCH 14/29] refactor(component): Pass field object directly to textarea pasing the whole object as the component is to do ALL logic for the field ref: #26 #27 nofusscomputing/centurion_erp#248 nofusscomputing/centurion_erp#388 --- src/components/form/Textarea.jsx | 48 ++++++++++++++++++++++++++++---- src/layout/ModelForm.jsx | 12 ++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/components/form/Textarea.jsx b/src/components/form/Textarea.jsx index d732072f..ad65f0f5 100644 --- a/src/components/form/Textarea.jsx +++ b/src/components/form/Textarea.jsx @@ -1,18 +1,56 @@ const TextArea = ({ id, - label, - helptext=null, - required=false, error_text=null, value= '', onChange = null, - class_name = null + class_name = null, + field_data = null }) => { if( value === null ) { value = '' } + let field_class_name = "common-field" + let helptext = null + let required = false + let label = '' + + if( field_data ) { + + field_data = Object(field_data) + + + + if( 'help_text' in field_data) { + + helptext = field_data['help_text'] + + } + + if( 'label' in field_data ) { + + label = field_data['label'] + + } + + if( 'required' in field_data) { + + required = field_data['required'] + + } + + if( 'style' in field_data ) { + + if( 'class' in field_data.style ) { + + field_class_name += String( ' ' + field_data['style']['class']) + + } + } + } + + return (
@@ -20,7 +58,7 @@ const TextArea = ({