Skip to content

Commit

Permalink
Support range filters for csv reports (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuali925 authored and zhongnansu committed Nov 9, 2021
1 parent 2b74a73 commit b9de9e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 1 addition & 2 deletions dashboards-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 @@ -141,11 +141,11 @@ export const replaceQueryURL = (pageUrl) => {
let queryUrl = unhashedUrl.pathname + unhashedUrl.hash;
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 dashboards-reports/server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,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 @@ -92,6 +91,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 Down Expand Up @@ -119,6 +126,14 @@ export const buildQuery = (report, is_count) => {
negatedBody.minimumShouldMatch(1);
requestBody.mustNot(negatedBody);
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 dashboards-reports/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6142,11 +6142,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 b9de9e7

Please sign in to comment.