MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / buildTaskListGroupedRenderItems

Function buildTaskListGroupedRenderItems

src/bases/taskListGrouping.ts:170–242  ·  view source on GitHub ↗
(options: {
	groups: readonly TaskListGroup[];
	taskNotes: readonly TaskInfo[];
	subGroupPropertyId: string | null;
	pathToProps: ReadonlyMap<string, Record<string, unknown>>;
	collapsedGroups: ReadonlySet<string>;
	collapsedSubGroups: ReadonlySet<string>;
	convertGroupKeyToString: (key: unknown) => string;
})

Source from the content-addressed store, hash-verified

168}
169
170export function buildTaskListGroupedRenderItems(options: {
171 groups: readonly TaskListGroup[];
172 taskNotes: readonly TaskInfo[];
173 subGroupPropertyId: string | null;
174 pathToProps: ReadonlyMap<string, Record<string, unknown>>;
175 collapsedGroups: ReadonlySet<string>;
176 collapsedSubGroups: ReadonlySet<string>;
177 convertGroupKeyToString: (key: unknown) => string;
178}): TaskListRenderItem[] {
179 const items: TaskListRenderItem[] = [];
180
181 for (const group of options.groups) {
182 const primaryKey = options.convertGroupKeyToString(group.key);
183 const groupPaths = new Set(group.entries.map((entry) => entry.file?.path));
184 const groupTasks = options.taskNotes.filter((task) => groupPaths.has(task.path));
185
186 if (groupTasks.length === 0) continue;
187
188 const isPrimaryCollapsed = options.collapsedGroups.has(primaryKey);
189 items.push({
190 type: "primary-header",
191 groupKey: primaryKey,
192 groupTitle: primaryKey,
193 taskCount: groupTasks.length,
194 groupEntries: group.entries,
195 isCollapsed: isPrimaryCollapsed,
196 });
197
198 if (isPrimaryCollapsed) continue;
199
200 if (options.subGroupPropertyId) {
201 const subGroups = groupTasksByTaskListSubProperty(
202 groupTasks,
203 options.subGroupPropertyId,
204 options.pathToProps
205 );
206
207 for (const [subKey, subTasks] of subGroups) {
208 if (subTasks.length === 0) continue;
209
210 const compoundKey = `${primaryKey}:${subKey}`;
211 const isSubCollapsed = options.collapsedSubGroups.has(compoundKey);
212 items.push({
213 type: "sub-header",
214 groupKey: primaryKey,
215 subGroupKey: subKey,
216 subGroupTitle: subKey,
217 taskCount: subTasks.length,
218 isCollapsed: isSubCollapsed,
219 parentKey: primaryKey,
220 });
221
222 if (!isSubCollapsed) {
223 for (const task of subTasks) {
224 items.push({
225 type: "task",
226 task,
227 groupKey: primaryKey,

Callers 3

renderGroupedMethod · 0.90
refreshGroupedViewMethod · 0.90

Calls 3

hasMethod · 0.80

Tested by

no test coverage detected