From bd4ce200852b405db448811ed38055108491b348 Mon Sep 17 00:00:00 2001 From: lassopicasso Date: Mon, 25 Mar 2024 15:44:29 +0100 Subject: [PATCH 1/4] Add selectedTypePointer as parentId if schema tree is for a type --- .../components/SchemaEditor/SchemaEditor.tsx | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx index e9a6480ccc6..a946143a9ec 100644 --- a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx +++ b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import classes from './SchemaEditor.module.css'; import { TypesInspector } from '../TypesInspector'; import { SchemaInspector } from '../SchemaInspector'; @@ -11,27 +11,10 @@ import { useAddReference } from './hooks/useAddReference'; import { NodePanel } from '../NodePanel'; export const SchemaEditor = () => { - const { schemaModel, selectedTypePointer, selectedNodePointer } = useSchemaEditorAppContext(); + const { schemaModel, selectedTypePointer } = useSchemaEditorAppContext(); const moveProperty = useMoveProperty(); const addReference = useAddReference(); - - const [expandedPropNodes, setExpandedPropNodes] = useState([]); - const [expandedDefNodes, setExpandedDefNodes] = useState([]); - - const selectedPropertyParent = schemaModel.getParentNode(selectedNodePointer); - - useEffect(() => { - if (selectedPropertyParent && !expandedPropNodes.includes(selectedPropertyParent.pointer)) { - setExpandedPropNodes((prevState) => [...prevState, selectedPropertyParent.pointer]); - } - }, [selectedPropertyParent, expandedPropNodes]); - - const selectedDefinitionParent = schemaModel.getParentNode(selectedTypePointer); - useEffect(() => { - if (selectedDefinitionParent && !expandedDefNodes.includes(selectedDefinitionParent.pointer)) { - setExpandedDefNodes((prevState) => [...prevState, selectedDefinitionParent.pointer]); - } - }, [selectedPropertyParent, expandedDefNodes, selectedDefinitionParent]); + console.log(moveProperty); if (schemaModel.isEmpty()) return null; const definitions: UiSchemaNodes = schemaModel.getDefinitions(); @@ -39,7 +22,18 @@ export const SchemaEditor = () => { return ( <> - + + // The listItemContext is not updated at the correct time, and useParentId is not working as expected in cases when drag and drop in schema tree for types + // Following issue may fix this: https://github.com/Altinn/altinn-studio/issues/11824 + moveProperty(pointer, { + index: position.index, + parentId: selectedTypePointer || position.parentId, + }) + } + rootId={ROOT_POINTER} + > From e1ef66a529638c9fdd53b9d10b13fadbcaaa8456 Mon Sep 17 00:00:00 2001 From: lassopicasso Date: Mon, 25 Mar 2024 16:10:23 +0100 Subject: [PATCH 2/4] remove console.log and rewrite comment --- .../src/components/SchemaEditor/SchemaEditor.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx index a946143a9ec..76ef80d3bb0 100644 --- a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx +++ b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx @@ -14,7 +14,6 @@ export const SchemaEditor = () => { const { schemaModel, selectedTypePointer } = useSchemaEditorAppContext(); const moveProperty = useMoveProperty(); const addReference = useAddReference(); - console.log(moveProperty); if (schemaModel.isEmpty()) return null; const definitions: UiSchemaNodes = schemaModel.getDefinitions(); @@ -25,8 +24,8 @@ export const SchemaEditor = () => { - // The listItemContext is not updated at the correct time, and useParentId is not working as expected in cases when drag and drop in schema tree for types - // Following issue may fix this: https://github.com/Altinn/altinn-studio/issues/11824 + // listItemContext update timing may affect useParentId functionality. For now, use selectedTypePointer as parentId if set, else use parentId from position object + // Refactor may provide a better solution: https://github.com/Altinn/altinn-studio/issues/11824 moveProperty(pointer, { index: position.index, parentId: selectedTypePointer || position.parentId, From a10b0bd65a70ac991be203eb720b1573684dc127 Mon Sep 17 00:00:00 2001 From: lassopicasso Date: Tue, 26 Mar 2024 10:10:44 +0100 Subject: [PATCH 3/4] add `DragAndDropListItemContext` to DragAndDropProvider --- .../src/components/SchemaEditor/SchemaEditor.tsx | 10 ++-------- .../DragAndDropProvider/DragAndDropProvider.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx index 76ef80d3bb0..42cf9b157da 100644 --- a/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx +++ b/frontend/packages/schema-editor/src/components/SchemaEditor/SchemaEditor.tsx @@ -23,15 +23,9 @@ export const SchemaEditor = () => { <> - // listItemContext update timing may affect useParentId functionality. For now, use selectedTypePointer as parentId if set, else use parentId from position object - // Refactor may provide a better solution: https://github.com/Altinn/altinn-studio/issues/11824 - moveProperty(pointer, { - index: position.index, - parentId: selectedTypePointer || position.parentId, - }) - } + onMove={moveProperty} rootId={ROOT_POINTER} + itemId={selectedTypePointer ?? null} >