Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: maintain indent in "Copy as Table" and "Copy as CSV" exports for sub-entries #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,33 @@ function updateLegacyInfo(entries: Entry[]): void {
}
}


function createTableSection(entry: Entry, settings: SimpleTimeTrackerSettings): string[][] {
/**
* Recursively generates a table section for the time tracker entries, maintaining the hierarchy
* and indenting sub-entries with a dynamic prefix.
*
* @param entry - The current time tracker entry to process. It may contain nested sub-entries.
* @param settings - The settings object for the SimpleTimeTracker, containing format options.
* @param indent - The current indentation level, starting at 0 for top-level entries and increasing for sub-entries.
* This value determines the prefix (e.g., "-", "--") added to sub-entry names.
*/
function createTableSection(entry: Entry, settings: SimpleTimeTrackerSettings, indent: number = 0): string[][] {
// Create dynamic prefix for sub-entries.
const prefix = `${"-".repeat(indent)} `;

// Generate the table data.
let ret = [[
entry.name,
`${prefix}${entry.name}`, // Add prefix based on the indent level.
entry.startTime ? formatTimestamp(entry.startTime, settings) : "",
entry.endTime ? formatTimestamp(entry.endTime, settings) : "",
entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : ""]];
entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : ""
]];

// If sub-entries exist, add them recursively.
if (entry.subEntries) {
for (let sub of orderedEntries(entry.subEntries, settings))
ret.push(...createTableSection(sub, settings));
ret.push(...createTableSection(sub, settings, indent + 1));
}

return ret;
}

Expand Down