Răsfoiți Sursa

support dynamic schema

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 11 luni în urmă
părinte
comite
ea47f8a850
1 a modificat fișierele cu 8 adăugiri și 1 ștergeri
  1. 8 1
      client/src/pages/dialogs/EditEntityDialog.tsx

+ 8 - 1
client/src/pages/dialogs/EditEntityDialog.tsx

@@ -12,6 +12,7 @@ import { rootContext } from '@/context';
 import DialogTemplate from '@/components/customDialog/DialogTemplate';
 import { CollectionFullObject } from '@server/types';
 import { DataService } from '@/http';
+import { DYNAMIC_FIELD } from '@/consts';
 
 const useStyles = makeStyles((theme: Theme) => ({
   code: {
@@ -54,13 +55,19 @@ const EditEntityDialog: FC<EditEntityDialogProps> = props => {
 
   // sort data by collection schema order
   const schema = collection.schema;
-  const sortedData: { [key: string]: any } = {};
+  let sortedData: { [key: string]: any } = {};
   schema.fields.forEach(field => {
     if (data[field.name] !== undefined) {
       sortedData[field.name] = data[field.name];
     }
   });
 
+  // add dynamic fields if exist
+  const isDynamicSchema = collection.schema.dynamicFields.length > 0;
+  if (isDynamicSchema) {
+    sortedData = { ...sortedData, ...data[DYNAMIC_FIELD] };
+  }
+
   const originalData = JSON.stringify(sortedData, null, 4);
 
   // create editor