Implement block conversion — export side and convert API#148
Conversation
|
⏭️ No files to mutate for |
|
⏭️ No files to mutate for |
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 99.71% | 1044/1047 |
| 🟢 | Branches | 98.44% | 315/320 |
| 🟢 | Functions | 98.39% | 244/248 |
| 🟢 | Lines | 99.7% | 1002/1005 |
Test suite run success
563 tests passing in 26 suites.
Report generated by 🧪jest coverage report action from 161783c
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 96.43% | 27/28 |
| 🟢 | Branches | 86.96% | 20/23 |
| 🟢 | Functions | 100% | 5/5 |
| 🟢 | Lines | 96.43% | 27/28 |
Test suite run success
11 tests passing in 2 suites.
Report generated by 🧪jest coverage report action from 161783c
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 93.65% (-1.6% 🔻) |
295/315 |
| 🟢 | Branches | 89.34% (-0.85% 🔻) |
109/122 |
| 🟡 | Functions | 75% (-5.43% 🔻) |
48/64 |
| 🟢 | Lines | 93.29% (-1.69% 🔻) |
278/298 |
Show new covered files 🐣
St.❔ |
File | Statements | Branches | Functions | Lines |
|---|---|---|---|---|---|
| 🟡 | api/BlocksAPI.ts | 68.18% | 71.43% | 56.25% | 66.67% |
Test suite run success
149 tests passing in 8 suites.
Report generated by 🧪jest coverage report action from 161783c
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟢 | Statements | 91.88% | 396/431 |
| 🟢 | Branches | 85.82% | 121/141 |
| 🟢 | Functions | 88.16% | 67/76 |
| 🟢 | Lines | 91.71% | 387/422 |
Test suite run success
130 tests passing in 7 suites.
Report generated by 🧪jest coverage report action from 161783c
|
⏭️ No files to mutate for |
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟡 | Statements | 70.97% | 22/31 |
| 🔴 | Branches | 20% | 1/5 |
| 🔴 | Functions | 50% | 6/12 |
| 🟡 | Lines | 68.97% | 20/29 |
Test suite run success
4 tests passing in 1 suite.
Report generated by 🧪jest coverage report action from 161783c
fc906c1 to
630d328
Compare
| id: string, | ||
| newType: string, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| dataOverrides?: BlockToolData |
There was a problem hiding this comment.
Better to leave a to-do if you're not going to implement it in this PR
There was a problem hiding this comment.
Now we're using this parameters to override data.
| * @param dataOverrides - optional data overrides for the new block @todo implement | ||
| */ | ||
| public convert( | ||
| id: string, |
There was a problem hiding this comment.
Please use id or index
Also, it would be more scalable to use a single object with parameters and add an optional useId property (see my PR that adds user ID to API methods)
There was a problem hiding this comment.
Please use id or index
Done, now we accepting both
Also, it would be more scalable to use a single object with parameters and add an optional useId property (see my PR that adds user ID to API methods)
Good advise, done.
b21e9e7 to
7901a5e
Compare
fcb9202 to
7353118
Compare
| })); | ||
| }); | ||
|
|
||
| it('exports text from source, imports into target, and replaces block at the same index', () => { |
There was a problem hiding this comment.
it is a good practice to name a test case starting with "should ...", so the full test will be in a declarative way ("it should ...")
| it('exports text from source, imports into target, and replaces block at the same index', () => { | |
| it('should export text from source, imports into target, and replaces block at the same index', () => { |
| const targetTool = { importTextContent: jest.fn(() => ({ text: { value: 'Hello', | ||
| fragments: [] } })) }; |
There was a problem hiding this comment.
bad line breaks, please format objects in a way where each object property stays on the separate line:
{
text: {
value: 'Hello',
fragments: []
}
}| { name: 'paragraph', | ||
| data: { text: { value: 'Hello', | ||
| fragments: [] } } }, |
There was a problem hiding this comment.
Pull request overview
Adds the export side of the block conversion pipeline and a public convert API. BlockToolFacade.exportTextContent() serializes block data to plain text via conversionConfig.export (function or keypath), and BlocksManager.convertBlock() uses it together with the previously added importTextContent() to replace a block in place with a new tool type.
Changes:
- Add
exportTextContent()toBlockToolFacadesupporting function and keypath export configs. - Add
convertBlock()toBlocksManager(remove + re-add at same index, optionaldataOverrides/userId). - Expose it via
BlocksAPI.convert({ block, newType, dataOverrides?, userId? })and update the interface signature.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/sdk/src/tools/facades/BlockToolFacade.ts | Implements exportTextContent() using conversionConfig.export. |
| packages/sdk/src/tools/facades/BaseToolFacade.spec.ts | Unit tests for the three export variants (missing/function/keypath). |
| packages/sdk/src/api/BlocksAPI.ts | Replaces commented convert signature with object-param public API. |
| packages/core/src/components/BlockManager.ts | Implements convertBlock() (export → import → replace). |
| packages/core/src/components/BlockManager.spec.ts | Tests for happy path, overrides, and missing export/import configs. |
| packages/core/src/api/BlocksAPI.ts | Wires convert() to BlocksManager.convertBlock(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const text = sourceTool.exportTextContent(block.data); | ||
| const newData = targetTool.importTextContent(text, []); |
| const sourceTool = this.#toolsManager.blockTools.get(block.name)!; | ||
| const targetTool = this.#toolsManager.blockTools.get(newType)!; |
| const finalData = dataOverrides !== undefined | ||
| ? { ...newData, | ||
| ...dataOverrides } | ||
| : newData; |
There was a problem hiding this comment.
Added doc for all parameter entry along all convertBlock() pipeline.
Add exportTextContent() to BlockToolFacade: supports function, string keypath, and dot-notation keypath via conversionConfig.export. Add convertBlock() to BlocksManager: exports text from the source block, imports it into the target type, and replaces the block at the same index.
7353118 to
161783c
Compare
Summary
exportTextContent()toBlockToolFacade. Supports a function, a string keypath, or a dot-notation keypath viaconversionConfig.export.convertBlock()toBlocksManager: exports text from the source block using its conversion config, imports it into the target tool type, and replaces the block at the same index.