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

[SIP-6] Add reactify function and convert world map to new directory structure. #5893

Merged
merged 12 commits into from
Sep 19, 2018

Conversation

kristw
Copy link
Contributor

@kristw kristw commented Sep 14, 2018

This PR add utility functions reactify and createAdaptor which are necessary for directory structure described in SIP-6 (#5692 )

Also demonstrate usage with WorldMap

@conglei @williaster

Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

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

Looks good overall, I had a couple comments/questions.

}
if (renderFn.defaultProps) {
ReactifiedComponent.defaultProps = renderFn.defaultProps;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

could we also check for + add displayName?

if (renderFn.displayName) {
  ReactifiedComponent.displayName = renderFn.displayName;
}

import reactify from '../../utils/reactify';
import WorldMap from './WorldMap';

export default reactify(WorldMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about just using WorldMap.jsx instead to denote react components instead of including React in the name?

My main thought is that this might make naming more consistent with visualizations that are React already (so wouldn't specify ReactMyVisComponent.jsx and instead would probably just be MyVisComponent.jsx), but would then require specifying a .jsx in the adaptor file (I'm personally okay with that for those that require it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am afraid I will make mistake when importing. If I specify ./WorldMap, which one will webpack resolve to first?

Copy link
Contributor

Choose a reason for hiding this comment

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

that's fair, I guess in a world where most visualizations are not react and will have react adapters, this is okay 👍

What do you think about them being ReactWorldMap.jsx vs *.js? I guess really there's no jsx in the file, so .js is probably the right call technically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good point. I can definitely rename it to .js


export default class BasicChartInput {
constructor(slice, payload, setControlValue) {
this.width = slice.width();
Copy link
Contributor

Choose a reason for hiding this comment

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

does this model support dynamic sizing easily? I think it'd be really nice to move away from width and height being functions on the slice object because it forces child to call them, or some component somewhere to add window resize listeners to then force the child to re-render (which differs depending on dashboard vs explorer, etc.), instead of auto-updating and cascading as props would.

With the new adaptor model I think we're pretty well poised to leverage the resize observer from vx's ParentSize component:

// createAdaptor.jsx

ReactDOM.render(
  <ParentSize>
    {({ width, height }) => (
      <Component 
        width={width} 
        height={height} 
        {...transformProps(basicChartInput)} 
      />,
    )}
  </ParentSize>,
  document.querySelector(slice.selector),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks interesting. I will give this a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't work with the explore page yet due to the parent <div> from bootstrap panel does not know its height so when ParentSize tries to get height 100%, it ends up getting the entire screen height. I don't feel like changing the explore page div style in this PR, so I will pass the width and height from slice as separated argument from basicChartInput instead and remove this once I work on the Chart.jsx.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for exploring (😉) it, sg 👍

@@ -0,0 +1,11 @@
import { mapKeys, camelCase, isPlainObject } from 'lodash/fp';

export default function convertKeysToCamelCase(object) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lovely!

@@ -0,0 +1,5 @@
import createAdaptor from '../../utils/createAdaptor';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking how to make each visualization as self contained (independent with superset code) as possible. But it seems now it is hard to do so, otherwise there will be duplicated codes like this for each visualizations type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remember this file is temporary and will be removed when we move to entirely plugin system.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think including it in @superset-ui/charts as a util function for the time being is okay.

@@ -0,0 +1,11 @@
export default function transformProps(basicChartInput) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we could do some propType check on formData.

Copy link
Contributor

Choose a reason for hiding this comment

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

that's an interesting idea. I think that doing that in another PR could be okay tho, it would probably be a decent amount of work to enumerate all of the options there. it's basically defining the formData interface / would be a precursor to the type script interface.

Copy link
Contributor Author

@kristw kristw Sep 17, 2018

Choose a reason for hiding this comment

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

It could be part of the BasicChartInput or extended class.

For example, class PieChartInput extends BasicChartInput then in the constructor you parse formData with new PieChartFormData(formData).

Maybe we should use TypeScript after all lol.

@@ -108,7 +108,7 @@ const vizMap = {
[VIZ_TYPES.word_cloud]: () =>
loadVis(import(/* webpackChunkName: "word_cloud" */ './wordcloud/WordCloud.js')),
[VIZ_TYPES.world_map]: () =>
loadVis(import(/* webpackChunkName: "world_map" */ './world_map.js')),
loadVis(import(/* webpackChunkName: "world_map" */ './WorldMap/adaptor.jsx')),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add index.js for each file and export adaptor there as default. Potentially we also want to just import the chart itself in the plugin system world.

Copy link
Contributor

Choose a reason for hiding this comment

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

index.js file per vis folder could be a good idea +1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This visualizations/index.js file and adaptor.jsx will be removed soon so I prefer not to create index.js to be another file waiting for deletion.

@codecov-io
Copy link

Codecov Report

Merging #5893 into master will decrease coverage by 15.6%.
The diff coverage is 11.29%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #5893       +/-   ##
===========================================
- Coverage   63.66%   48.06%   -15.61%     
===========================================
  Files         386      393        +7     
  Lines       23538    23687      +149     
  Branches     2628     2669       +41     
===========================================
- Hits        14986    11385     -3601     
- Misses       8539    12301     +3762     
+ Partials       13        1       -12
Impacted Files Coverage Δ
superset/assets/src/utils/createAdaptor.jsx 0% <0%> (ø)
superset/assets/src/utils/reactify.jsx 0% <0%> (ø)
...ssets/src/visualizations/WorldMap/ReactWorldMap.js 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/adaptor.jsx 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/WorldMap.js 0% <0%> (ø)
...sets/src/visualizations/WorldMap/transformProps.js 0% <0%> (ø)
...ssets/src/visualizations/models/BasicChartInput.js 0% <0%> (ø)
...uperset/assets/src/utils/convertKeysToCamelCase.js 100% <100%> (ø)
...perset/assets/src/visualizations/nvd3/PropTypes.js 0% <0%> (-100%) ⬇️
.../dashboard/util/charts/getEffectiveExtraFilters.js 5.55% <0%> (-94.45%) ⬇️
... and 206 more

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 19a3319...86ee56c. Read the comment docs.

2 similar comments
@codecov-io
Copy link

Codecov Report

Merging #5893 into master will decrease coverage by 15.6%.
The diff coverage is 11.29%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #5893       +/-   ##
===========================================
- Coverage   63.66%   48.06%   -15.61%     
===========================================
  Files         386      393        +7     
  Lines       23538    23687      +149     
  Branches     2628     2669       +41     
===========================================
- Hits        14986    11385     -3601     
- Misses       8539    12301     +3762     
+ Partials       13        1       -12
Impacted Files Coverage Δ
superset/assets/src/utils/createAdaptor.jsx 0% <0%> (ø)
superset/assets/src/utils/reactify.jsx 0% <0%> (ø)
...ssets/src/visualizations/WorldMap/ReactWorldMap.js 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/adaptor.jsx 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/WorldMap.js 0% <0%> (ø)
...sets/src/visualizations/WorldMap/transformProps.js 0% <0%> (ø)
...ssets/src/visualizations/models/BasicChartInput.js 0% <0%> (ø)
...uperset/assets/src/utils/convertKeysToCamelCase.js 100% <100%> (ø)
...perset/assets/src/visualizations/nvd3/PropTypes.js 0% <0%> (-100%) ⬇️
.../dashboard/util/charts/getEffectiveExtraFilters.js 5.55% <0%> (-94.45%) ⬇️
... and 206 more

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 19a3319...86ee56c. Read the comment docs.

@codecov-io
Copy link

Codecov Report

Merging #5893 into master will decrease coverage by 15.6%.
The diff coverage is 11.29%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #5893       +/-   ##
===========================================
- Coverage   63.66%   48.06%   -15.61%     
===========================================
  Files         386      393        +7     
  Lines       23538    23687      +149     
  Branches     2628     2669       +41     
===========================================
- Hits        14986    11385     -3601     
- Misses       8539    12301     +3762     
+ Partials       13        1       -12
Impacted Files Coverage Δ
superset/assets/src/utils/createAdaptor.jsx 0% <0%> (ø)
superset/assets/src/utils/reactify.jsx 0% <0%> (ø)
...ssets/src/visualizations/WorldMap/ReactWorldMap.js 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/adaptor.jsx 0% <0%> (ø)
...set/assets/src/visualizations/WorldMap/WorldMap.js 0% <0%> (ø)
...sets/src/visualizations/WorldMap/transformProps.js 0% <0%> (ø)
...ssets/src/visualizations/models/BasicChartInput.js 0% <0%> (ø)
...uperset/assets/src/utils/convertKeysToCamelCase.js 100% <100%> (ø)
...perset/assets/src/visualizations/nvd3/PropTypes.js 0% <0%> (-100%) ⬇️
.../dashboard/util/charts/getEffectiveExtraFilters.js 5.55% <0%> (-94.45%) ⬇️
... and 206 more

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 19a3319...86ee56c. Read the comment docs.

@kristw
Copy link
Contributor Author

kristw commented Sep 18, 2018

Comments addressed.

Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

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

LGTM

@williaster williaster merged commit 8fff0d9 into apache:master Sep 19, 2018
@kristw kristw deleted the kristw-reactify branch September 19, 2018 15:45
@mistercrunch
Copy link
Member

mistercrunch commented Sep 20, 2018

@kristw @williaster I'm not quite sure why, but since this PR it looks like we've been running only a handful of javascript tests.

codecov-io is often out of whack, but it looks like it was in tune here detecting this.

@kristw
Copy link
Contributor Author

kristw commented Sep 20, 2018 via email

@kristw
Copy link
Contributor Author

kristw commented Sep 20, 2018 via email

betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
…structure. (apache#5893)

* reactify world map

* add createAdaptor

* fix typo

* add schema

* move directory

* remove unnecessary lines

* make setRef a function

* convert keys to camelcase

* add unit test

* update formatting

* add check for displayName

* pass width and height as separate inputs
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants