UNPKG

bookr-cli

Version:

A terminal-based CLI tool to book time in Jira using the Tempo plugin by parsing your current Git branch name

30 lines 3.64 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text } from 'ink'; import { secondsToJiraFormat } from '../utils/time-parser.js'; export const WorklogTable = ({ worklogs, title = 'Worklogs', showTempoId = true, showJiraId = true, showSource = false, }) => { if (!worklogs.length) { return (_jsx(Box, { flexDirection: "column", padding: 1, children: _jsx(Text, { color: "yellow", children: "\uD83D\uDCED No worklogs found." }) })); } // Calculate totals const totalSeconds = worklogs.reduce((sum, w) => sum + w.timeSpentSeconds, 0); const totalTime = secondsToJiraFormat(totalSeconds); const totalHours = (totalSeconds / 3600).toFixed(2); const uniqueIssues = new Set(worklogs.map(w => w.issueKey)); // Determine column widths based on content const maxTempoIdLength = Math.max(8, ...worklogs.map(w => (w.tempoId || '').length)); const maxJiraIdLength = Math.max(8, ...worklogs.map(w => (w.jiraId || '').length)); const maxIssueKeyLength = Math.max(6, ...worklogs.map(w => w.issueKey.length)); const maxTimeLength = 6; // Fixed width for time column const maxSummaryLength = Math.max(8, ...worklogs.map(w => w.summary.length)); const maxSourceLength = showSource ? 6 : 0; // "tempo" or "jira" // Create separator line const separatorLength = (showTempoId ? maxTempoIdLength + 3 : 0) + (showJiraId ? maxJiraIdLength + 3 : 0) + maxIssueKeyLength + 3 + maxTimeLength + 3 + maxSummaryLength + (showSource ? maxSourceLength + 3 : 0); const separator = '─'.repeat(separatorLength); return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Text, { color: "cyan", bold: true, children: title }), _jsx(Text, { color: "gray", children: separator }), _jsxs(Box, { children: [showTempoId && (_jsxs(Text, { color: "yellow", bold: true, children: [('Tempo ID'.padEnd(maxTempoIdLength)), " |", ' '] })), showJiraId && (_jsxs(Text, { color: "yellow", bold: true, children: [('Jira ID'.padEnd(maxJiraIdLength)), " |", ' '] })), _jsxs(Text, { color: "yellow", bold: true, children: [('Issue'.padEnd(maxIssueKeyLength)), " |", ' '] }), _jsxs(Text, { color: "yellow", bold: true, children: [('Time'.padEnd(maxTimeLength)), " |", ' '] }), _jsx(Text, { color: "yellow", bold: true, children: "Summary" }), showSource && (_jsx(Text, { color: "yellow", bold: true, children: ' | Source' }))] }), _jsx(Text, { color: "gray", children: separator }), worklogs.map((worklog, index) => (_jsxs(Box, { children: [showTempoId && (_jsxs(Text, { children: [(worklog.tempoId || '').padEnd(maxTempoIdLength), " |", ' '] })), showJiraId && (_jsxs(Text, { children: [(worklog.jiraId || '').padEnd(maxJiraIdLength), " |", ' '] })), _jsxs(Text, { children: [worklog.issueKey.padEnd(maxIssueKeyLength), " |", ' '] }), _jsxs(Text, { children: [secondsToJiraFormat(worklog.timeSpentSeconds).padEnd(maxTimeLength), " |", ' '] }), _jsx(Text, { children: worklog.summary }), showSource && (_jsxs(Text, { children: [' | ', (worklog.source || '').padEnd(maxSourceLength)] }))] }, `${worklog.tempoId || worklog.jiraId || index}`))), _jsx(Text, { color: "gray", children: separator }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { color: "green", bold: true, children: ["\uD83D\uDCCA Total time: ", totalTime, " (", totalHours, " hours)"] }), _jsxs(Text, { color: "blue", children: ["\uD83D\uDCDD Worklog entries: ", worklogs.length] }), _jsxs(Text, { color: "magenta", children: ["\uD83C\uDFAF Issues worked on: ", uniqueIssues.size] })] })] })); }; //# sourceMappingURL=WorklogTable.js.map