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

feat(control-utils): add infotooltipwithtrigger #442

Conversation

pkdotson
Copy link
Contributor

@pkdotson pkdotson commented May 5, 2020

🏆 Enhancements

Adding infotooltipwithtrigger to superset ui. This is required for migrating partition chart control panels.

@pkdotson pkdotson requested a review from a team as a code owner May 5, 2020 23:57
@vercel
Copy link

vercel bot commented May 5, 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/73baqpif1
✅ Preview: https://superset-ui-git-fork-preset-io-phillip-so-264-partiti-6351f5.superset.now.sh

@pkdotson pkdotson changed the title PR to merge packges for controls migration chore: PR to merge packges for controls migration May 5, 2020
@codecov
Copy link

codecov bot commented May 6, 2020

Codecov Report

Merging #442 into master will increase coverage by 0.12%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #442      +/-   ##
=========================================
+ Coverage    3.08%   3.20%   +0.12%     
=========================================
  Files         151     152       +1     
  Lines        5218    5238      +20     
  Branches      273     275       +2     
=========================================
+ Hits          161     168       +7     
- Misses       5020    5033      +13     
  Partials       37      37              
Impacted Files Coverage Δ
plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js 0.00% <0.00%> (ø)
plugins/legacy-plugin-chart-sunburst/src/index.js 0.00% <0.00%> (ø)
plugins/legacy-plugin-chart-world-map/src/index.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% <0.00%> (ø)
...ins/legacy-preset-chart-nvd3/src/utils/tokenize.ts 100.00% <0.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...1c4be62. Read the comment docs.

Copy link
Contributor

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. Added a couple of comments on style nits.

I'm not sure we want to put this under control-utils, though, as this seems to be a fairly generic component that is used in more than chart controls.

I feel we kind of need a generic UI library + an arsenal of library-agnostic chart controls to better prepare for future migration.

"dependencies": {
"lodash": "^4.17.15",
"react": "^16.13.1",
"react-bootstrap": "^1.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Re: dependencies

  1. These should be peerDependencies, as they are shared by multiple superset-ui packages and should be upgraded all at once.
  2. We are not using react-bootstrap@1 yet. It's for Bootstrap v4, but we are still stuck with Boostrap v3. Check incubator-superset for property versions for react-bootstrap and @types/react-bootstrap.
  3. Can we get rid of lodash? Is kebabCase absolutely necessary? Could you investigate why do we needed an ID for the tooltip in the first place? It's the best if we could just remove it. Less dependencies the better.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding 3, I think that kind of effort is better left until after we've moved things from superset. This should be as clean a refactor as possible, just moving code into superset-ui.

Copy link
Contributor

@kristw kristw May 6, 2020

Choose a reason for hiding this comment

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

react in particular should always be peerDependencies in any library. There should always be one react.

react-bootstrap can be left in dependencies

Copy link
Member

Choose a reason for hiding this comment

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

I also don't agree with making these peer dependencies, because the code directly depends on them. Peer dependencies aren't meant to be used for optimization, npm does that automatically when version numbers of dependencies are compatible with each other.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with making them dependencies as-is except react

Copy link
Contributor

@ktmud ktmud May 6, 2020

Choose a reason for hiding this comment

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

True, npm might be able to remove duplicates, but I think there is also the implication of what if it is not compatible? Are we really OK with having multiple versions of the dependent libraries in our app?

These superset-ui packages cannot work outside of Superset or Superset UI demos, so they should not introduce their own large non-optional dependencies. Using peerDependencies kind of forces package maintainers and library users to keep the dependencies up to date.

Copy link
Contributor

@kristw kristw May 6, 2020

Choose a reason for hiding this comment

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

True, npm might be able to remove duplicates, but I think there is also the implication of what if it is not compatible? Are we really OK with having multiple versions of the dependent libraries in our app?

I think that is how all packages work tho. I am ok having multiple versions of the dependent instead of worrying about breaking anything if bump version of one dependencies.

These superset-ui packages cannot work outside of Superset or Superset UI demos, so they should not introduce their own large non-optional dependencies. Using peerDependencies kind of forces package maintainers to keep the dependencies up to date.

This is actually not entirely correct. These packages can work outside of Superset and Superset UI demos. They are independent packages on their own (number format, time format, color, etc.) which do not need Superset to function. I have them as dependencies in other projects and have always think of them independent from incubator-superset. They should have their own dependencies.

Copy link
Member

@suddjian suddjian May 6, 2020

Choose a reason for hiding this comment

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

All other superset-ui packages have things (including lodash) listed under dependencies. Is this different somehow?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am proposing we proceed with moving react to peerDependencies and leave the remaining in dependencies unless there is objection?

Copy link
Member

Choose a reason for hiding this comment

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

No objection here. I actually already moved react, but haven't pushed it yet.

icon: 'info-circle',
placement: 'right',
};
const tooltipStyle = { wordWrap: 'break-word' } as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Try avoid any if possible:

const tooltipStyle: React.CSSProperties = { wordWrap: 'break-word' };

Since this rule is so simple, you can probably also just inline the style in <Tooltip ... style={}>.

Copy link
Contributor

Choose a reason for hiding this comment

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

having constant here is better so react won't re-render. when passing object to style, react only compares reference.

import React from 'react';
import { kebabCase } from 'lodash';
// @ts-ignore
import { Tooltip, OverlayTrigger } from 'react-bootstrap';
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to remove // @ts-ignore and add proper typing support by installing @types/react-bootstrap.

Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly, bootstrap 3 doesn't have types support. We ran into this problem in incubator-superset as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of @ts-ignore, you can add a declaration file. Even if it is an empty declaration

Example:
https://github.com/apache-superset/superset-ui/blob/master/packages/superset-ui-translation/types/external.d.ts

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 @types/react-bootstrap @ 0.32.2 works with Bootstrap v3. There might be cases with suboptimal typings, where you can then do @ts-ignore per module.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! That means we can add types for bootstrap back in incubator-superset too

Copy link
Member

Choose a reason for hiding this comment

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

@ktmud I tried adding the types for bootstrap, but that leads to an issue in CI. It looks like our version of typescript isn't happy with those type definitions, any ideas on how to fix?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, should've used @types/react-bootstrap @ ^0.32.21. This is also what's used in incubator-superset.

Btw, it's preferable to have @types/* in dependencies instead of devDependencies so that dependent packages can have easier access to typings when the library is used in npm link.

className: 'text-muted',
icon: 'info-circle',
placement: 'right',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use ES6 function argument defaults.

placement: string;
bsStyle: string;
className: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Make those with defaults optional.

interface Props {
  label: string;
  icon: string;
  tooltip?: string;
  onClick?: () => void;
  placement?: string;
  bsStyle?: string;
  className?: string;
}

Copy link
Contributor

@kristw kristw May 6, 2020

Choose a reason for hiding this comment

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

+1 @ktmud with the small change to use type for Props instead of interface. (Just convention from guidelines at Airbnb and used throughout the codebase at the moment). Also export the type.

Copy link
Contributor

Choose a reason for hiding this comment

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

interface means the properties are immutable which often runs into problems when you want to extend the component and override the prop types.

@kristw
Copy link
Contributor

kristw commented May 6, 2020

Please also add unit test to ensure 100% coverage

@suddjian
Copy link
Member

suddjian commented May 7, 2020

Addressed PR feedback, should be ready for a re-review

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! Thanks to all involved for giving this so much due diligence.

@kristw kristw changed the title chore: PR to merge packges for controls migration feat(control-utils): add infotooltipwithtrigger May 7, 2020
@kristw kristw merged commit 488e945 into apache-superset:master May 7, 2020
@rusackas rusackas deleted the phillip/SO-264-partitionchart-controls-packages branch July 17, 2020 20:38
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