-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Conversation
There was a problem hiding this 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; | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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),
);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
122076f
to
86ee56c
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
2 similar comments
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Comments addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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. |
I forgot to remove .only from one of the tests. I have fix for that in the deprecate getcolorfromscheme PR
Best regards,
Krist
…--
Krist Wongsuphasawat
http://kristw.yellowpigz.com
On Sep 20, 2018, 08:27 -0700, Maxime Beauchemin ***@***.***>, wrote:
@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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I can create the fix as a separate PR too. Apologize for the issue.
Best regards,
Krist
…--
Krist Wongsuphasawat
http://kristw.yellowpigz.com
On Sep 20, 2018, 08:27 -0700, Maxime Beauchemin ***@***.***>, wrote:
@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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
…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
This PR add utility functions
reactify
andcreateAdaptor
which are necessary for directory structure described in SIP-6 (#5692 )Also demonstrate usage with
WorldMap
@conglei @williaster