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

Fix condition to determine if the date field's value is an array #299

Merged
merged 9 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@types/set-interval-async": "^1.0.0",
"@types/showdown": "^1.9.3",
"babel-jest": "^27.5.1",
"cypress": "^13.6.0",
"elastic-builder": "^2.7.1",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-no-unsanitized": "^3.0.2",
Expand Down
8 changes: 4 additions & 4 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
import converter from 'json-2-csv';
import _ from 'lodash';
import moment from 'moment-timezone';
import { DATA_REPORT_CONFIG } from './constants';

Check failure on line 10 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

'DATA_REPORT_CONFIG' is defined but never used. Allowed unused vars must match /^_/u
import {
buildOpenSearchQuery,
Filter,
Query,
OpenSearchQueryConfig,
} from '../../../../../src/plugins/data/common';
import { string } from 'joi';

Check failure on line 17 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

`joi` import should occur before import of `./constants`

Check failure on line 17 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

'string' is defined but never used. Allowed unused vars must match /^_/u

export var metaData = {

Check failure on line 19 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected var, use let or const instead
saved_search_id: <string>null,

Check failure on line 20 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
report_format: <string>null,

Check failure on line 21 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
start: <string>null,

Check failure on line 22 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
end: <string>null,

Check failure on line 23 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
fields: <string>null,

Check failure on line 24 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
type: <string>null,

Check failure on line 25 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Use 'as string' instead of '<string>'
timeFieldName: <string>null,
sorting: <string>null,
fields_exist: <boolean>false,
selectedFields: <any>[],

Check warning on line 29 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
paternName: <string>null,
searchSourceJSON: <any>[],

Check warning on line 31 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
dateFields: <any>[],

Check warning on line 32 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
};

// Get the selected columns by the user.
Expand All @@ -52,7 +52,7 @@
// 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 buildRequestBody = (
report: any,

Check warning on line 55 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
allowLeadingWildcards: boolean,
is_count: number
) => {
Expand Down Expand Up @@ -119,13 +119,13 @@

// Fetch the data from OpenSearch
export const getOpenSearchData = (
arrayHits: any,

Check warning on line 122 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
report: { _source: any },

Check warning on line 123 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
params: { excel: any; limit: number },

Check warning on line 124 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
dateFormat: string,
timezone: string
) => {
let hits: any = [];

Check warning on line 128 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
for (let valueRes of arrayHits) {
for (let data of valueRes.hits) {
const fields = data.fields;
Expand All @@ -145,8 +145,8 @@
if (typeof dateValue === 'string') {
data._source[keys] = moment.utc(dateValue).tz(timezone).format(dateFormat);
} else if (
fieldDateValue.length !== 0 &&
fieldDateValue instanceof Array
dateValue.length !== 0 &&
dateValue instanceof Array
) {
fieldDateValue.forEach((element, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my knowledge, why whats the difference between fieldDateValue and dateValue above. Cuz I saw the change was trying to switch to dateValue .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally the variable was dateValue for this condition but was mistakenly changed in different PR which caused TypeError: Cannot create property '0' on number '1700813322772'. Reverting to fix the issue.

data._source[keys][index] = moment.utc(element).tz(timezone).format(dateFormat);
Expand All @@ -161,8 +161,8 @@
if (typeof fieldDateValue === 'string') {
keys.push(moment.utc(fieldDateValue).tz(timezone).format(dateFormat));
} else if (
fieldDateValue.length !== 0 &&
fieldDateValue instanceof Array
dateValue.length !== 0 &&
dateValue instanceof Array
) {
let tempArray: string[] = [];
fieldDateValue.forEach((index) => {
Expand Down Expand Up @@ -205,7 +205,7 @@

//Convert the data to Csv format
export const convertToCSV = async (dataset, csvSeparator) => {
let convertedData: any = [];

Check warning on line 208 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const options = {
delimiter: { field: csvSeparator, eol: '\n' },
emptyFieldValue: ' ',
Expand Down Expand Up @@ -254,7 +254,7 @@
* This is intend to avoid CSV injection in Microsoft Excel.
* @param doc document
*/
function sanitize(doc: any) {

Check warning on line 257 in server/routes/utils/dataReportHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
for (const field in doc) {
if (doc[field] == null) continue;
if (
Expand Down
Loading
Loading