Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): task duration #209

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading