Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support sorting for csv report based on saved search #86

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions dashboards-reports/server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import { DATA_REPORT_CONFIG } from './constants';

import esb from 'elastic-builder';
import esb, { Sort } from 'elastic-builder';
import moment from 'moment';
import converter from 'json-2-csv';
import _ from 'lodash';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const getSelectedFields = async (columns) => {
metaData.selectedFields = selectedFields;
};

//Build the OpenSearch query from the meta data
// Build the OpenSearch query from the meta data
// is_count is set to 1 if we building the count query but 0 if we building the fetch data query
export const buildQuery = (report, is_count) => {
let requestBody = esb.boolQuery();
Expand Down Expand Up @@ -149,14 +149,10 @@ export const buildQuery = (report, is_count) => {
let reqBody = esb.requestBodySearch().query(requestBody).version(true);

if (report._source.sorting.length > 0) {
if (report._source.sorting.length === 1)
reqBody.sort(
esb.sort(report._source.sorting[0][0], report._source.sorting[0][1])
);
else
reqBody.sort(
esb.sort(report._source.sorting[0], report._source.sorting[1])
);
const sortings: Sort[] = report._source.sorting.map((element: string[]) => {
return esb.sort(element[0], element[1]);
});
reqBody.sorts(sortings);
}

//get the selected fields only
Expand Down Expand Up @@ -249,11 +245,11 @@ function traverse(data, keys, result = {}) {
*/
function sanitize(doc: any) {
for (const field in doc) {
if (doc[field] == null)
continue
if (doc[field] == null) continue;
if (
doc[field].toString().startsWith('+') ||
(doc[field].toString().startsWith('-') && typeof doc[field] !== "number") ||
(doc[field].toString().startsWith('-') &&
typeof doc[field] !== 'number') ||
doc[field].toString().startsWith('=') ||
doc[field].toString().startsWith('@')
) {
Expand Down