Skip to content

Commit

Permalink
feat: improves report table output (#46)
Browse files Browse the repository at this point in the history
* adds cli-table3 dependency

* feat(today report): improves output

* feat(weekly report): improves table output format

But its kludgy because the data structure has been forced for console.table. This works but it could be improved. A lot

* ci(lint): corrects error in eslint rules

* fix: lintfix

* chore(release): 0.10.8

* docs: updates feature table
  • Loading branch information
beauraines authored Mar 13, 2023
1 parent bdf396f commit 4e90a80
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"sourceType": "module"
},
"rules": {
"allowTernary": true
"no-unused-expressions": "warn"
}
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.10.8](https://github.com/beauraines/toggl-cli/compare/v0.10.7...v0.10.8) (2023-03-13)


### Features

* **today report:** improves output ([0025d4a](https://github.com/beauraines/toggl-cli/commit/0025d4a4ab2f81ea31e27cd06d4ce0e69e3288f5))
* **weekly report:** improves table output format ([4e58b1a](https://github.com/beauraines/toggl-cli/commit/4e58b1a7bbf6fcdc815be44e87f7aeca44583a09))


### Bug Fixes

* lintfix ([e52684c](https://github.com/beauraines/toggl-cli/commit/e52684c022a02bdf4add209fdc0a7681095a85ee))

### [0.10.7](https://github.com/beauraines/toggl-cli/compare/v0.10.6...v0.10.7) (2023-03-12)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This was made possible because [saintedlama](https://github.com/saintedlama) had
| Client: other user feature? | | |
| Client: specify client name | | |
| Colorize output | | |
| Better table output | | |
| Better table output | | |
| List recent time entries || |
| Command line completion || [#6](https://github.com/beauraines/toggl-cli-node/issues/6) |

Expand Down
13 changes: 10 additions & 3 deletions cmds/today.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Client from '../client.js'
import dayjs from 'dayjs'
import {getWorkspace,getProjects, formatDuration,formatDurationAsTime} from '../utils.js'
import { getWorkspace, getProjects, formatDuration, formatDurationAsTime } from '../utils.js'
import dur from 'dayjs/plugin/duration.js'
import relativeTime from 'dayjs/plugin/relativeTime.js'
import Table from 'cli-table3'
dayjs.extend(relativeTime)
dayjs.extend(dur)

Expand All @@ -14,7 +15,7 @@ export const handler = async function (argv) {
const client = Client()
const workspace = await getWorkspace()
const projects = await getProjects(workspace.id)
const params = {
const params = {
start_date: dayjs().startOf('day').toISOString(),
end_date: dayjs().toISOString()
}
Expand Down Expand Up @@ -77,7 +78,13 @@ function displayDailyReport (report, format) {
break
case 'table':
default:
console.table(report, ['project_name', 'duration_formatted'])
const table = new Table({
head: ['Project', 'Duration']
})
for (const project of report) {
table.push([project.project_name, project.duration_formatted])
}
console.log(table.toString())
break
}
}
11 changes: 10 additions & 1 deletion cmds/weekly.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getWorkspace, formatDuration, getProjectById } from '../utils.js'
import dayjs from 'dayjs'
import dur from 'dayjs/plugin/duration.js'
import relativeTime from 'dayjs/plugin/relativeTime.js'
import Table from 'cli-table3'
dayjs.extend(relativeTime)
dayjs.extend(dur)

Expand Down Expand Up @@ -54,7 +55,15 @@ export const handler = async function (argv) {
for (const project of reportData) {
project.Total = formatDuration(project.Total * 1000)
}
console.table(reportData)

const head = Object.keys(reportData[0])
const table = new Table({
head
})
for (const project of reportData) {
table.push(Object.values(project))
}
console.log(table.toString())
}

// TODO figure out what to do with these
Expand Down
28 changes: 26 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beauraines/toggl-cli",
"version": "0.10.7",
"version": "0.10.8",
"description": "",
"main": "cli.js",
"bin": {
Expand Down Expand Up @@ -30,6 +30,7 @@
},
"license": "MIT",
"dependencies": {
"cli-table3": "^0.6.3",
"dayjs": "^1.11.6",
"debug": "^4.3.4",
"dotenv": "^16.0.3",
Expand Down

0 comments on commit 4e90a80

Please sign in to comment.