fix(frontend): Fix duplication (#1237)

This commit is contained in:
Faton Ramadani
2023-02-25 10:18:21 +01:00
committed by GitHub
parent e1f686d850
commit e87f4fc44b
2 changed files with 7 additions and 4 deletions
@@ -107,8 +107,6 @@ export function insertNewGridItem(
const subGrid = app.subgrids[key] ?? []
subGrid.push(createNewGridItem(subGrid, id, data))
app.subgrids[key] = subGrid
}
for (let i = 0; i < (data.numberOfSubgrids ?? 0); i++) {
app.subgrids[`${id}-${i}`] = []
@@ -169,16 +167,21 @@ export function deleteGridItem(
export function duplicateGridItem(
app: App,
focusedGrid: FocusedGrid | undefined,
parent: string | undefined,
id: string
): string | undefined {
const gridItem = findGridItem(app, id)
if (gridItem) {
const newId = getNextGridItemId(app)
const newItem = JSON.parse(JSON.stringify(gridItem))
newItem.id = newId
newItem.data.id = newId
let focusedGrid = parent
? { parentComponentId: parent.split('-')[0], subGridIndex: Number(parent.split('-')[1]) }
: undefined
return insertNewGridItem(app, newItem.data, focusedGrid)
}
return undefined
@@ -35,7 +35,7 @@
function duplicateElement(id: string) {
$dirtyStore = true
const newId = duplicateGridItem($app, $focusedGrid, id)
const newId = duplicateGridItem($app, parent, id)
$selectedComponent = newId
}