Skip to content

Commit

Permalink
Support range filters for csv reports (opensearch-project#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuali925 authored and zhongnansu committed Oct 28, 2021
1 parent b43aeaa commit 8c0fe2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 1 addition & 2 deletions kibana-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions kibana-reports/server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <string>null,
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down
5 changes: 0 additions & 5 deletions kibana-reports/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8c0fe2f

Please sign in to comment.