Skip to content

Commit

Permalink
Remove ClientOnlyTocKind enum
Browse files Browse the repository at this point in the history
Use OrphanCollectionKind instead
  • Loading branch information
TylerZeroMaster committed Jan 15, 2025
1 parent 79512bb commit b7b2e2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/specs/__snapshots__/book-tocs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ exports[`filtering toggleTocTreesFilteringHandler 1`] = `
[
{
"children": [],
"type": "ClientOnlyTocKinds.OrphanCollection",
"type": "OrphanCollection",
"value": undefined,
},
{
Expand Down
10 changes: 5 additions & 5 deletions client/specs/book-tocs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type vscode from 'vscode'
import { expect } from '@jest/globals'

import { BookRootNode, type BookToc, type ClientTocNode, TocNodeKind } from '../../common/src/toc'
import { type BookOrTocNode, ClientOnlyTocKinds, TocsTreeProvider, toggleTocTreesFilteringHandler } from '../src/book-tocs'
import { type BookOrTocNode, type OrphanCollection, OrphanCollectionKind, TocsTreeProvider, toggleTocTreesFilteringHandler } from '../src/book-tocs'

const testTocPage: ClientTocNode = {
type: TocNodeKind.Page,
Expand Down Expand Up @@ -38,8 +38,8 @@ const testToc: BookToc = {
licenseUrl: 'licenseUrl',
tocTree: [testTocSubbook]
}
const testOrphanCollection = {
type: ClientOnlyTocKinds.OrphanCollection,
const testOrphanCollection: OrphanCollection = {
type: OrphanCollectionKind,
children: []
}
describe('Toc Provider', () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('Toc Provider', () => {
})
it('gets children and parents', () => {
p.update([testToc], [])
expect(p.getChildren()).toEqual([testToc, { children: [], type: ClientOnlyTocKinds.OrphanCollection, value: undefined }])
expect(p.getChildren()).toEqual([testToc, { children: [], type: OrphanCollectionKind, value: undefined }])
expect(p.getParent(testToc)).toBe(undefined)
expect(p.getChildren(testToc)).toEqual(testToc.tocTree)
expect(p.getParent(testToc.tocTree[0])).toBe(testToc)
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('filtering', () => {
const fakeChildren = [
{ type: BookRootNode.Singleton, tocTree: [{ type: TocNodeKind.Subbook, label: 'unit1', children: [{ type: TocNodeKind.Subbook, label: 'subcol1', children: [{ type: TocNodeKind.Page, label: 'm2', children: [] }] }] }] },
{ type: BookRootNode.Singleton, tocTree: [{ label: 'm1', children: [] }] },
{ type: ClientOnlyTocKinds.OrphanCollection, children: [], value: undefined }
{ type: OrphanCollectionKind, children: [], value: undefined }
]
getChildrenStub.returns(fakeChildren)

Expand Down
14 changes: 6 additions & 8 deletions client/src/book-tocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { EventEmitter, type TreeItem, TreeItemCollapsibleState, Uri, type TreeDa
import { type BookToc, type ClientTocNode, BookRootNode, TocNodeKind, type ClientPageish } from '../../common/src/toc'
import type vscode from 'vscode'

export enum ClientOnlyTocKinds {
OrphanCollection = 'ClientOnlyTocKinds.OrphanCollection'
}
export const OrphanCollectionKind = 'OrphanCollection'

interface OrphanCollection {
type: ClientOnlyTocKinds.OrphanCollection
children: BookOrTocNode[]
export interface OrphanCollection {
type: typeof OrphanCollectionKind
children: Array<BookToc | ClientTocNode>
}
export type BookOrTocNode = BookToc | ClientTocNode | OrphanCollection

Expand All @@ -32,7 +30,7 @@ export class TocsTreeProvider implements TreeDataProvider<BookOrTocNode> {

constructor() {
this.bookTocs = []
this.orphanCollection = { type: ClientOnlyTocKinds.OrphanCollection, children: [] }
this.orphanCollection = { type: OrphanCollectionKind, children: [] }
}

public toggleFilterMode() {
Expand Down Expand Up @@ -96,7 +94,7 @@ export class TocsTreeProvider implements TreeDataProvider<BookOrTocNode> {
label: node.value.title,
contextValue: capabilities.join(',')
}
case ClientOnlyTocKinds.OrphanCollection:
case OrphanCollectionKind:
return {
iconPath: TocItemIcon.Subbook,
collapsibleState: TreeItemCollapsibleState.Collapsed,
Expand Down
6 changes: 3 additions & 3 deletions client/src/tocs-event-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vscode from 'vscode'
import { type TocsTreeProvider, type BookOrTocNode, ClientOnlyTocKinds } from './book-tocs'
import { type TocsTreeProvider, type BookOrTocNode, OrphanCollectionKind } from './book-tocs'
import { type TocModification, TocModificationKind, type TocModificationParams, TocNodeKind, BookRootNode, type CreatePageEvent, type CreateSubbookEvent, type CreateAncillaryEvent, isClientTocNode } from '../../common/src/toc'
import { ExtensionServerRequest } from '../../common/src/requests'
import { expect, getRootPathUri } from './utils'
Expand Down Expand Up @@ -212,10 +212,10 @@ export class TocsEventHandler implements vscode.TreeDragAndDropController<BookOr
if (target === undefined) { throw new Error('BUG: Bad drop target') }
if (
target !== dragging &&
dragging.type !== ClientOnlyTocKinds.OrphanCollection &&
dragging.type !== OrphanCollectionKind &&
dragging.type !== BookRootNode.Singleton
) {
if (target.type === ClientOnlyTocKinds.OrphanCollection) {
if (target.type === OrphanCollectionKind) {
await this.removeNode(dragging)
} else {
await this.moveNode(dragging, target)
Expand Down

0 comments on commit b7b2e2f

Please sign in to comment.