Kaynağa Gözat

near object/relation edit

Ivan Asmer 4 yıl önce
ebeveyn
işleme
37d0bcf896
1 değiştirilmiş dosya ile 2 ekleme ve 48 silme
  1. 2 48
      src/App.js

+ 2 - 48
src/App.js

@@ -9,20 +9,6 @@ import createModels2 from './front-models'
 let gql = new GraphQLClient("/graphql", {headers: localStorage.authToken ? {Authorization: 'Bearer '+localStorage.authToken} : {}})
 
 
-//TODO: use graphql-tag to get types, or, at least detect query 
-//for proper binding between model objects and result of gql query
-
-
-
-const dataReader = async () => {
-    const { PriceItem } = await createModels2(gql)
-    let data            = await PriceItem.find({}, {limit: [10]})
-    return {data, PriceItem }
-}
-
-const Th = p =>
-<div className='Th' {...p} />
-
 
 const EditFormRow = ({field, models={}, value, options=defaultAdminOptions, record, onChange}) => {
     return (
@@ -67,7 +53,6 @@ const EditForm = ({record, models={}, options=defaultAdminOptions, Components:{E
     )
 }
 
-//<div className='Row' style={{position: 'relative',top}}>
 const Row = ({top, selected, children}) => { 
     return (
         <>
@@ -151,14 +136,13 @@ const GridHeader = ({fields, sort, onSort}) =>
 </div>
 
 const getModelByField = (field, models={}) => {
-    if (field.type.kind = 'OBJECT') {
+    if (field.type.kind === 'OBJECT') {
         return models[field.type.name]
     }
-    if (field.type.kind = 'LIST') return models[field.type.ofType.name]
+    if (field.type.kind === 'LIST') return models[field.type.ofType.name]
 }
 
 const VirtualScroll = ({options, gridHeight, count, rowHeight, components:Components={Row, Cell}, onScroll, records, skip, models={}}) => { 
-    //const [records, setRecords] = useState([])
     const limit = gridHeight/rowHeight
     const {Row, Cell} = Components
 
@@ -166,31 +150,14 @@ const VirtualScroll = ({options, gridHeight, count, rowHeight, components:Compon
 
     useEffect(() => setEdit({field: null, record: null}), [records])
 
-    const timeout = useRef(0)
-
     const fields = records && records[0] && records[0].constructor.fields
 
-    const onlyInputs = records && records[0] && records[0].constructor.inputs.filter(input => !fields.find(field => field.name === input.name))
-
-
 
     return (
     <div className='GridViewport' 
-         onScroll={e => {
-             //let skip = Math.ceil(e.target.scrollTop/rowHeight)
-             //if (skip < 0) skip = 0
-             //if (skip > count - limit) skip = count - limit
-
-             //clearInterval(timeout.current)
-             //timeout.current = setTimeout(() => {
-                 //console.log(skip, limit)
-                 //onScroll(skip,limit)
-             //}, 1000)
-         }} 
          style={{maxHeight: gridHeight, height: gridHeight}} >
         <div className='GridContent' 
              style={{height: count*rowHeight, minHeight: count*rowHeight, maxHeight: count*rowHeight}} >
-        { /*      <div style={{height: skip*rowHeight}} /> */ }
             {records && records.map((record,i) =><React.Fragment key={i}> 
                                             {edit.record && edit.record._id === record._id ? <EditForm models={models} record={record} options={options}/>: 
                                             <Row options={options}>
@@ -202,7 +169,6 @@ const VirtualScroll = ({options, gridHeight, count, rowHeight, components:Compon
                                             </Row>}
                 </React.Fragment>
             )}
-        {/*            <div style={{height: (count - skip - records.length)*rowHeight}} /> */ }
         </div>
     </div>
     )
@@ -228,11 +194,6 @@ const ModelView = ({model, models={}, options, components:Components={Search, Co
 
     console.log(cursorCalls)
 
-    //useEffect(() => {
-        //setCursorCalls({sort:cursorCalls.sort, skip: skip ? [skip] : undefined, limit: overloadedRowCount ? [overloadedRowCount] : undefined})
-    //}, [scroll])
-
-
     useEffect(() => {
         model.count(query, cursorCalls).then(count => setCount(count))
         model.find(query, cursorCalls).then(records => Promise.all(records)).then(records => setRecords(records))
@@ -373,17 +334,10 @@ function App() {
     models || createModels2(gql).then(models => setModels(models))
 
     const classes = models
-    console.log(classes)
-    //if (classes && Object.keys(classes).length){
-        //classes.Good.find().then(goods => console.log(goods))
-        //classes.Image.find().then(images => console.log(images))
-    //}
 
     return (
         <div className="App">
             {models && <Admin models={models} />}
-            {/*models && <ModelGrid model={models.Image} rowHeight={50} gridHeight={700} overload={5} query={query} 
-                        cellDoubleClick={(name, text, _id) => setQueryText(`{${name}:\`${text}\`}`)}/> */}
         </div>
     );
 }