Working file loading!
This commit is contained in:
@@ -11,19 +11,34 @@ export const JobFileSelector = (props: JobFileSelectorProps) => {
|
||||
const [query, setQuery] = createSignal("");
|
||||
const [selectedJobId, setSelectedJobId] = createSignal<string | null>(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++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -33,9 +33,29 @@ export const FileViewer = Node.create<FileViewerOptions>({
|
||||
|
||||
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 };
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user