diff --git a/src/components/JobFileSelector.tsx b/src/components/JobFileSelector.tsx index 88c3983..a8304c0 100644 --- a/src/components/JobFileSelector.tsx +++ b/src/components/JobFileSelector.tsx @@ -11,19 +11,34 @@ export const JobFileSelector = (props: JobFileSelectorProps) => { const [query, setQuery] = createSignal(""); const [selectedJobId, setSelectedJobId] = createSignal(null); - // Auto-detect job ID from active note tags + // Auto-detect job ID from active note tags (traversing up hierarchy) onMount(() => { const currentNoteId = activeNoteId(); if (currentNoteId) { - const currentNote = store.notes.find(n => n.id === currentNoteId); - if (currentNote) { - const jobIdTag = currentNote.tags.find(t => t.startsWith("job_id:")); + let currentId = currentNoteId; + let currentNote = store.notes.find(n => n.id === currentId); + let depth = 0; + + // Traverse up "child-of-" tags to find the root or any ancestor with a job_id + while (currentNote && depth < 10) { + const jobIdTag = currentNote.tags?.find(t => t.startsWith("job_id:")); if (jobIdTag) { const id = jobIdTag.split(":")[1]; if (id) { setSelectedJobId(id); + return; // Found it! } } + + const parentTag = currentNote.tags?.find(t => t.startsWith("child-of-")); + if (!parentTag) break; + + const parentId = parentTag.replace("child-of-", ""); + const parent = store.notes.find(n => n.id === parentId); + if (!parent) break; + + currentNote = parent; + depth++; } } }); diff --git a/src/lib/extensions/file-viewer.ts b/src/lib/extensions/file-viewer.ts index 44d33a9..f68954c 100644 --- a/src/lib/extensions/file-viewer.ts +++ b/src/lib/extensions/file-viewer.ts @@ -33,9 +33,29 @@ export const FileViewer = Node.create({ addAttributes() { return { - jobId: { default: null }, - collectionId: { default: 'Job_Info_Prod' }, - filename: { default: null }, + jobId: { + default: null, + parseHTML: element => element.getAttribute('data-job-id'), + renderHTML: attributes => { + if (!attributes.jobId) return {}; + return { 'data-job-id': attributes.jobId }; + }, + }, + collectionId: { + default: 'Job_Info_Prod', + parseHTML: element => element.getAttribute('data-collection-id') || 'Job_Info_Prod', + renderHTML: attributes => { + return { 'data-collection-id': attributes.collectionId || 'Job_Info_Prod' }; + }, + }, + filename: { + default: null, + parseHTML: element => element.getAttribute('data-filename'), + renderHTML: attributes => { + if (!attributes.filename) return {}; + return { 'data-filename': attributes.filename }; + }, + }, }; },