-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix error that occurs when dragging a type into an object (#13762)
- Loading branch information
Showing
13 changed files
with
125 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
frontend/packages/schema-editor/src/components/SchemaEditor/hooks/useAddReference.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import type { HandleAdd, ItemPosition } from 'app-shared/types/dndTypes'; | ||
import { useCallback } from 'react'; | ||
import type { NodePosition } from '@altinn/schema-model'; | ||
import { SchemaModel } from '@altinn/schema-model'; | ||
import { calculatePositionInFullList } from '../utils'; | ||
import { useSavableSchemaModel } from '../../../hooks/useSavableSchemaModel'; | ||
import { useSchemaEditorAppContext } from '@altinn/schema-editor/hooks/useSchemaEditorAppContext'; | ||
|
||
export const useAddReference = (): HandleAdd<string> => { | ||
const { setSelectedUniquePointer, schemaModel } = useSchemaEditorAppContext(); | ||
const { setSelectedUniquePointer } = useSchemaEditorAppContext(); | ||
const savableModel = useSavableSchemaModel(); | ||
return useCallback( | ||
(reference: string, position: ItemPosition) => { | ||
const index = calculatePositionInFullList(savableModel, position); | ||
const target: NodePosition = { parentPointer: position.parentId, index }; | ||
const schemaPointer = savableModel.getFinalNode(target.parentPointer).schemaPointer; | ||
const parentPointer = savableModel.getSchemaPointerByUniquePointer(position.parentId); | ||
const target: NodePosition = { parentPointer, index }; | ||
const { schemaPointer } = savableModel.getFinalNode(target.parentPointer); | ||
const refName = savableModel.generateUniqueChildName(schemaPointer, 'ref'); | ||
const ref = savableModel.addReference(refName, reference, target); | ||
const uniquePointer = schemaModel.getUniquePointer(ref.schemaPointer); | ||
const uniquePointer = SchemaModel.getUniquePointer(ref.schemaPointer); | ||
setSelectedUniquePointer(uniquePointer); | ||
}, | ||
[savableModel, setSelectedUniquePointer, schemaModel], | ||
[savableModel, setSelectedUniquePointer], | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.