fix: skip recursive remove on grid component (#621)

releated issue: #383
This commit is contained in:
chenos 2022-07-12 20:44:21 +08:00 committed by GitHub
parent 5f9d5436e7
commit 057e1d0039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,9 @@ const GridRowContext = createContext(null);
const GridColContext = createContext(null); const GridColContext = createContext(null);
const GridContext = createContext<any>({}); const GridContext = createContext<any>({});
const breakRemoveOnGrid = (s: Schema) => s['x-component'] === 'Grid';
const breakRemoveOnRow = (s: Schema) => s['x-component'] === 'Grid.Row';
const ColDivider = (props) => { const ColDivider = (props) => {
const { isOver, setNodeRef } = useDroppable({ const { isOver, setNodeRef } = useDroppable({
id: props.id, id: props.id,
@ -154,7 +157,7 @@ export const useGridContext = () => {
export const useGridRowContext = () => { export const useGridRowContext = () => {
return useContext(GridRowContext); return useContext(GridRowContext);
} };
export const Grid: any = observer((props: any) => { export const Grid: any = observer((props: any) => {
const field = useField(); const field = useField();
@ -168,7 +171,12 @@ export const Grid: any = observer((props: any) => {
<DndWrapper dndContext={props.dndContext}> <DndWrapper dndContext={props.dndContext}>
<RowDivider <RowDivider
id={`${addr}_0`} id={`${addr}_0`}
data={{ wrapSchema: wrapRowSchema, insertAdjacent: 'afterBegin', schema: fieldSchema }} data={{
breakRemoveOn: breakRemoveOnGrid,
wrapSchema: wrapRowSchema,
insertAdjacent: 'afterBegin',
schema: fieldSchema,
}}
/> />
{rows.map((schema, index) => { {rows.map((schema, index) => {
return ( return (
@ -176,7 +184,12 @@ export const Grid: any = observer((props: any) => {
<RecursionField name={schema.name} schema={schema} /> <RecursionField name={schema.name} schema={schema} />
<RowDivider <RowDivider
id={`${addr}_${index + 1}`} id={`${addr}_${index + 1}`}
data={{ wrapSchema: wrapRowSchema, insertAdjacent: 'afterEnd', schema }} data={{
breakRemoveOn: breakRemoveOnGrid,
wrapSchema: wrapRowSchema,
insertAdjacent: 'afterEnd',
schema,
}}
/> />
</React.Fragment> </React.Fragment>
); );
@ -208,7 +221,12 @@ Grid.Row = observer((props) => {
> >
<ColDivider <ColDivider
id={`${addr}_0`} id={`${addr}_0`}
data={{ wrapSchema: wrapColSchema, insertAdjacent: 'afterBegin', schema: fieldSchema }} data={{
breakRemoveOn: breakRemoveOnRow,
wrapSchema: wrapColSchema,
insertAdjacent: 'afterBegin',
schema: fieldSchema,
}}
/> />
{cols.map((schema, index) => { {cols.map((schema, index) => {
return ( return (
@ -216,7 +234,12 @@ Grid.Row = observer((props) => {
<RecursionField name={schema.name} schema={schema} /> <RecursionField name={schema.name} schema={schema} />
<ColDivider <ColDivider
id={`${addr}_${index + 1}`} id={`${addr}_${index + 1}`}
data={{ wrapSchema: wrapColSchema, insertAdjacent: 'afterEnd', schema }} data={{
breakRemoveOn: breakRemoveOnRow,
wrapSchema: wrapColSchema,
insertAdjacent: 'afterEnd',
schema,
}}
/> />
</React.Fragment> </React.Fragment>
); );