Skip to content

Commit

Permalink
feat: maintain indent in "Copy as Table" and "Copy as CSV" exports fo…
Browse files Browse the repository at this point in the history
…r sub-entries

Enhanced the `createTableSection` function to include dynamic prefixing based on the indentation level, ensuring the hierarchical structure of sub-entries is preserved. Each sub-entry level now includes an additional `-` prefix, improving readability in both "Copy as Table" and "Copy as CSV" exports.

This feature resolves issue Ellpeck#22.
  • Loading branch information
Karamellwuerfel committed Nov 17, 2024
1 parent 1831b25 commit be98e22
Showing 1 changed file with 21 additions and 5 deletions.
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

0 comments on commit be98e22

Please sign in to comment.