From 4c664876b5e1fa9cf4cc7091b10912b0edb5dc33 Mon Sep 17 00:00:00 2001 From: Vikash Prem Sharma Date: Tue, 26 Nov 2024 15:25:54 +0530 Subject: [PATCH] Group the custom fields by required and optional on asset create/edit form --- .../assets/custom-fields-inputs.tsx | 127 +++++++++++++----- 1 file changed, 93 insertions(+), 34 deletions(-) diff --git a/app/components/assets/custom-fields-inputs.tsx b/app/components/assets/custom-fields-inputs.tsx index 3b5ad0175..359c87189 100644 --- a/app/components/assets/custom-fields-inputs.tsx +++ b/app/components/assets/custom-fields-inputs.tsx @@ -209,40 +209,99 @@ export default function AssetCustomFields({ {customFields.length > 0 ? ( - customFields.map((field, index) => { - const value = customFieldsValues?.find( - (cfv) => cfv.customFieldId === field.id - )?.value; - const displayVal = value - ? (getCustomFieldDisplayValue(value) as string) - : ""; - return ( - {field.helpText}

: undefined} - className="border-b-0" - required={field.required} - > - {typeof fieldTypeToCompMap[field.type] === "function" ? ( - fieldTypeToCompMap[field.type]!(field as unknown as CustomField) - ) : ( - - )} -
- ); - }) + <> +
+

Required Fields

+ {customFields + .filter((field) => field.required) + .map((field, index) => { + const value = customFieldsValues?.find( + (cfv) => cfv.customFieldId === field.id + )?.value; + const displayVal = value + ? (getCustomFieldDisplayValue(value) as string) + : ""; + return ( + {field.helpText}

: undefined + } + className="border-b-0" + required={field.required} + > + {typeof fieldTypeToCompMap[field.type] === "function" ? ( + fieldTypeToCompMap[field.type]!( + field as unknown as CustomField + ) + ) : ( + + )} +
+ ); + })} +
+
+
+

Optional Fields

+ {customFields + .filter((field) => !field.required) + .map((field, index) => { + const value = customFieldsValues?.find( + (cfv) => cfv.customFieldId === field.id + )?.value; + const displayVal = value + ? (getCustomFieldDisplayValue(value) as string) + : ""; + return ( + {field.helpText}

: undefined + } + className="border-b-0" + required={field.required} + > + {typeof fieldTypeToCompMap[field.type] === "function" ? ( + fieldTypeToCompMap[field.type]!( + field as unknown as CustomField + ) + ) : ( + + )} +
+ ); + })} +
+ ) : (