Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

chore(legacy-preset-chart-nvd3): move bullet chart option parsing from backend to frontend #440

Merged

Conversation

villebro
Copy link
Contributor

@villebro villebro commented May 4, 2020

🏠 Internal

This moves BulletViz range and marker parsing logic from the backend to the frontend. Once this PR is merged the relevant logic will be removed from viz.py: https://github.com/apache/incubator-superset/blob/5d167afb9499d7ce30c7ea763b19993af347dc23/superset/viz.py#L1094-L1124

Moving this will be necessary to deprecate viz.py, as non-datasource related data processing will not be supported in the new chart data API.

SCREENSHOTS

image
image

FYI @suddjian @rusackas

@villebro villebro requested a review from a team as a code owner May 4, 2020 08:09
@vercel
Copy link

vercel bot commented May 4, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/oqnr50ybv
✅ Preview: https://superset-ui-git-fork-preset-io-villebro-bullet-annotations.superset.now.sh

@codecov
Copy link

codecov bot commented May 4, 2020

Codecov Report

Merging #440 into master will increase coverage by 0.03%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #440      +/-   ##
==========================================
+ Coverage   22.20%   22.23%   +0.03%     
==========================================
  Files         264      265       +1     
  Lines        6500     6520      +20     
  Branches      588      590       +2     
==========================================
+ Hits         1443     1450       +7     
- Misses       5020     5033      +13     
  Partials       37       37              
Impacted Files Coverage Δ
plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js 0.00% <0.00%> (ø)
...ins/legacy-preset-chart-nvd3/src/transformProps.js 0.00% <0.00%> (ø)
...ins/legacy-preset-chart-nvd3/src/utils/isTruthy.js 100.00% <ø> (ø)
...ins/legacy-preset-chart-nvd3/src/utils/tokenize.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86847d1...ebf4746. Read the comment docs.

@pull-request-size pull-request-size bot removed the size/M label May 4, 2020
@vercel vercel bot temporarily deployed to Preview May 4, 2020 10:43 Inactive
*/
import { validateNumber } from '@superset-ui/validator';

const tokenizeToNumericArray = value => {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Perhaps a classic function and inline export is more readable here.
  • (optional) This file can also be written in typescript
export function tokenizeToNumericArray(value) {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do 👍

import { validateNumber } from '@superset-ui/validator';

const tokenizeToNumericArray = value => {
if (value && value.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

value.trim() returns a new string and does not mutate value

if (value) {
  const tokens = value.trim().split(',').map(v => v.trim());
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thought in the if-statement was merely to check that value is defined and isn't only whitespace. Could probably have been written more elegantly, will try to refactor more sensibly.

Copy link
Member

Choose a reason for hiding this comment

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

I noticed that too, but the code doesn't actually depend on the value being trimmed. The trim() is just being used to check that it contains characters other than spaces, so I think this is fine.

};

const tokenizeToStringArray = value => {
if (value && value.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

value.trim() does not mutate value

return value 
  ? value.trim().split(',').map(token => token.trim());
  : null;

return null;
};

const tokenizeToStringArray = value => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can use inline export like above

Copy link
Member

@suddjian suddjian 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
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM

it('evals numeric strings properly', () => {
expect(tokenizeToNumericArray('1')).toStrictEqual([1]);
expect(tokenizeToNumericArray('1,2,3,4')).toStrictEqual([1, 2, 3, 4]);
expect(tokenizeToNumericArray(' 1, 2, 3, 4 ')).toStrictEqual([1, 2, 3, 4]);
Copy link
Member

Choose a reason for hiding this comment

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

Could throw some decimal values in here, if you wanna make sure people don't randomly turn parseFloat int parseInt or something silly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point 👍

@villebro villebro changed the title chore: move bullet chart option parsing from backend to frontend chore(legacy-preset-chart-nvd3): move bullet chart option parsing from backend to frontend May 5, 2020
@villebro
Copy link
Contributor Author

villebro commented May 5, 2020

@kristw I think this is ready for another round of review.

@rusackas rusackas merged commit 2a5e0a9 into apache-superset:master May 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants