bookr-cli
Version:
A terminal-based CLI tool to book time in Jira using the Tempo plugin by parsing your current Git branch name
33 lines • 2.83 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
function formatHours(hours) {
return hours % 1 === 0 ? `${hours}h` : `${hours.toFixed(1)}h`;
}
function formatPercentage(percentage) {
if (typeof percentage === 'string')
return `${percentage}%`;
return `${percentage.toFixed(1)}%`;
}
export const ProgressTable = ({ rows, title = 'Progress', showWorkload = false }) => {
// Determine column widths
const maxDayLength = Math.max(6, ...rows.map(r => r.dayName.length));
const maxDateLength = Math.max(10, ...rows.map(r => r.date.length));
const maxHoursLength = Math.max(5, ...rows.map(r => formatHours(r.hoursLogged).length));
const maxRequiredLength = showWorkload ? Math.max(8, ...rows.map(r => formatHours(r.hoursRequired || 0).length)) : 0;
const maxPercLength = Math.max(4, ...rows.map(r => formatPercentage(r.percentage).length));
const separatorLength = maxDayLength + 3 + maxDateLength + 3 + maxHoursLength + 3 +
(showWorkload ? maxRequiredLength + 3 : 0) +
maxPercLength;
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: [_jsxs(Text, { color: "yellow", bold: true, children: ['Day'.padEnd(maxDayLength), " | "] }), _jsxs(Text, { color: "yellow", bold: true, children: ['Date'.padEnd(maxDateLength), " | "] }), _jsxs(Text, { color: "yellow", bold: true, children: ['Hours'.padEnd(maxHoursLength), " | "] }), showWorkload && _jsxs(Text, { color: "yellow", bold: true, children: ['Required'.padEnd(maxRequiredLength), " | "] }), _jsx(Text, { color: "yellow", bold: true, children: '%' })] }), _jsx(Text, { color: "gray", children: separator }), rows.map((row) => {
let color = 'red';
if (row.percentage === '100+' || (typeof row.percentage === 'number' && row.percentage >= 100)) {
color = 'green';
}
else if (typeof row.percentage === 'number' && row.percentage >= 75) {
color = 'yellow';
}
return (_jsxs(Box, { children: [_jsxs(Text, { children: [row.dayName.padEnd(maxDayLength), " | "] }), _jsxs(Text, { children: [row.date.padEnd(maxDateLength), " | "] }), _jsxs(Text, { children: [formatHours(row.hoursLogged).padEnd(maxHoursLength), " | "] }), showWorkload && _jsxs(Text, { children: [formatHours(row.hoursRequired || 0).padEnd(maxRequiredLength), " | "] }), _jsx(Text, { color: color, children: formatPercentage(row.percentage).padEnd(maxPercLength) })] }, `${row.date}-${row.dayName}`));
})] }));
};
//# sourceMappingURL=ProgressTable.js.map