Skip to content

Commit

Permalink
Fix duration filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-stupakov committed Apr 26, 2024
1 parent f408f7f commit fc3215b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 75 deletions.
2 changes: 2 additions & 0 deletions web-app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"crypto-js": "^4.1.1",
"date-fns": "^2.29.1",
"graphql": "^15.3.0",
"humanize-duration": "^3.32.0",
"jotai": "^1.10.0",
"jwt-decode": "^3.1.2",
"moment": "^2.30.1",
Expand Down Expand Up @@ -73,6 +74,7 @@
"@types/cookie": "^0.5.1",
"@types/crypto-js": "^4.1.1",
"@types/gtag.js": "^0.0.10",
"@types/humanize-duration": "^3.27.4",
"@types/node": "18.6.1",
"@types/react": "^18.0.24",
"@types/react-collapse": "^5.0.1",
Expand Down
12 changes: 11 additions & 1 deletion web-app/client/src/components/TaskItem/TaskItem.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import humanizeDuration from 'humanize-duration';
import moment from 'moment';
import Link from 'next/link';
import { FC, ReactNode } from 'react';
Expand All @@ -21,6 +22,8 @@ import {
} from 'types/globalTypes';
import styles from './TaskItem.module.scss';

const nanoSecondsToMilliseconds = (ns: number) => ns * 1e-6;

const getIcon = (state: getTasksInfo_tasksInfo_data_state): ReactNode => {
const props = {
className: styles.statusIcon,
Expand Down Expand Up @@ -79,7 +82,14 @@ const getStatus = (state: getTasksInfo_tasksInfo_data_state): ReactNode => {
return (
<>
<span className={styles.success}>Completed</span> in{' '}
{moment.duration(state.elapsedTime).humanize()}
{state.elapsedTime !== null && (
<span title={`${state.elapsedTime} ns`}>
{humanizeDuration(nanoSecondsToMilliseconds(state.elapsedTime), {
units: ['h', 'm', 's', 'ms'],
round: true,
})}
</span>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getDatasetsInfo_datasets_data,
} from '@graphql/operations/queries/__generated__/getDatasetsInfo';
import { GET_DATASETS_INFO } from '@graphql/operations/queries/getDatasetsInfo';
import { formatToRange } from '@utils/formatToRange';
import {
DatasetsQueryFilters,
DatasetsQueryOrderingParameter,
Expand Down Expand Up @@ -43,17 +44,6 @@ const defaultOrdering: Ordering = {
direction: OrderDirection.DESC,
};

const formatToRange = <T, TResult>(
values: [T | undefined, T | undefined],
formatter: (value: T) => TResult,
) =>
values.some(Boolean)
? {
from: values[0] ? formatter(values[0]) : undefined,
to: values[1] ? formatter(values[1]) : undefined,
}
: undefined;

const filtersToApi = (filters: Filters): DatasetsQueryFilters => ({
...filters,
searchString: filters.searchString || undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getTasksInfo_tasksInfo_data,
} from '@graphql/operations/queries/__generated__/getTasksInfo';
import { GET_TASKS_INFO } from '@graphql/operations/queries/getTasksInfo';
import { formatToRange } from '@utils/formatToRange';
import {
OrderDirection,
TasksQueryFilters,
Expand Down Expand Up @@ -41,21 +42,13 @@ const defaultOrdering: Ordering = {
direction: OrderDirection.DESC,
};

const secondsToNanoseconds = (s: number) => s * 1e9;

const filtersToApi = (filters: Filters): TasksQueryFilters => ({
...filters,
searchString: filters.searchString || undefined,
elapsedTime: filters.elapsedTime.some(Boolean)
? {
from: filters.elapsedTime[0] ?? undefined,
to: filters.elapsedTime[1] ?? undefined,
}
: undefined,
period: filters.period.some(Boolean)
? {
from: filters.period[0]?.toISOString() ?? undefined,
to: filters.period[1]?.toISOString() ?? undefined,
}
: undefined,
elapsedTime: formatToRange(filters.elapsedTime, secondsToNanoseconds),
period: formatToRange(filters.period, (value) => value.toISOString()),
});

const TasksOverview: FC = () => (
Expand Down
17 changes: 5 additions & 12 deletions web-app/client/src/routes/UserCabinet/tabs/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getOwnTasks_user_tasks_data,
} from '@graphql/operations/queries/__generated__/getOwnTasks';
import { GET_OWN_TASKS } from '@graphql/operations/queries/getOwnTasks';
import { formatToRange } from '@utils/formatToRange';
import {
OrderDirection,
TasksQueryFilters,
Expand Down Expand Up @@ -39,21 +40,13 @@ const defaultOrdering: Ordering = {
direction: OrderDirection.DESC,
};

const secondsToNanoseconds = (s: number) => s * 1e9;

const filtersToApi = (filters: Filters): TasksQueryFilters => ({
...filters,
searchString: filters.searchString || undefined,
elapsedTime: filters.elapsedTime.some(Boolean)
? {
from: filters.elapsedTime[0] ?? undefined,
to: filters.elapsedTime[1] ?? undefined,
}
: undefined,
period: filters.period.some(Boolean)
? {
from: filters.period[0]?.toISOString() ?? undefined,
to: filters.period[1]?.toISOString() ?? undefined,
}
: undefined,
elapsedTime: formatToRange(filters.elapsedTime, secondsToNanoseconds),
period: formatToRange(filters.period, (value) => value.toISOString()),
});

const Tasks: FC = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getOwnDatasets_user_datasets_data,
} from '@graphql/operations/queries/__generated__/getOwnDatasets';
import { GET_OWN_DATASETS } from '@graphql/operations/queries/getOwnDatasets';
import { formatToRange } from '@utils/formatToRange';
import {
DatasetsQueryFilters,
DatasetsQueryOrderingParameter,
Expand Down Expand Up @@ -39,17 +40,6 @@ const defaultOrdering: Ordering = {
direction: OrderDirection.DESC,
};

const formatToRange = <T, TResult>(
values: [T | undefined, T | undefined],
formatter: (value: T) => TResult,
) =>
values.some(Boolean)
? {
from: values[0] ? formatter(values[0]) : undefined,
to: values[1] ? formatter(values[1]) : undefined,
}
: undefined;

const filtersToApi = (filters: Filters): DatasetsQueryFilters => ({
...filters,
includeBuiltIn: false,
Expand Down
10 changes: 10 additions & 0 deletions web-app/client/src/utils/formatToRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const formatToRange = <T, TResult>(
values: [T | undefined, T | undefined],
formatter: (value: T) => TResult,
) =>
values.some(Boolean)
? {
from: values[0] ? formatter(values[0]) : undefined,
to: values[1] ? formatter(values[1]) : undefined,
}
: undefined;
61 changes: 34 additions & 27 deletions web-app/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,11 @@
resolved "https://registry.yarnpkg.com/@types/gtag.js/-/gtag.js-0.0.10.tgz#ac90d9b79c00daac447725a4b78ec1c398796760"
integrity sha512-98Hy7woUb3jMAMXkZQwfIOYNyfxmI0+U4m0PpCGdnd/FHk0tDpQFCqgXdNkdEoXsKkcGya/2Gew1cAJjKJspVw==

"@types/humanize-duration@^3.27.4":
version "3.27.4"
resolved "https://registry.yarnpkg.com/@types/humanize-duration/-/humanize-duration-3.27.4.tgz#51d6d278213374735440bc3749de920935e9127e"
integrity sha512-yaf7kan2Sq0goxpbcwTQ+8E9RP6HutFBPv74T/IA/ojcHKhuKVlk2YFYyHhWZeLvZPzzLE3aatuQB4h0iqyyUA==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
Expand Down Expand Up @@ -3215,18 +3220,6 @@ array.prototype.find@^2.1.1:
es-abstract "^1.20.4"
es-shim-unscopables "^1.0.0"

array.prototype.findlast@^1.2.4:
version "1.2.5"
resolved "https://registry.yarnpkg.com/array.prototype.findlast/-/array.prototype.findlast-1.2.5.tgz#3e4fbcb30a15a7f5bf64cf2faae22d139c2e4904"
integrity sha512-CVvd6FHg1Z3POpBLxO6E6zr+rSKEQ9L6rZHAaY7lLfhKsWYUBBOuMs0e9o24oopj6H+geRCX0YJ+TJLBK2eHyQ==
dependencies:
call-bind "^1.0.7"
define-properties "^1.2.1"
es-abstract "^1.23.2"
es-errors "^1.3.0"
es-object-atoms "^1.0.0"
es-shim-unscopables "^1.0.2"

array.prototype.findlastindex@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.3.tgz#b37598438f97b579166940814e2c0493a4f50207"
Expand Down Expand Up @@ -3258,7 +3251,7 @@ array.prototype.flat@^1.3.2:
es-abstract "^1.22.1"
es-shim-unscopables "^1.0.0"

array.prototype.flatmap@^1.3.2:
array.prototype.flatmap@^1.3.1, array.prototype.flatmap@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.3.2.tgz#c9a7c6831db8e719d6ce639190146c24bbd3e527"
integrity sha512-Ewyx0c9PmpcsByhSW4r+9zDU7sGjFc86qf/kKtuSCRdhfbk0SNLLkaT5qvcHnRGgc5NP/ly/y+qkXkqONX54CQ==
Expand All @@ -3279,17 +3272,7 @@ array.prototype.reduce@^1.0.5:
es-array-method-boxes-properly "^1.0.0"
is-string "^1.0.7"

array.prototype.toreversed@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/array.prototype.toreversed/-/array.prototype.toreversed-1.1.2.tgz#b989a6bf35c4c5051e1dc0325151bf8088954eba"
integrity sha512-wwDCoT4Ck4Cz7sLtgUmzR5UV3YF5mFHUlbChCzZBQZ+0m2cl/DH3tKgvphv1nKgFsJ48oCSg6p91q2Vm0I/ZMA==
dependencies:
call-bind "^1.0.2"
define-properties "^1.2.0"
es-abstract "^1.22.1"
es-shim-unscopables "^1.0.0"

array.prototype.tosorted@^1.1.3:
array.prototype.tosorted@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/array.prototype.tosorted/-/array.prototype.tosorted-1.1.3.tgz#c8c89348337e51b8a3c48a9227f9ce93ceedcba8"
integrity sha512-/DdH4TiTmOKzyQbp/eadcCVexiCb36xJg7HshYOYJnNZFDj33GEv0P7GxsynpShhq4OLYJzbGcBDkLsDt7MnNg==
Expand Down Expand Up @@ -6168,6 +6151,11 @@ human-signals@^4.3.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-4.3.1.tgz#ab7f811e851fca97ffbd2c1fe9a958964de321b2"
integrity sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==

humanize-duration@^3.32.0:
version "3.32.0"
resolved "https://registry.yarnpkg.com/humanize-duration/-/humanize-duration-3.32.0.tgz#b25f64ef55d723b049b197b6b4aa3c96c202b6c9"
integrity sha512-6WsXYTHJr7hXKqoqf5zoWza/lANRAqGlbnZnm0cjDykbXuez1JVXOQGmq0EPB45pXYAJyueRA3S3hfhmMbrMEQ==

hyperlinker@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hyperlinker/-/hyperlinker-1.0.0.tgz#23dc9e38a206b208ee49bc2d6c8ef47027df0c0e"
Expand Down Expand Up @@ -8002,6 +7990,15 @@ object.entries@^1.1.2:
define-properties "^1.1.4"
es-abstract "^1.20.4"

object.entries@^1.1.6:
version "1.1.8"
resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.8.tgz#bffe6f282e01f4d17807204a24f8edd823599c41"
integrity sha512-cmopxi8VwRIAw/fkijJohSfpef5PdN0pMQJN6VC/ZKvn0LIknWD8KtgY6KlQdEc4tIjcQ3HxSMmnvtzIscdaYQ==
dependencies:
call-bind "^1.0.7"
define-properties "^1.2.1"
es-object-atoms "^1.0.0"

object.entries@^1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.7.tgz#2b47760e2a2e3a752f39dd874655c61a7f03c131"
Expand All @@ -8011,6 +8008,16 @@ object.entries@^1.1.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"

object.fromentries@^2.0.6:
version "2.0.8"
resolved "https://registry.yarnpkg.com/object.fromentries/-/object.fromentries-2.0.8.tgz#f7195d8a9b97bd95cbc1999ea939ecd1a2b00c65"
integrity sha512-k6E21FzySsSK5a21KRADBd/NGneRegFO5pLHfdQLpRDETUNJueLXs3WCzyQ3tFRDYgbq3KHGXfTbi2bs8WQ6rQ==
dependencies:
call-bind "^1.0.7"
define-properties "^1.2.1"
es-abstract "^1.23.2"
es-object-atoms "^1.0.0"

object.fromentries@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/object.fromentries/-/object.fromentries-2.0.7.tgz#71e95f441e9a0ea6baf682ecaaf37fa2a8d7e616"
Expand Down Expand Up @@ -8041,7 +8048,7 @@ object.groupby@^1.0.1:
es-abstract "^1.22.1"
get-intrinsic "^1.2.1"

object.hasown@^1.1.3:
object.hasown@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/object.hasown/-/object.hasown-1.1.4.tgz#e270ae377e4c120cdcb7656ce66884a6218283dc"
integrity sha512-FZ9LZt9/RHzGySlBARE3VF+gE26TxR38SdmqOqliuTnl9wrKulaQs+4dee1V+Io8VfxqzAfHu6YuRgUy8OHoTg==
Expand Down Expand Up @@ -9042,7 +9049,7 @@ resolve@^1.22.4:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^2.0.0-next.5:
resolve@^2.0.0-next.4:
version "2.0.0-next.5"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-2.0.0-next.5.tgz#6b0ec3107e671e52b68cd068ef327173b90dc03c"
integrity sha512-U7WjGVG9sH8tvjW5SmGbQuui75FiyjAX72HX15DwBBwF9dNiQZRQAg9nnPhYy+TUnE0+VcrttuvNI8oSxZcocA==
Expand Down Expand Up @@ -9504,7 +9511,7 @@ string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string.prototype.matchall@^4.0.10:
string.prototype.matchall@^4.0.8:
version "4.0.11"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz#1092a72c59268d2abaad76582dccc687c0297e0a"
integrity sha512-NUdh0aDavY2og7IbBPenWqR9exH+E26Sv8e0/eTe1tltDGZL+GtBkDAnnyBtmekfK6/Dq3MkcGtzXFEd1LQrtg==
Expand Down
7 changes: 6 additions & 1 deletion web-app/server/src/graphql/schema/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ const typeDefs = gql`
to: Int
}
input FloatRange {
from: Float
to: Float
}
input DatasetsQueryFilters {
searchString: String
includeBuiltIn: Boolean! = true
Expand Down Expand Up @@ -704,7 +709,7 @@ const typeDefs = gql`
input TasksQueryFilters {
searchString: String
includeDeleted: Boolean
elapsedTime: IntRange
elapsedTime: FloatRange
period: StringRange
}
Expand Down

0 comments on commit fc3215b

Please sign in to comment.