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

Allow UI elements to be injected and remove Antd dependency #520

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aocenas
Copy link

@aocenas aocenas commented Feb 12, 2020

Which problem is this PR solving?

Part of both #509 and #508

Short description of the changes

This tries to remove dependency on Antd. Issue with Antd is first the size of the overall dependency, global styles and problematic theming that would have theme both the trace UI and the Antd elements separately.

This provides a react context that needs to be used for injecting required UI components. This would allow injecting custom UI element to make theming better. For example in Grafana we use custom component library to share styling and behaviour.

Caveats:

  • It is hard to provide any defaults as that would mean a default UI library needs to be included. Antd could be defined as a peer dependency, that though would mean a warning if you do not install it which is probably not ideal. That UI components are required will make this a bit harder to use. Long term defaults can be implemented directly in the jeager ui though.
  • This is designed so that the context provider is public and users implementing this as a library would use it directly ala Redux provider. Seems better than having long list of props but that is subjective.

@aocenas
Copy link
Author

aocenas commented Feb 12, 2020

This is just a draft to get feedback on this approach.

Signed-off-by: Andrej Ocenas <mr.ocenas@gmail.com>
@codecov
Copy link

codecov bot commented Feb 12, 2020

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (8cb13c4) 92.92% compared to head (523799c) 96.57%.
Report is 751 commits behind head on main.

❗ Current head 523799c differs from pull request most recent head ba8f09b. Consider uploading reports for the commit ba8f09b to get more accurate results

Files Patch % Lines
.../jaeger-ui/src/components/QualityMetrics/index.tsx 93.87% 3 Missing ⚠️
...r-ui/src/components/Monitor/ServicesView/index.tsx 98.37% 2 Missing ⚠️
...components/SearchTracePage/SearchResults/index.tsx 90.00% 2 Missing ⚠️
...aeger-ui/src/actions/path-agnostic-decorations.tsx 97.91% 1 Missing ⚠️
packages/jaeger-ui/src/components/App/TopNav.tsx 94.44% 1 Missing ⚠️
...rc/components/DeepDependencies/SidePanel/index.tsx 96.77% 1 Missing ⚠️
...jaeger-ui/src/components/DependencyGraph/index.jsx 95.83% 1 Missing ⚠️
...ger-ui/src/components/Monitor/EmptyState/index.tsx 92.85% 1 Missing ⚠️
...c/components/Monitor/ServicesView/serviceGraph.tsx 98.18% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #520      +/-   ##
==========================================
+ Coverage   92.92%   96.57%   +3.64%     
==========================================
  Files         197      254      +57     
  Lines        4808     7620    +2812     
  Branches     1160     1986     +826     
==========================================
+ Hits         4468     7359    +2891     
+ Misses        299      261      -38     
+ Partials       41        0      -41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@everett980 everett980 left a comment

Choose a reason for hiding this comment

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

Minor changes (variable name, use a const, a type, and possibly avoiding manually checking for undefined), but otherwise looks like a good start.

Though the title is a bit confusing as it does not remove antd as a dependency, it just removes it as a dependency of TracePage components.

placement?: TooltipPlacement;
children?: React.ReactNode;
},
{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be unknown

updateViewRangeTime={this.updateViewRangeTime}
viewRange={viewRange}
/>
<UIElementsContext.Provider value={{ Popover }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The value here should be a const at the top of the file. Something like const UI_ELEMENTS = { Popover };. Without that, ever render of TracePage/index will cause all consumers to re-render (source).

export function GetElementsContext(props: GetElementsContextProps) {
return (
<UIElementsContext.Consumer>
{(value: Elements | undefined) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to my feedback on another PR, is it possible to remove the | undefined and rely on TypeScript to check that the value is provided?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Although I suppose that depends on a way to check that UiElementsContext.Consumer is always used within a UiElementsContext.Provider 🤔

*/
export function GetElementsContext(props: GetElementsContextProps) {
return (
<UIElementsContext.Consumer>
Copy link
Collaborator

Choose a reason for hiding this comment

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

UI should be Ui. For the sake of camel/pascal case, acronyms should be treated as a word. UiFind as an example

@everett980
Copy link
Collaborator

Also, how will this impact our ability to add functionality to JaegerUI?

For instance, the UiPopover interface only has five props defined. If we want to use Antd's Popover's onVisibleChange, do we just update the type, mention it in the change log for the yet-to-be created jaeger-components package, and leave it to consumers to make sure their provided components are compatible with the types in uiElementsContext when they update?

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.

None yet

2 participants