|
@@ -2,6 +2,7 @@ import React, {useState, useEffect, useMemo, useRef} from 'react';
|
|
|
import logo from './logo.svg';
|
|
|
import './App.css';
|
|
|
import Select from 'react-select/async'
|
|
|
+import {sortableContainer, sortableElement} from 'react-sortable-hoc';
|
|
|
|
|
|
import { GraphQLClient } from 'graphql-request';
|
|
|
|
|
@@ -286,6 +287,7 @@ const ForeignAutocomplete = ({models={}, children:value, onChange, model, exclud
|
|
|
}}
|
|
|
value={value && {value: value._id, label: shortName(value), record: value}}
|
|
|
onChange={(obj) => {
|
|
|
+ debugger;
|
|
|
onChange(obj.record._id ? obj.record : null)
|
|
|
}}
|
|
|
/>
|
|
@@ -298,6 +300,21 @@ const ObjectShortEdit = ({...props}) =>
|
|
|
<ForeignAutocomplete {...props}/>
|
|
|
</>
|
|
|
|
|
|
+const SortableCell = sortableElement(({onAdd, onDelete, onCh, ...props}) =>
|
|
|
+<div className='SortableCell'>
|
|
|
+ <button onClick={onAdd}>+</button>
|
|
|
+ <button onClick={onDelete}>x</button>
|
|
|
+ <Cell onChange={onCh} {...props} />
|
|
|
+</div>)
|
|
|
+const SortableContainer = sortableContainer(({children}) => {
|
|
|
+ return <div>{children}</div>;
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+const arrayMove = (arr, newIndex, oldIndex) => {
|
|
|
+ const withoutOld = arr.filter((item, i) => i !== oldIndex)
|
|
|
+ return [...withoutOld.slice(0, newIndex), arr[oldIndex], ...withoutOld.slice(newIndex)]
|
|
|
+}
|
|
|
|
|
|
const defaultAdminOptions =
|
|
|
{
|
|
@@ -327,17 +344,20 @@ const defaultAdminOptions =
|
|
|
return model.fields[0].name === '_id' ? <ObjectShortEdit children={children} model={model} {...props}/> : <EditForm models={models} record={children} options={options} />
|
|
|
},
|
|
|
Array: ({children, onChange, ...props}) => {
|
|
|
- debugger;
|
|
|
- return (<>{children.map((child, i) =>
|
|
|
- <Cell {...props} children={child} selected
|
|
|
- onChange={data => {
|
|
|
+ return (<><SortableContainer onSortEnd={({newIndex, oldIndex}) => {
|
|
|
+ onChange(arrayMove(children, newIndex, oldIndex))
|
|
|
+ }}>{children.map((child, i) =>
|
|
|
+ <SortableCell onDelete={() => onChange(children.filter((item, j) => j !== i))}
|
|
|
+ onAdd={() => onChange([...children.slice(0, i),null,...children.slice(i)])}
|
|
|
+ index={i} key={(child && (child._id || child.key)) || i} {...props} children={child} selected
|
|
|
+ onCh={data => {
|
|
|
const copy = [...children]
|
|
|
debugger;
|
|
|
copy[i] = (data && data.target && data.target.value) || data
|
|
|
onChange(copy)
|
|
|
}}
|
|
|
/>)}
|
|
|
- </>)
|
|
|
+ </SortableContainer><button onClick={() => onChange([...children, null])}>+</button></>)
|
|
|
}
|
|
|
},
|
|
|
fields:{
|