Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/blank note explorer view (#493)
* Create Blank Note Explorer View Creates a new "Blank Note" explorer view which displays all notes that contain only a title. When note.source.text.trim().split('\n').length is equal to 1, a note is considered blank. This should mean that the note contains only a title. The UX experience is identical to that of the Orphan view. A user can toggle between both the flat view and a nested view grouped by directory. * Cleaned up views and made them much more dynamic. Instead of just copy and pasting the orphans view into blank notes, I created a filtered notes provider, which behaves identically to the old orphan/blank notes providers, but allows the caller to pass in the "filter function" which will narrow down the list of notes in the view. This also allows us to more easily unit test the filtering logic, and only test the flatten / nested logic in one place. It also makes it so that when we refactor the way one of these views works (e.g. adding the markdown preview), we don't have to make changes to the other view. * Fixed unit test that was failing in Windows. * Combined placeholders and blank notes. * Removed workspacesFsPaths and replaced with workspacesURIs Co-authored-by: J.T. James <joel.james@myfuelmaster.com>
- Loading branch information
1 parent
596d96e
commit f48c74c
Showing
13 changed files
with
828 additions
and
288 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
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,110 +1,32 @@ | ||
import { OrphansProvider, Directory, OrphansProviderConfig } from './orphans'; | ||
import { OrphansConfigGroupBy } from '../settings'; | ||
import { FoamWorkspace } from 'foam-core'; | ||
import { createTestNote } from '../test/test-utils'; | ||
import { isOrphan } from './orphans'; | ||
|
||
describe('orphans', () => { | ||
const orphanA = createTestNote({ | ||
uri: '/path/orphan-a.md', | ||
title: 'Orphan A', | ||
}); | ||
const orphanB = createTestNote({ | ||
uri: '/path-bis/orphan-b.md', | ||
title: 'Orphan B', | ||
}); | ||
const orphanC = createTestNote({ | ||
uri: '/path-exclude/orphan-c.md', | ||
title: 'Orphan C', | ||
}); | ||
|
||
const workspace = new FoamWorkspace() | ||
.set(orphanA) | ||
.set(orphanB) | ||
.set(orphanC) | ||
.set(createTestNote({ uri: '/path/non-orphan-1.md' })) | ||
.set( | ||
createTestNote({ | ||
uri: '/path/non-orphan-2.md', | ||
links: [{ slug: 'non-orphan-1' }], | ||
}) | ||
) | ||
.resolveLinks(); | ||
|
||
const dataStore = { read: () => '' } as any; | ||
const orphanA = createTestNote({ | ||
uri: '/path/orphan-a.md', | ||
title: 'Orphan A', | ||
}); | ||
|
||
// Mock config | ||
const config: OrphansProviderConfig = { | ||
exclude: ['path-exclude/**/*'], | ||
groupBy: OrphansConfigGroupBy.Folder, | ||
workspacesFsPaths: [''], | ||
}; | ||
const nonOrphan1 = createTestNote({ | ||
uri: '/path/non-orphan-1.md', | ||
}); | ||
|
||
it('should return the orphans as a folder tree', async () => { | ||
const provider = new OrphansProvider(workspace, dataStore, config); | ||
const result = await provider.getChildren(); | ||
expect(result).toMatchObject([ | ||
{ | ||
collapsibleState: 1, | ||
label: '/path', | ||
description: '1 orphan', | ||
notes: [{ title: 'Orphan A' }], | ||
}, | ||
{ | ||
collapsibleState: 1, | ||
label: '/path-bis', | ||
description: '1 orphan', | ||
notes: [{ title: 'Orphan B' }], | ||
}, | ||
]); | ||
}); | ||
const nonOrphan2 = createTestNote({ | ||
uri: '/path/non-orphan-2.md', | ||
links: [{ slug: 'non-orphan-1' }], | ||
}); | ||
|
||
it('should return the orphans in a directory', async () => { | ||
const provider = new OrphansProvider(workspace, dataStore, config); | ||
const directory = new Directory('/path', [orphanA as any]); | ||
const result = await provider.getChildren(directory); | ||
expect(result).toMatchObject([ | ||
{ | ||
collapsibleState: 0, | ||
label: 'Orphan A', | ||
description: '/path/orphan-a.md', | ||
command: { command: 'vscode.open' }, | ||
}, | ||
]); | ||
}); | ||
const workspace = new FoamWorkspace() | ||
.set(orphanA) | ||
.set(nonOrphan1) | ||
.set(nonOrphan2) | ||
.resolveLinks(); | ||
|
||
it('should return the flattened orphans', async () => { | ||
const mockConfig = { ...config, groupBy: OrphansConfigGroupBy.Off }; | ||
const provider = new OrphansProvider(workspace, dataStore, mockConfig); | ||
const result = await provider.getChildren(); | ||
expect(result).toMatchObject([ | ||
{ | ||
collapsibleState: 0, | ||
label: 'Orphan A', | ||
description: '/path/orphan-a.md', | ||
command: { command: 'vscode.open' }, | ||
}, | ||
{ | ||
collapsibleState: 0, | ||
label: 'Orphan B', | ||
description: '/path-bis/orphan-b.md', | ||
command: { command: 'vscode.open' }, | ||
}, | ||
]); | ||
describe('isOrphan', () => { | ||
it('should return true when a note with no connections is provided', () => { | ||
expect(isOrphan(workspace, orphanA)).toBeTruthy(); | ||
}); | ||
|
||
it('should return the orphans without exclusion', async () => { | ||
const mockConfig = { ...config, exclude: [] }; | ||
const provider = new OrphansProvider(workspace, dataStore, mockConfig); | ||
const result = await provider.getChildren(); | ||
expect(result).toMatchObject([ | ||
expect.anything(), | ||
expect.anything(), | ||
{ | ||
collapsibleState: 1, | ||
label: '/path-exclude', | ||
description: '1 orphan', | ||
notes: [{ title: 'Orphan C' }], | ||
}, | ||
]); | ||
it('should return false when a note with connections is provided', () => { | ||
expect(isOrphan(workspace, nonOrphan1)).toBeFalsy(); | ||
}); | ||
}); |
Oops, something went wrong.