Преглед на файлове

basic edit of arrays. TODO: dnd, add, remove and fix nested object arrays save(not relations)

Ivan Asmer преди 4 години
родител
ревизия
5826b3e712
променени са 1 файла, в които са добавени 18 реда и са изтрити 5 реда
  1. 18 5
      src/App.js

+ 18 - 5
src/App.js

@@ -76,8 +76,9 @@ const Cell = ({children, options, record, field, selected, model, models={}, onC
     let Formatter = React.Fragment
 
     const viewOrEdit = (!record.constructor.inputs || record.constructor.inputs.some(input => input.name === field.name)) && selected ? 'edit' : 'view'
-    if (field.type.name in options[viewOrEdit].formatters){
-        Formatter = options[viewOrEdit].formatters[field.type.name]
+    const typeName   = field.type.name || field.type.ofType.name
+    if (typeName in options[viewOrEdit].formatters){
+        Formatter = options[viewOrEdit].formatters[typeName]
     }
     if (field.name in options[viewOrEdit].fields){
         Formatter = options[viewOrEdit].fields[field.name]
@@ -93,7 +94,7 @@ const Cell = ({children, options, record, field, selected, model, models={}, onC
 
     return( 
         <div className='Cell' onClick={onClick}>
-            <Formatter options={options} model={model} models={models} {...props} field={field}>
+            <Formatter record={record} options={options} model={model} models={models} {...props} field={field}>
                   {Formatter === React.Fragment ? (children && children.toString()) : children}
             </Formatter>
         </div>
@@ -239,7 +240,7 @@ const ModelView = ({model, models={}, options, components:Components={Search, Co
                                 skip={skip}
                                 count={count}
                                 records={records}
-                                gridHeight={500} 
+                                gridHeight={700} 
                                 rowHeight={50} 
                                 onScroll={(skip, limit) =>  {
                                     limit = undefined;
@@ -325,7 +326,19 @@ const defaultAdminOptions =
                 Object: ({children, options, model, models, ...props}) => {
                     return model.fields[0].name === '_id' ? <ObjectShortEdit children={children}  model={model} {...props}/> : <EditForm models={models} record={children} options={options} />
                 },
-                Array: ({children}) => <>{children.map(child => <ObjectShortView children={child} />)}</>
+                Array: ({children, onChange, ...props}) => {
+                    debugger;
+                    return (<>{children.map((child, i) => 
+                        <Cell {...props} children={child} selected 
+                                onChange={data => {
+                                                        const copy = [...children]
+                                                        debugger;
+                                                        copy[i] = (data && data.target && data.target.value) || data
+                                                        onChange(copy)
+                                }}
+                            />)}
+                        </>)
+                }
             },
             fields:{
                 createdAt: ({children}) => <input value={new Date(+children).toISOString()} />,