-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9334f2
commit bf6ce54
Showing
10 changed files
with
105 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Jest Tests", | ||
"type": "node", | ||
"request": "launch", | ||
"runtimeArgs": [ | ||
"--inspect-brk", | ||
"${workspaceRoot}/node_modules/.bin/jest", | ||
"--runInBand" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"port": 9229 | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,53 @@ | ||
import { ComponentContent, FieldContent } from "../entities/ComponentContent"; | ||
import { | ||
ComponentFieldStructure, | ||
ComponentStructure, | ||
} from "../entities/ComponentStructure"; | ||
import { findComponentById, findComponentStructure } from "../utils/finder"; | ||
|
||
import { BlockContent } from "../entities/BlockContent"; | ||
import { BlockStructure } from "../entities/BlockStructure"; | ||
import { ComponentContent } from "../entities/ComponentContent"; | ||
import { Repeater } from "../entities/Repeater"; | ||
import { buildNewSingleComponentFromStructure } from "../utils/builder"; | ||
|
||
export const addComponent = ( | ||
zoneStore, | ||
blockIndex: number, | ||
componentId: string | ||
blockId: string, | ||
rootId: string, | ||
componentStructureId: string | ||
) => { | ||
console.debug("Coucou"); | ||
const blockStructure: BlockStructure = zoneStore.getBlockStructure( | ||
zoneStore.content[blockIndex].block_id | ||
console.debug("coucou"); | ||
const blockIndex = zoneStore.content.findIndex( | ||
(block: BlockContent) => block.id === blockId | ||
); | ||
const blockContent: BlockContent = zoneStore.content[blockIndex]; | ||
const componentStructure: ComponentStructure = findBlockStructure( | ||
const blockStructure: BlockStructure = zoneStore.getBlockStructure(blockId); | ||
const componentStructure: ComponentStructure = findComponentStructure( | ||
blockStructure, | ||
componentId | ||
componentStructureId | ||
); | ||
console.debug("Structure found : " + componentStructure); | ||
const componentContent: ComponentContent | Repeater<ComponentContent> = | ||
buildNewSingleComponentFromStructure(componentStructure); | ||
const newBlockContent = insertNewComponent( | ||
blockContent, | ||
componentContent, | ||
componentId | ||
rootId | ||
); | ||
zoneStore.content[blockIndex] = newBlockContent; | ||
}; | ||
|
||
const findBlockStructure = ( | ||
structure: BlockStructure | ComponentStructure, | ||
componentId: string | ||
): ComponentStructure => { | ||
return Object.values(structure.fields).find( | ||
(field: ComponentFieldStructure) => { | ||
if (field.type !== "component") return false; | ||
return field.id === componentId; | ||
} | ||
) as ComponentStructure; | ||
return 2; | ||
}; | ||
|
||
const insertNewComponent = ( | ||
content: BlockContent | ComponentContent, | ||
newComponentContent: ComponentContent, | ||
componentId: string | ||
rootId: string | ||
): BlockContent | ComponentContent => { | ||
const repeater = content.fields.find((field) => { | ||
if (field.type !== "repeater") return false; | ||
field.component_id === componentId; | ||
}) as Repeater<ComponentContent>; | ||
repeater.sub_elements.push(newComponentContent); | ||
console.debug(content); | ||
const { node: foundComponent } = findComponentById(content, rootId); | ||
if ((foundComponent as FieldContent).type !== "repeater") | ||
throw new Error("Cannot insert component into non repeater parent"); | ||
(foundComponent as Repeater<ComponentContent>).sub_elements.push( | ||
newComponentContent | ||
); | ||
console.log(content); | ||
return content; | ||
}; |
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