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

E2e/feature/ri 6231 spike] fix the rounding issue for json data type #4089

Conversation

KIvanow
Copy link
Collaborator

@KIvanow KIvanow commented Nov 14, 2024

Tested it with bigints as numbers, bigints as strings both as the only element in the json and the same two options as part of arrays and objects.

In the added changes testes were performed with very large jsons that trigger partial retrievals of the information (kudos to @romansergeenkosofteq for pointing the different case there). For both cases we are not parsing the data on the BE before sending it back to the UI (to avoid the bigint issues). All of the parsing is done afterwards in the client. Separated the parsing function into 2 different ones
1 - parsing when the data is simple and whole (we've retrieved the entire json and simply need to parse it)
2 - parsing the partially retrieved data. In that case the data is not just a string or a JSON valid object but looks more like this:
"data": [ { "key": "_id", "path": "[0][\"_id\"]", "cardinality": 1, "type": "string", "value": "\"6735edc1021e565aca45f9fe\"" }, { "key": "index", "path": "[0][\"index\"]", "cardinality": 1, "type": "integer", "value": "1188950299261208942" },
So separating the two seemed appropriate.

Tests were added for both parsing cases.

Copy link
Contributor

@rsergeenko rsergeenko left a comment

Choose a reason for hiding this comment

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

could you please add tests
also, could you please test the case when we get not the whole JSON (when it is big)

@KIvanow
Copy link
Collaborator Author

KIvanow commented Nov 14, 2024

could you please add tests also, could you please test the case when we get not the whole JSON (when it is big)

@romansergeenkosofteq do we have a big json anywhere is test files or docs that we can use for the second thing?

Copy link
Contributor

@rsergeenko rsergeenko left a comment

Choose a reason for hiding this comment

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

  1. I am not sure that it is a good solution to parse JSON in the slice, I would recommend set in the store what we receive from BE. The responsibility how to work with that data should be on component layer.
  2. Please, use our linter (we don't use semicolons) and add empty line at the end of the files

@KIvanow
Copy link
Collaborator Author

KIvanow commented Nov 15, 2024

  1. I am not sure that it is a good solution to parse JSON in the slice, I would recommend set in the store what we receive from BE. The responsibility how to work with that data should be on component layer.

Updated the approach to not parse the jsons in the slice, but in a component directly. Added it in a util in case
we need it in multiple other places down the line.

  1. Please, use our linter (we don't use semicolons) and add empty line at the end of the files
    Thank you for the tip!

@ArtemHoruzhenko I've also updated the BE tests to check the new structure. Surprisingly the DTO didn't require changes

@KIvanow KIvanow requested a review from rsergeenko November 15, 2024 15:40
Copy link
Collaborator

@ArtemHoruzhenko ArtemHoruzhenko left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@rsergeenko rsergeenko left a comment

Choose a reason for hiding this comment

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

@KIvanow there are some ESLint errors in the utils.ts (@typescript-eslint/indent, no-trailing-spaces, arrow-parens, no-param-reassign, import/order). Please use our eslint settings for IDE.

@KIvanow
Copy link
Collaborator Author

KIvanow commented Nov 19, 2024

Testing is done :)

@KIvanow KIvanow self-assigned this Nov 19, 2024
setChangedValue('null')
} else {
setChangedValue(value)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add stringify function which will return value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean like so -> 238acd9 having a function wrapping up this functionality, instead of doing it directly in the useEffect, or something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but could you please move it to utils and call smth like stringifyScalarValue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, covered it with tests as well 2d08a99

I usually wait until something needs the function from a different component,before separating it in a util, but I can see the benefit of the other approach as well

data: parseJsonData(data?.data)
}))
.catch(reject)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest parse json in the fetchVisualisationResults

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was initially there, but you suggested it to be on the component level, since fetchVisualisationResults is in the slice itself and the slices should simply store the data from the server in a previous comment #4089 (review)

Do you mean going back to the initial implementation or something else?

Copy link
Contributor

@rsergeenko rsergeenko Nov 20, 2024

Choose a reason for hiding this comment

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

fetchVisualisationResults do not store results. It's ok to transform result of BE and return prepared data. I think it will be better then wrap this function in the Promise. Or another way - get stringified data from this function and parse this data after call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see what you mean. Updated it.

purposfully not using json-bigin library as it fails with scientific notations and probably other edge cases
        seemed like a simple enough use case to implement directly
Copy link
Contributor

@rsergeenko rsergeenko left a comment

Choose a reason for hiding this comment

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

please, do lint changed FE files, there are some lint errors

@KIvanow
Copy link
Collaborator Author

KIvanow commented Nov 20, 2024

please, do lint changed FE files, there are some lint errors

@romansergeenkosofteq done and added the linter to be triggered on save for all of my devices. Sorry for the recurring issue

@mariasergeenko mariasergeenko merged commit 8483ef3 into main Nov 21, 2024
8 of 9 checks passed
@mariasergeenko mariasergeenko deleted the e2e/feature/RI-6231-SPIKE]-Fix-the-rounding-issue-for-JSON-data-type branch November 21, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants