Skip to content

Commit

Permalink
fix(ui): task duration (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
bozerkins authored Oct 13, 2023
1 parent 8dfe92b commit d112631
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,24 @@ go mod download
LOG_LEVEL=debug LOG_FORMAT=text ARGO_URL=http://localhost:8081 ARGO_TOKEN=example STATE_TYPE=in-memory go run . -server
```


### Start the argo-watcher server (postgres)

Start database

```shell
# start the database in a separate terminal window
docker compose up postgres
```

Start server

```shell
# go to backend directory
cd cmd/argo-watcher
# install dependencies
go mod tidy
# OR start argo-watcher (postgres)
LOG_LEVEL=debug LOG_FORMAT=text ARGO_URL=http://localhost:8081 ARGO_TOKEN=example STATE_TYPE=postgres DB_USER=watcher DB_PASSWORD=watcher DB_NAME=watcher go run . -server
LOG_LEVEL=debug LOG_FORMAT=text ARGO_URL=http://localhost:8081 ARGO_TOKEN=example STATE_TYPE=postgres DB_USER=watcher DB_PASSWORD=watcher DB_NAME=watcher DB_MIGRATIONS_PATH=../../db/migrations go run . -server
```

#### Logs in simple text
Expand Down
8 changes: 5 additions & 3 deletions web/src/Components/TasksTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,12 @@ function TasksTable({
)}
</TableCell>
<TableCell>
{task.updated && (
<span>{taskDuration(task.created, task.updated)}</span>
{task.status === 'in progress' && (
<span>{taskDuration(task.created, null)}</span>
)}
{task.status !== 'in progress' && (
<span>{taskDuration(task.created, task?.updated)}</span>
)}
{!task.updated && <span>-</span>}
</TableCell>
<TableCell>
{task.images.map((item, index) => {
Expand Down
16 changes: 12 additions & 4 deletions web/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@ export const relativeTime = oldTimestamp => {
};

export const relativeHumanDuration = seconds => {
function numberEnding(number) {
return number > 1 ? 's' : '';
}

if (seconds < 60) {
// Less than a minute has passed:
return `< 1 minute`;
} else if (seconds < 3600) {
// Less than an hour has passed:
return `${Math.floor(seconds / 60)} minutes`;
const minutes = Math.floor(seconds / 60);
return `${minutes} minute${numberEnding(minutes)}`;
} else if (seconds < 86400) {
// Less than a day has passed:
return `${Math.floor(seconds / 3600)} hours`;
const hours = Math.floor(seconds / 3600);
return `${hours} hour${numberEnding(hours)}`;
} else if (seconds < 2620800) {
// Less than a month has passed:
return `${Math.floor(seconds / 86400)} days`;
const days = Math.floor(seconds / 86400);
return `${days} day${numberEnding(days)}`;
} else if (seconds < 31449600) {
// Less than a year has passed:
return `${Math.floor(seconds / 2620800)} months`;
const months = Math.floor(seconds / 2620800);
return `${months} month${numberEnding(months)}`;
}

// More than a year has passed:
Expand Down

0 comments on commit d112631

Please sign in to comment.