Skip to content

Commit

Permalink
fix(workspace): rename note breaks noteref for user hierarchy (#3782)
Browse files Browse the repository at this point in the history
* fix(workspace): rename note breaks noteref for user hierarchy

* added comment
  • Loading branch information
Harshita-mindfire committed Nov 16, 2022
1 parent 7c9abf7 commit 053b949
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/engine-server/src/DendronEngineV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,9 @@ export class DendronEngineV3 extends EngineV3Base implements DEngine {
// And if this used to be a frontmatter tag, the alias being undefined will force it to be removed because a frontmatter tag can't point to something outside of tags hierarchy.
alias = undefined;
}
// for user tag links, we'll have to regenerate the alias
if (newLoc.fname.startsWith(USERS_HIERARCHY)) {
// for user tag links, we'll have to regenerate the alias.
// added link.type !==ref check because syntax like !@john doesn't work as a note ref
if (link.type !== "ref" && newLoc.fname.startsWith(USERS_HIERARCHY)) {
const fnameWithoutTag = newLoc.fname.slice(USERS_HIERARCHY.length);
alias = `@${fnameWithoutTag}`;
} else if (oldLink.from.fname.startsWith(USERS_HIERARCHY)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-server/src/drivers/file/storev2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ export class FileStorage implements DStore {
alias = undefined;
}
// for user tag links, we'll have to regenerate the alias
if (newLoc.fname.startsWith(USERS_HIERARCHY)) {
if (link.type !== "ref" && newLoc.fname.startsWith(USERS_HIERARCHY)) {
const fnameWithoutTag = newLoc.fname.slice(USERS_HIERARCHY.length);
alias = `@${fnameWithoutTag}`;
} else if (oldLink.from.fname.startsWith(USERS_HIERARCHY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,61 @@ suite("RenameNoteCommand", function () {
expect(updatedSomeNote.body).toEqual("[[foo]]");
});
});
describeMultiWS("GIVEN a note with reference to user note", {}, () => {
test("WHEN renamed THEN note ref should not break", async () => {
const extension = ExtensionProvider.getExtension();
const { vaults, wsRoot } = extension.getDWorkspace();
const engine = extension.getEngine();
const oldNote = await NoteTestUtilsV4.createNoteWithEngine({
fname: "user.one",
body: "note body",
vault: vaults[0],
engine,
wsRoot,
});

await NoteTestUtilsV4.createNoteWithEngine({
fname: "some-note",
body: "![[user.one]]",
vault: vaults[0],
wsRoot,
engine,
});
await extension.wsUtils.openNote(oldNote);
const cmd = new RenameNoteCommand(extension);
const vaultName = VaultUtils.getName(vaults[0]);
await cmd.execute({
moves: [
{
oldLoc: {
fname: oldNote.fname,
vaultName,
},
newLoc: {
fname: "user.two",
vaultName,
},
},
],
nonInteractive: true,
initialValue: "user.two",
});
// note `user.one` is renamed to `user.two`, `some-note`'s reference to `![[user.one]]` is updated to `![[user.two]]`
const newNote = (
await engine.findNotes({
vault: vaults[0],
fname: "user.two",
})
)[0];
expect(newNote).toBeTruthy();

const updatedSomeNote = (
await engine.findNotes({
vault: vaults[0],
fname: "some-note",
})
)[0];
expect(updatedSomeNote.body).toEqual("![[user.two]]");
});
});
});

0 comments on commit 053b949

Please sign in to comment.