Skip to content

Commit a822a07

Browse files
authored
enhance: show vaults by name instead of path (#1078)
* chore: auto build on dev * enhance: show vaults by name instead of path
1 parent 49c6005 commit a822a07

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
- dev
78
- integ-publish
89
pull_request:
910
branches:

packages/plugin-core/src/components/lookup/utils.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const CONTEXT_DETAIL = "current note context";
4141
export const HIERARCHY_MATCH_DETAIL = "hierarchy match";
4242
export const FULL_MATCH_DETAIL = "hierarchy match and current note context";
4343

44-
export type VaultPickerItem = { vault: DVault } & Partial<QuickPickItem>;
44+
export type VaultPickerItem = { vault: DVault, label: string } & Partial<Omit<QuickPickItem, "label">>;
4545

4646
function isDVaultArray(
4747
overrides?: VaultPickerItem[] | DVault[]
@@ -452,14 +452,14 @@ export class PickerUtilsV2 {
452452
): Promise<DVault | undefined> {
453453
const pickerOverrides = isDVaultArray(overrides)
454454
? overrides.map((value) => {
455-
return { vault: value };
455+
return { vault: value, label: VaultUtils.getName(value) };
456456
})
457457
: overrides;
458458

459459
const vaults: VaultPickerItem[] =
460460
pickerOverrides ??
461-
DendronWorkspace.instance().vaultsv4.map((value) => {
462-
return { vault: value };
461+
DendronWorkspace.instance().vaultsv4.map((vault) => {
462+
return { vault, label: VaultUtils.getName(vault) };
463463
});
464464

465465
const items = vaults.map((ent) => ({
@@ -492,7 +492,7 @@ export class PickerUtilsV2 {
492492

493493
// Only 1 vault, no other options to choose from:
494494
if (engine.vaults.length <= 1) {
495-
return Array.of({ vault });
495+
return Array.of({ vault, label: VaultUtils.getName(vault) });
496496
}
497497

498498
const domain = fname.split(".").slice(0, -1);
@@ -517,6 +517,7 @@ export class PickerUtilsV2 {
517517
return {
518518
vault: value,
519519
detail: HIERARCHY_MATCH_DETAIL,
520+
label: VaultUtils.getName(vault)
520521
};
521522
});
522523

@@ -525,11 +526,12 @@ export class PickerUtilsV2 {
525526
vaultSuggestions.push({
526527
vault,
527528
detail: CONTEXT_DETAIL,
529+
label: VaultUtils.getName(vault)
528530
});
529531

530532
allVaults.forEach((cmpVault) => {
531533
if (cmpVault.fsPath !== vault.fsPath) {
532-
vaultSuggestions.push({ vault: cmpVault });
534+
vaultSuggestions.push({ vault: cmpVault, label: VaultUtils.getName(vault) });
533535
}
534536
});
535537
}
@@ -543,6 +545,7 @@ export class PickerUtilsV2 {
543545
vaultSuggestions.push({
544546
vault,
545547
detail: FULL_MATCH_DETAIL,
548+
label: VaultUtils.getName(vault)
546549
});
547550

548551
vaultsWithMatchingHierarchy.forEach((ent) => {
@@ -554,6 +557,7 @@ export class PickerUtilsV2 {
554557
vaultSuggestions.push({
555558
vault: ent.vault,
556559
detail: HIERARCHY_MATCH_DETAIL,
560+
label: VaultUtils.getName(vault)
557561
});
558562
}
559563
});
@@ -564,7 +568,7 @@ export class PickerUtilsV2 {
564568
(suggestion) => suggestion.vault.fsPath === wsVault.fsPath
565569
)
566570
) {
567-
vaultSuggestions.push({ vault: wsVault });
571+
vaultSuggestions.push({ vault: wsVault, label: VaultUtils.getName(wsVault) });
568572
}
569573
});
570574
} else {
@@ -573,6 +577,7 @@ export class PickerUtilsV2 {
573577
vaultSuggestions.push({
574578
vault,
575579
detail: CONTEXT_DETAIL,
580+
label: VaultUtils.getName(vault)
576581
});
577582

578583
allVaults.forEach((wsVault) => {
@@ -581,7 +586,7 @@ export class PickerUtilsV2 {
581586
(suggestion) => suggestion.vault.fsPath === wsVault.fsPath
582587
)
583588
) {
584-
vaultSuggestions.push({ vault: wsVault });
589+
vaultSuggestions.push({ vault: wsVault, label: VaultUtils.getName(wsVault) });
585590
}
586591
});
587592
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { VaultUtils } from "@dendronhq/common-all";
2+
import {
3+
ENGINE_HOOKS
4+
} from "@dendronhq/engine-test-utils";
5+
import { describe } from "mocha";
6+
import sinon from "sinon";
7+
import { PickerUtilsV2, VaultPickerItem } from "../../components/lookup/utils";
8+
import { VSCodeUtils } from "../../utils";
9+
import { expect } from "../testUtilsv2";
10+
import {
11+
runLegacyMultiWorkspaceTest, setupBeforeAfter
12+
} from "../testUtilsV3";
13+
14+
suite("Plugin Utils", function () {
15+
describe("PickerUtils", function () {
16+
const ctx = setupBeforeAfter(this);
17+
18+
test("vault picker", function (done) {
19+
runLegacyMultiWorkspaceTest({
20+
ctx,
21+
postSetupHook: ENGINE_HOOKS.setupBasic,
22+
onInit: async ({vaults}) => {
23+
const stub = sinon.stub(VSCodeUtils, "showQuickPick").returns({} as any);
24+
await PickerUtilsV2.promptVault();
25+
const items: VaultPickerItem[] = vaults.map((vault) => ({
26+
vault,
27+
label: VaultUtils.getName(vault)
28+
}));
29+
expect(stub.calledOnceWith(items)).toBeTruthy();
30+
done();
31+
},
32+
});
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)