-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Widen parameter type for easier use with different collections. * Using methods for bulk retrieval to reduce db roundtrips. * Extracting helper function for parsing timestamp filters. * Improving typing. * Removing leading underscore from variables. * Adding license header.
- Loading branch information
1 parent
a4c1634
commit fad12cc
Showing
5 changed files
with
69 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
graylog2-web-interface/src/components/common/PaginatedEntityTable/parseTimerangeFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import moment from 'moment'; | ||
import trim from 'lodash/trim'; | ||
|
||
import { extractRangeFromString } from 'components/common/EntityFilters/helpers/timeRange'; | ||
import { adjustFormat } from 'util/DateTime'; | ||
import type { TimeRange, RelativeTimeRange } from 'views/logic/queries/Query'; | ||
|
||
const allTimesRange: RelativeTimeRange = { type: 'relative', range: 0 }; | ||
|
||
const isNullOrBlank = (s: string | undefined) => { | ||
if (!s) { | ||
return true; | ||
} | ||
|
||
return trim(s) === ''; | ||
}; | ||
|
||
const parseTimerangeFilter = (timestamp: string | undefined): TimeRange => { | ||
if (!timestamp) { | ||
return allTimesRange; | ||
} | ||
|
||
const [from, to] = extractRangeFromString(timestamp); | ||
|
||
if (!from && !to) { | ||
return allTimesRange; | ||
} | ||
|
||
return { | ||
type: 'absolute', | ||
from: isNullOrBlank(from) ? adjustFormat(moment(0).utc(), 'internal') : from, | ||
to: isNullOrBlank(to) ? adjustFormat(moment().utc(), 'internal') : to, | ||
}; | ||
}; | ||
|
||
export default parseTimerangeFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters