Skip to content

Commit

Permalink
Add Ancillary feature (#204)
Browse files Browse the repository at this point in the history
* Add tocs event handler for drag and drop

Should also handle rename/remove/etc

* Update vscode types to latest version

* Always set dragging to undefined after a drop

* Add orphans to tree view and try to fix coverage

The orphans appear outside of all books, at the bottom of the tree view

* Use contextValue to conditionally add buttons to tree items

Might be better to use `capabilities`, an array of words like 'delete', 'rename', etc., to support conditions

Example: we may not want to allow removing an orphaned subbook/page

* Use capabilities instead of ToCNodeKind for tree condition

* Use data transfer items instead of class field for dragged item

* Update tests; add some polish

* Find parent book recursively instead of iteratively

Mostly to address a problem with the tsconfig file, but it's probably better this way anyway

* Remove seemingly unnecessary istanbul ignores

* When moving node to different book, update both collection files

I was stuck on this for a bit. Initially I tried
to write the srcBookToc immediately after removing the node on
model-manager.ts:594. The tests kept failing because the page was being
orphaned instead of appearing in the second book.

I realized that the sideEffectFn was running which
overwrote `this.bookTocs` with a new array. This meant that the splice
(model-manager.ts:597) was modifying a different list of children because the
reference returned by `lookupToken` was not the same as the one stored in
`bookToc`.

I moved my write operation to the end and added a warning. Hopefully the
warning will save someone else from this confusion in the future.

* Fix typo in comment

* Add Ancillary functionality to TOC Tree

* Fixed test cases

* Added `book-tocs` snapshot to commit.

* Code lint

* Fixed the code coverage.

* Fixed bug when the no node was selected

* Move leaf nodes into Book and Subbook drop targets

Before: Move leaf node above or below Book/Subbook drop target

After: Insert leaf node at the top of the Book/Subbook child list (index 0)

* Properly handle ouroboros case for subbooks

* Added possibility to create nodes in selected books and subbooks

* Updated the tests.

---------

Co-authored-by: Tyler Nullmeier <tylerzeromaster@gmail.com>
  • Loading branch information
sparksam and TylerZeroMaster authored Aug 5, 2024
1 parent 80b43d0 commit 30dcb65
Show file tree
Hide file tree
Showing 20 changed files with 989 additions and 66 deletions.
14 changes: 7 additions & 7 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/node": "^17.0.16",
"@types/react-sortable-tree": "^0.3.15",
"@types/uuid": "^8.3.4",
"@types/vscode": "^1.64.0",
"@types/vscode": "^1.89.0",
"@types/xmldom": "^0.1.31",
"json-stable-stringify": "^1.0.1",
"preact": "^10.6.5",
Expand Down
6 changes: 6 additions & 0 deletions client/specs/__mocks__/vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class CodeLens {}
class DocumentLink {}
class CodeAction {}
class CallHierarchyItem {}
class DataTransferItem {
constructor(value) { this.value = value }
}
class DataTransfer {}

class ThemeIcon {
static File = 'File'
Expand Down Expand Up @@ -222,6 +226,8 @@ const vscode = {
ProgressLocation,
FileSystemError,
TextEditorRevealType,
DataTransferItem,
DataTransfer
};

module.exports = { ...vscode, default: vscode };
14 changes: 14 additions & 0 deletions client/specs/__snapshots__/book-tocs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`Toc Provider filters fileids when filtering is set 1`] = `
"command": "vscode.open",
"title": "open",
},
"contextValue": "rename,delete",
"description": "fileId",
"iconPath": "File",
"label": "title",
Expand All @@ -39,6 +40,7 @@ exports[`Toc Provider filters fileids when filtering is set 2`] = `
"command": "vscode.open",
"title": "open",
},
"contextValue": "rename,delete",
"iconPath": "File",
"label": "title (fileId)",
"resourceUri": {
Expand All @@ -63,6 +65,7 @@ exports[`Toc Provider filters fileids when filtering is set 3`] = `
"command": "vscode.open",
"title": "open",
},
"contextValue": "rename,delete",
"description": "fileId",
"iconPath": "File",
"label": "title",
Expand Down Expand Up @@ -102,6 +105,7 @@ exports[`Toc Provider returns tree items for children 1`] = `
exports[`Toc Provider returns tree items for children 2`] = `
{
"collapsibleState": "Collapsed",
"contextValue": "rename",
"iconPath": "Folder",
"label": "title",
}
Expand All @@ -121,6 +125,7 @@ exports[`Toc Provider returns tree items for children 3`] = `
"command": "vscode.open",
"title": "open",
},
"contextValue": "rename",
"description": "fileId",
"iconPath": "File",
"label": "title",
Expand All @@ -131,3 +136,12 @@ exports[`Toc Provider returns tree items for children 3`] = `
},
}
`;

exports[`Toc Provider returns tree items for children 4`] = `
{
"collapsibleState": "Collapsed",
"contextValue": "rename",
"iconPath": "Folder",
"label": "title",
}
`;
18 changes: 15 additions & 3 deletions client/specs/book-tocs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ const testTocPage: ClientTocNode = {
fileId: 'fileId'
}
}
const testTocAncillary: ClientTocNode = {
type: TocNodeKind.Ancillary,
value: {
absPath: '/path/to/ancillary',
token: 'token',
title: 'title',
fileId: 'fileId'
}
}
const testTocSubbook: ClientTocNode = {
type: TocNodeKind.Subbook,
value: { token: 'token', title: 'title' },
children: [testTocPage]
children: [testTocPage, testTocAncillary]
}
const testToc: BookToc = {
type: BookRootNode.Singleton,
Expand All @@ -27,15 +36,17 @@ const testToc: BookToc = {
licenseUrl: 'licenseUrl',
tocTree: [testTocSubbook]
}

describe('Toc Provider', () => {
const p = new TocsTreeProvider()
it('returns tree items for children', () => {
expect(p.getTreeItem(testToc)).toMatchSnapshot()
expect(p.getTreeItem(testTocSubbook)).toMatchSnapshot()
expect(p.getTreeItem(testTocPage)).toMatchSnapshot()
expect(p.getTreeItem(testTocAncillary)).toMatchSnapshot()
})
it('filters fileids when filtering is set', () => {
const p = new TocsTreeProvider()
p.update([testToc], [])
expect(p.getTreeItem(testTocPage)).toMatchSnapshot()
p.toggleFilterMode()
expect(p.getTreeItem(testTocPage)).toMatchSnapshot()
Expand All @@ -50,10 +61,11 @@ describe('Toc Provider', () => {
expect(p.getTreeItem(nonloadedPage).label).toBe(`Loading... (${nonloadedPage.value.fileId})`)
})
it('gets children and parents', () => {
p.update([testToc])
p.update([testToc], [])
expect(p.getChildren()).toEqual([testToc])
expect(p.getParent(testToc)).toBe(undefined)
expect(p.getChildren(testToc)).toEqual(testToc.tocTree)
expect(p.getParent(testToc.tocTree[0])).toBe(testToc)
expect(p.getParentBook(testToc)).toBe(undefined)
})
})
4 changes: 2 additions & 2 deletions client/specs/panel-toc-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ describe('Toc Editor', () => {
expect(getMessage().type).toBe(TocModificationKind.SubbookRename)

sinon.stub(vscode.window, 'showInputBox').returns(Promise.resolve('new_title'))
await p.handleMessage({ type: TocNodeKind.Page, title: 'foo', bookIndex: 0 })
await p.handleMessage({ type: TocNodeKind.Page, title: 'foo', bookIndex: 0, parentNodeToken: undefined })
expect(getMessage().title).toBe('new_title')

await p.handleMessage({ type: TocNodeKind.Subbook, title: 'foo', bookIndex: 0, slug: 'subbook_slug' })
await p.handleMessage({ type: TocNodeKind.Subbook, title: 'foo', bookIndex: 0, slug: 'subbook_slug', parentNodeToken: undefined })
expect(getMessage().title).toBe('new_title')
})
it('disposes', () => {
Expand Down
Loading

0 comments on commit 30dcb65

Please sign in to comment.