feat(in-app-help): hide notes that are hidden from share

This commit is contained in:
Elian Doran 2025-03-16 13:33:07 +02:00
parent 6f799692e0
commit 8aaf2367e9
No known key found for this signature in database
2 changed files with 42 additions and 4 deletions

View File

@ -30,7 +30,37 @@ describe("In-app help", () => {
}; };
const item = parseNoteMeta(meta, "/"); const item = parseNoteMeta(meta, "/");
const icon = item.attributes?.find((a) => a.name === "iconClass"); const icon = item?.attributes?.find((a) => a.name === "iconClass");
expect(icon?.value).toBe("bx bx-star"); expect(icon?.value).toBe("bx bx-star");
}); });
it("hides note that is hidden from share tree", () => {
const meta: NoteMeta = {
isClone: false,
noteId: "yoAe4jV2yzbd",
notePath: ["OkOZllzB3fqN", "yoAe4jV2yzbd"],
title: "Features",
notePosition: 40,
prefix: null,
isExpanded: false,
type: "text",
mime: "text/html",
attributes: [
{
type: "label",
name: "shareHiddenFromTree",
value: "",
isInheritable: false,
position: 10
}
],
format: "html",
attachments: [],
dirFileName: "Features",
children: []
};
const item = parseNoteMeta(meta, "/");
expect(item).toBeFalsy();
});
}); });

View File

@ -25,15 +25,16 @@ export function getHelpHiddenSubtreeData() {
function parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] { function parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] {
if (!noteMetaFile.files) { if (!noteMetaFile.files) {
console.log("No meta files");
return []; return [];
} }
const metaRoot = noteMetaFile.files[0]; const metaRoot = noteMetaFile.files[0];
const parsedMetaRoot = parseNoteMeta(metaRoot, "/" + (metaRoot.dirFileName ?? "")); const parsedMetaRoot = parseNoteMeta(metaRoot, "/" + (metaRoot.dirFileName ?? ""));
return parsedMetaRoot.children ?? []; return parsedMetaRoot?.children ?? [];
} }
export function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem { export function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem | null {
let iconClass: string = "bx bx-file"; let iconClass: string = "bx bx-file";
const item: HiddenSubtreeItem = { const item: HiddenSubtreeItem = {
id: `_help_${noteMeta.noteId}`, id: `_help_${noteMeta.noteId}`,
@ -62,6 +63,10 @@ export function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSu
value: attribute.value value: attribute.value
}); });
} }
if (attribute.name === "shareHiddenFromTree") {
return null;
}
} }
// Handle text notes // Handle text notes
@ -84,7 +89,10 @@ export function parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSu
const children: HiddenSubtreeItem[] = []; const children: HiddenSubtreeItem[] = [];
for (const childMeta of noteMeta.children) { for (const childMeta of noteMeta.children) {
let newDocNameRoot = noteMeta.dirFileName ? `${docNameRoot}/${noteMeta.dirFileName}` : docNameRoot; let newDocNameRoot = noteMeta.dirFileName ? `${docNameRoot}/${noteMeta.dirFileName}` : docNameRoot;
children.push(parseNoteMeta(childMeta, newDocNameRoot)); const item = parseNoteMeta(childMeta, newDocNameRoot);
if (item) {
children.push(item);
}
} }
item.children = children; item.children = children;