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

[Shared UX] Migrate popover from presentation to shared ux package #128665

Merged
merged 34 commits into from
Apr 10, 2022

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Mar 28, 2022

Summary

This PR migrates the popover from the items directory in presentation_util to the shared ux package.

  • The ToolbarButton is refactored to accept a specified iconSide prop to accommodate controls such as control_group_container.tsx where the icon is on the right.

  • ts-ignore comment added to bypass the error:

info [bazel] packages/kbn-shared-ux-components/src/toolbar/popovers/popover.tsx:35:6 - error TS2322: Type '{ children: ReactNode; onClick?: MouseEventHandler | undefined; color?: string | undefined; style?: CSSProperties | undefined; ... 276 more ...; closePopover: () => void; }' is not assignable to type 'IntrinsicClassAttributes'.
  | info [bazel]   Types of property 'css' are incompatible.
  | info [bazel]     Type 'InterpolationWithTheme' is not assignable to type 'Interpolation'.
  | info [bazel]       Type 'ArrayInterpolation' is not assignable to type 'Interpolation'.
  | info [bazel]         Type 'ArrayInterpolation' is not assignable to type 'ArrayInterpolation'.
  | info [bazel]           The types returned by 'pop()' are incompatible between these types.
  | info [bazel]             Type 'Interpolation' is not assignable to type 'Interpolation'.
  | info [bazel]               Type 'ArrayInterpolation' is not assignable to type 'Interpolation'.
  | info [bazel]
  | info [bazel] 35     <EuiPopover {...{ isOpen, button, closePopover }} {...popover}>
  | info [bazel]        ~~~~~~~~~~
  | info [bazel]
  | info [bazel]
  | info [bazel] Found 1 error in packages/kbn-shared-ux-components/src/toolbar/popovers/popover.tsx:35

Checklist

@rshen91 rshen91 added 8.3 candidate Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) backport:skip This commit does not require backporting labels Mar 28, 2022
@rshen91 rshen91 self-assigned this Mar 30, 2022
@rshen91 rshen91 marked this pull request as ready for review March 30, 2022 16:00
@rshen91 rshen91 added the v8.3.0 label Mar 30, 2022
@rshen91 rshen91 added the release_note:skip Skip the PR/issue when compiling release notes label Mar 30, 2022
@rshen91 rshen91 requested review from majagrubic and sebelga March 30, 2022 16:05
Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

This looks pretty sound to me, but @clintandrewhall if you could have an additional look, would be appreciated.

@@ -9,14 +9,16 @@
import React from 'react';
import { EuiButton } from '@elastic/eui';
import { EuiButtonPropsForButton } from '@elastic/eui/src/components/button/button';
import { ButtonContentIconSide } from '@elastic/eui/src/components/button/button_content';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { ButtonContentIconSide } from '@elastic/eui/src/components/button/button_content';
import { EuiButtonDisplayProps } from '@elastic/eui/src/components/button/button_content';


export interface Props extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType'> {
label: string;
iconSide?: ButtonContentIconSide;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
iconSide?: ButtonContentIconSide;

@@ -9,14 +9,16 @@
import React from 'react';
import { EuiButton } from '@elastic/eui';
import { EuiButtonPropsForButton } from '@elastic/eui/src/components/button/button';
import { ButtonContentIconSide } from '@elastic/eui/src/components/button/button_content';

export interface Props extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType'> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export interface Props extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType'> {
export interface Props extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType' | 'iconSide'> {

return (
<EuiButton size="m" color="primary" fill={true} {...rest}>
<EuiButton size="m" color="primary" fill={true} iconSide={iconSide} {...rest}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary, but it it is:

Suggested change
<EuiButton size="m" color="primary" fill={true} iconSide={iconSide} {...rest}>
<EuiButton size="m" color="primary" fill={true} {...{ iconSide, ...rest }>

const button = <ToolbarButton onClick={onButtonClick} {...{ label, iconSide, iconType }} />;

return (
// @ts-ignore - Types of property csss are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.
Copy link
Contributor

@clintandrewhall clintandrewhall Mar 31, 2022

Choose a reason for hiding this comment

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

@thompsongl Any suggestions on this particular error?

Suggested change
// @ts-ignore - Types of property csss are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.
// @ts-expect-error - Types of property css are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.

Copy link
Contributor

@thompsongl thompsongl Mar 31, 2022

Choose a reason for hiding this comment

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

I don't see any errors here locally, and switching to @ts-expect-error introduces an error

Screen Shot 2022-03-31 at 4 18 56 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

type_check also passes

Screen Shot 2022-03-31 at 4 34 08 PM

Is there somewhere else the error presents?

Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is this was a leftover from some previous version of EUI. I removed it now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, by removing it I get the following error:


Type '{ children: ReactNode; onClick?: MouseEventHandler<HTMLDivElement> \| undefined; color?: string \| undefined; style?: CSSProperties \| undefined; ... 276 more ...; closePopover: () => void; }' is not assignable to type 'IntrinsicClassAttributes<EuiPopover>'.
--
  | info [bazel]   Types of property 'css' are incompatible.
  | info [bazel]     Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.
  | info [bazel]       Type 'ArrayInterpolation<undefined>' is not assignable to type 'Interpolation<Theme>'.
  | info [bazel]         Type 'ArrayInterpolation<undefined>' is not assignable to type 'ArrayInterpolation<Theme>'.
  | info [bazel]           The types returned by 'pop()' are incompatible between these types.
  | info [bazel]             Type 'Interpolation<undefined>' is not assignable to type 'Interpolation<Theme>'.
  | info [bazel]               Type 'ArrayInterpolation<undefined>' is not assignable to type 'Interpolation<Theme>'.
  | info [bazel]
  | info [bazel] 35     <EuiPopover {...{ isOpen, button, closePopover }} {...popover}>



Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, just saw you were talking about ts-ignore vs ts-expect-error rather than the actual type error not being present :D

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I don't get any errors after removing the TS comment entirely. bazel build and type_check both pass, and I get no errors in my IDE. Where do you see that error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see it now on bootstrap. That error is from a type mismatch between emotion@10 and emotion@11. Storybook uses emotion@10 and EUI, Kibana, etc. use emotion@11. This is more likely a bazel config problem (perhaps from how it builds with kbn-storybook package?) more so than an actual type error. Thinking on how to resolve.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the following to kbn-shared-ux-components/tsconfig.json compilerOptions resolves the error:

"paths": {
  "@emotion/core": [
    "node_modules/@emotion/react"
  ]
}

Also, the error will be resolved for us in the next release of storybook: https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.31

Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

We need to take the fix provided by @thompsongl for the Typescript incompatibility.

const button = <ToolbarButton onClick={onButtonClick} {...{ label, iconSide, iconType }} />;

return (
// @ts-ignore - Types of property css are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should rarely-- if ever-- use @ts-ignore, because if the error is resolved elsewhere, the ignore will remain. If we use @ts-expect-error, changes that resolve the error will prompt the resolver to remove this comment.

Suggested change
// @ts-ignore - Types of property css are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.
// @ts-expect-error - Types of property css are incompatible Type 'InterpolationWithTheme<any>' is not assignable to type 'Interpolation<Theme>'.

@clintandrewhall
Copy link
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

expected head sha didn’t match current head ref.

@majagrubic
Copy link
Contributor

@elasticmachine merge upstream

@majagrubic
Copy link
Contributor

Synced offline with @spalger about the ts problem, this is the conclusion:

I think the underlying issue is that while we expose the tsconfig.base.json file to bazel packages when they're built we don't expose the typings/* directory, so the "@emotion/core": ["typings/@emotion"], directive in tsconfig.base.json is silently ignored by TypeScript in the package build (because typings/@emotion can't be resolved).
I think it might be time to move the base tsconfigs to a package so that we can have all of their dependencies available when we're using them in another package. In the meantime we should probably stick with a // @ts-ignore

@majagrubic
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

Please complete my two documentation requests before committing. Approving to unblock.

date: 2022-03-28
---

> This documentation is in-progress.
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to complete this before committing.

const button = <ToolbarButton onClick={onButtonClick} {...{ label, iconSide, iconType }} />;

return (
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment before committing.

@majagrubic
Copy link
Contributor

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dataViewEditor 153 154 +1
maps 863 864 +1
spaces 264 265 +1
total +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/shared-ux-components 4 6 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dataViewEditor 154.0KB 154.5KB +538.0B
maps 2.7MB 2.7MB +531.0B
spaces 268.6KB 269.1KB +531.0B
total +1.6KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataViewEditor 10.6KB 10.6KB +1.0B
Unknown metric groups

API count

id before after diff
@kbn/shared-ux-components 32 34 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @rshen91

@majagrubic majagrubic merged commit 2894e40 into elastic:main Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.3 candidate backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants