Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags explorer improvements #1275

Merged
merged 15 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/foam-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@
"when": "view == foam-vscode.orphans && foam-vscode.views.orphans.group-by == 'folder'",
"group": "navigation"
},
{
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.show == 'all'",
"group": "navigation"
},
{
"command": "foam-vscode.views.tags-explorer.show:all",
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.show == 'for-current-file'",
"group": "navigation"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:folder",
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.group-by == 'off'",
"group": "navigation"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:off",
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.group-by == 'folder'",
"group": "navigation"
},
{
"command": "foam-vscode.views.placeholders.show:for-current-file",
"when": "view == foam-vscode.placeholders && foam-vscode.views.placeholders.show == 'all'",
Expand Down Expand Up @@ -192,6 +212,22 @@
"command": "foam-vscode.views.orphans.group-by:off",
"when": "false"
},
{
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
"when": "false"
},
{
"command": "foam-vscode.views.tags-explorer.show:all",
"when": "false"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:folder",
"when": "false"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:off",
"when": "false"
},
{
"command": "foam-vscode.views.placeholders.show:for-current-file",
"when": "false"
Expand Down Expand Up @@ -308,6 +344,26 @@
"title": "Flat list",
"icon": "$(list-flat)"
},
{
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
"title": "Show tags in current file",
"icon": "$(file)"
},
{
"command": "foam-vscode.views.tags-explorer.show:all",
"title": "Show tags in workspace",
"icon": "$(files)"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:folder",
"title": "Group By Folder",
"icon": "$(list-tree)"
},
{
"command": "foam-vscode.views.tags-explorer.group-by:off",
"title": "Flat list",
"icon": "$(list-flat)"
},
{
"command": "foam-vscode.views.placeholders.show:for-current-file",
"title": "Show placeholders in current file",
Expand Down
4 changes: 0 additions & 4 deletions packages/foam-vscode/src/features/panels/notes-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ export class NotesProvider extends FolderTreeProvider<
return parts;
}

isValueType(value: Resource): value is Resource {
return value.uri != null;
}

createValueTreeItem(
value: Resource,
parent: FolderTreeItem<Resource>
Expand Down
42 changes: 20 additions & 22 deletions packages/foam-vscode/src/features/panels/tags-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Tags tree panel', () => {
});
const workspace = new FoamWorkspace().set(noteA);
const foamTags = FoamTags.fromWorkspace(workspace);
const provider = new TagsProvider(foamTags, workspace);
const provider = new TagsProvider(foamTags, workspace, false);
provider.refresh();

const treeItems = (await provider.getChildren()) as TagItem[];
Expand All @@ -43,12 +43,12 @@ describe('Tags tree panel', () => {
});
const workspace = new FoamWorkspace().set(noteA);
const foamTags = FoamTags.fromWorkspace(workspace);
const provider = new TagsProvider(foamTags, workspace);
const provider = new TagsProvider(foamTags, workspace, false);
provider.refresh();

const parentTreeItems = (await provider.getChildren()) as TagItem[];
const parentTagItem = parentTreeItems.pop();
expect(parentTagItem.title).toEqual('parent');
expect(parentTagItem.label).toEqual('parent');

const childTreeItems = (await provider.getChildren(
parentTagItem
Expand All @@ -57,7 +57,7 @@ describe('Tags tree panel', () => {
childTreeItems.forEach(child => {
if (child instanceof TagItem) {
// eslint-disable-next-line jest/no-conditional-expect
expect(child.title).toEqual('child');
expect(child.label).toEqual('child');
}
});
});
Expand All @@ -73,15 +73,15 @@ describe('Tags tree panel', () => {
});
const workspace = new FoamWorkspace().set(noteA).set(noteB);
const foamTags = FoamTags.fromWorkspace(workspace);
const provider = new TagsProvider(foamTags, workspace);
const provider = new TagsProvider(foamTags, workspace, false);
provider.refresh();

const parentTreeItems = (await provider.getChildren()) as TagItem[];
const parentTagItem = parentTreeItems.filter(
item => item instanceof TagItem
)[0];

expect(parentTagItem.title).toEqual('parent');
expect(parentTagItem.label).toEqual('parent');
expect(parentTreeItems).toHaveLength(1);

const childTreeItems = (await provider.getChildren(
Expand All @@ -91,12 +91,12 @@ describe('Tags tree panel', () => {
childTreeItems.forEach(child => {
if (child instanceof TagItem) {
// eslint-disable-next-line jest/no-conditional-expect
expect(['child', 'subchild']).toContain(child.title);
expect(['child', 'subchild']).toContain(child.label);
// eslint-disable-next-line jest/no-conditional-expect
expect(child.title).not.toEqual('parent');
expect(child.label).not.toEqual('parent');
}
});
expect(childTreeItems).toHaveLength(3);
expect(childTreeItems).toHaveLength(2);
});

it('handles a parent and child tag in the same note', async () => {
Expand All @@ -107,7 +107,7 @@ describe('Tags tree panel', () => {
});
const workspace = new FoamWorkspace().set(noteC);
const foamTags = FoamTags.fromWorkspace(workspace);
const provider = new TagsProvider(foamTags, workspace);
const provider = new TagsProvider(foamTags, workspace, false);

provider.refresh();

Expand All @@ -116,7 +116,7 @@ describe('Tags tree panel', () => {
item => item instanceof TagItem
)[0];

expect(parentTagItem.title).toEqual('main');
expect(parentTagItem.label).toEqual('main');

const childTreeItems = (await provider.getChildren(
parentTagItem
Expand All @@ -132,10 +132,10 @@ describe('Tags tree panel', () => {
.filter(item => item instanceof TagItem)
.forEach(item => {
expect(['main/subtopic']).toContain(item.tag);
expect(item.title).toEqual('subtopic');
expect(item.label).toEqual('subtopic');
});

expect(childTreeItems).toHaveLength(3);
expect(childTreeItems).toHaveLength(2);
});

it('handles a tag with multiple levels of hierarchy - #1134', async () => {
Expand All @@ -145,28 +145,26 @@ describe('Tags tree panel', () => {
});
const workspace = new FoamWorkspace().set(noteA);
const foamTags = FoamTags.fromWorkspace(workspace);
const provider = new TagsProvider(foamTags, workspace);
const provider = new TagsProvider(foamTags, workspace, false);

provider.refresh();

const parentTreeItems = (await provider.getChildren()) as TagItem[];
const parentTagItem = parentTreeItems.pop();
expect(parentTagItem.title).toEqual('parent');
expect(parentTagItem.label).toEqual('parent');

const childTreeItems = (await provider.getChildren(
parentTagItem
)) as TagItem[];

expect(childTreeItems).toHaveLength(2);
expect(childTreeItems[0].label).toMatch(/^Search.*/);
expect(childTreeItems[1].label).toEqual('child');
expect(childTreeItems).toHaveLength(1);
expect(childTreeItems[0].label).toEqual('child');

const grandchildTreeItems = (await provider.getChildren(
childTreeItems[1]
childTreeItems[0]
)) as TagItem[];

expect(grandchildTreeItems).toHaveLength(2);
expect(grandchildTreeItems[0].label).toMatch(/^Search.*/);
expect(grandchildTreeItems[1].label).toEqual('second');
expect(grandchildTreeItems).toHaveLength(1);
expect(grandchildTreeItems[0].label).toEqual('second');
});
});
Loading
Loading