From 8c0fe2f0b31d829464d27e6cde1965fd70ce795c Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 22 Oct 2021 13:23:10 -0700 Subject: [PATCH] Support range filters for csv reports (#185) --- kibana-reports/package.json | 3 +-- .../context_menu/context_menu_helpers.js | 8 +++++-- .../server/routes/utils/dataReportHelpers.ts | 21 ++++++++++++++++--- kibana-reports/yarn.lock | 5 ----- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/kibana-reports/package.json b/kibana-reports/package.json index b3f3e7d7..12a1adaf 100644 --- a/kibana-reports/package.json +++ b/kibana-reports/package.json @@ -66,8 +66,7 @@ "identity-obj-proxy": "^3.0.0", "jest-dom": "^4.0.0", "react-test-renderer": "^16.12.0", - "ts-jest": "^26.1.0", - "tsc": "^1.20150623.0" + "ts-jest": "^26.1.0" }, "resolutions": { "trim": "^1.0.0", diff --git a/kibana-reports/public/components/context_menu/context_menu_helpers.js b/kibana-reports/public/components/context_menu/context_menu_helpers.js index 0062f86b..938e7dd0 100644 --- a/kibana-reports/public/components/context_menu/context_menu_helpers.js +++ b/kibana-reports/public/components/context_menu/context_menu_helpers.js @@ -129,11 +129,15 @@ export const replaceQueryURL = (pageUrl) => { let [, fromDateStringMatch, toDateStringMatch] = queryUrl.match( timeRangeMatcher ); - fromDateString = decodeURIComponent(fromDateStringMatch.replace(/[']+/g, '')); + const fromDateString = decodeURIComponent( + fromDateStringMatch.replace(/[']+/g, '') + ); // convert time range to from date format in case time range is relative const fromDateFormat = dateMath.parse(fromDateString); - toDateString = decodeURIComponent(toDateStringMatch.replace(/[']+/g, '')); + const toDateString = decodeURIComponent( + toDateStringMatch.replace(/[']+/g, '') + ); const toDateFormat = dateMath.parse(toDateString, { roundUp: true }); // replace to and from dates with absolute date diff --git a/kibana-reports/server/routes/utils/dataReportHelpers.ts b/kibana-reports/server/routes/utils/dataReportHelpers.ts index e585c20c..5e3c227a 100644 --- a/kibana-reports/server/routes/utils/dataReportHelpers.ts +++ b/kibana-reports/server/routes/utils/dataReportHelpers.ts @@ -13,12 +13,11 @@ * permissions and limitations under the License. */ -import { DATA_REPORT_CONFIG } from './constants'; - import esb, { Sort } from 'elastic-builder'; -import moment from 'moment'; import converter from 'json-2-csv'; import _ from 'lodash'; +import moment from 'moment'; +import { DATA_REPORT_CONFIG } from './constants'; export var metaData = { saved_search_id: null, @@ -81,6 +80,14 @@ export const buildQuery = (report, is_count) => { } requestBody.minimumShouldMatch(1); break; + case 'range': + const builder = esb.rangeQuery(item.meta.key); + if (item.meta.params.gte) builder.gte(item.meta.params.gte); + if (item.meta.params.lte) builder.lte(item.meta.params.lte); + if (item.meta.params.gt) builder.gt(item.meta.params.gt); + if (item.meta.params.lt) builder.lt(item.meta.params.lt); + requestBody.must(builder); + break; } break; case true: @@ -106,6 +113,14 @@ export const buildQuery = (report, is_count) => { } requestBody.minimumShouldMatch(1); break; + case 'range': + const builder = esb.rangeQuery(item.meta.key); + if (item.meta.params.gte) builder.gte(item.meta.params.gte); + if (item.meta.params.lte) builder.lte(item.meta.params.lte); + if (item.meta.params.gt) builder.gt(item.meta.params.gt); + if (item.meta.params.lt) builder.lt(item.meta.params.lt); + requestBody.mustNot(builder); + break; } break; } diff --git a/kibana-reports/yarn.lock b/kibana-reports/yarn.lock index eed39831..83bd7b85 100644 --- a/kibana-reports/yarn.lock +++ b/kibana-reports/yarn.lock @@ -6115,11 +6115,6 @@ ts-jest@^26.1.0: semver "7.x" yargs-parser "18.x" -tsc@^1.20150623.0: - version "1.20150623.0" - resolved "https://registry.yarnpkg.com/tsc/-/tsc-1.20150623.0.tgz#4ebc3c774e169148cbc768a7342533f082c7a6e5" - integrity sha1-Trw8d04WkUjLx2inNCUz8ILHpuU= - tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"