MCPcopy
hub / github.com/callumalpass/tasknotes / assignTaskAsSubtask

Function assignTaskAsSubtask

src/services/taskRelationshipActions.ts:104–140  ·  view source on GitHub ↗
(
	plugin: TaskNotesPlugin,
	parentFile: TFile,
	subtask: TaskInfo
)

Source from the content-addressed store, hash-verified

102}
103
104export async function assignTaskAsSubtask(
105 plugin: TaskNotesPlugin,
106 parentFile: TFile,
107 subtask: TaskInfo
108): Promise<TaskInfo | null> {
109 const projectReference = generateLink(
110 plugin.app,
111 parentFile,
112 subtask.path,
113 "",
114 "",
115 plugin.settings.useFrontmatterMarkdownLinks
116 );
117 const legacyReference = `[[${parentFile.basename}]]`;
118 const subtaskProjects = Array.isArray(subtask.projects) ? subtask.projects : [];
119
120 if (subtaskProjects.includes(projectReference) || subtaskProjects.includes(legacyReference)) {
121 publishUserNotice(
122 plugin.emitter,
123 translate(plugin, "contextMenus.task.organization.notices.alreadySubtask")
124 );
125 return null;
126 }
127
128 const sanitizedProjects = subtaskProjects.filter((entry) => entry !== legacyReference);
129 const updatedProjects = [...sanitizedProjects, projectReference];
130 const updatedSubtask = await plugin.updateTaskProperty(subtask, "projects", updatedProjects);
131
132 publishUserNotice(
133 plugin.emitter,
134 translate(plugin, "contextMenus.task.organization.notices.addedAsSubtask", {
135 subtask: subtask.title,
136 parent: parentFile.basename,
137 })
138 );
139 return updatedSubtask;
140}
141
142export function buildSubtaskCreationPrePopulatedValues(
143 plugin: TaskNotesPlugin,

Calls 4

generateLinkFunction · 0.90
publishUserNoticeFunction · 0.90
updateTaskPropertyMethod · 0.80
translateFunction · 0.70

Tested by

no test coverage detected