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

[EuiComment] Add "custom" option to EuiComment.type and more enhancements #5692

Conversation

elizabetdev
Copy link
Contributor

@elizabetdev elizabetdev commented Mar 4, 2022

Summary

The idea of this PR was to add a docs example/demo of a comment system similar to the one from Security -> Cases.

But when I tried to build the demo I struggled to add a EuiMarkdownEditor inside a comment list. So I inspected the code of the Security -> Cases and noticed that they styled the comment list to make it work:

https://github.com/elastic/kibana/blob/513a08ea390156327a8fbeed4d6d6254315e02cd/x-pack/plugins/cases/public/components/user_actions/index.tsx#L43-L56

This research leads to introducing a new component called EuiTimeline #5730 and some enhancements in EuiCommentList and EuiComment components to better suit Security and Observability use cases. Thanks, @snide, and @cchaos for showing me pain points in the current usages.

Using the EuiTimeline

The EuiCommentList and EuiComment are now using the new EuiTimeline and EuiTimelineItem components respectively.

New props

I added a "custom" option to EuiComment.type. With this option, consumers can pass any custom element in the timeline.

custom@2x

In the past, the timeline was reflecting the type of event. The type update had a smaller avatar and it was defaulting to a dot. Now the timeline always defaults to the avatar with the username initial letter:

timeline@2x

For this reason, I needed to introduce a new prop updateIcon to allow the events type update to have a custom icon. Also added a prop called updateColor that changes de panel color of an event type update.

update props@2x

The EuiComment.actions prop was updated to also accept a ReactNode[]. This way we ensure better spacing when multiple actions are added.

Breaking changes

I changed the EuiCommentEvent.username type from ReactNode to string. The reason for that is that now the timeline icon defaults to an avatar with an initial username letter. So we need to make sure the username is a string to pass to the EuiAvatar.name.

Another breaking change is that EuiCommentList (<ol/>) is now required to wrap the EuiComment when EuiComment.component defaults to li.

Note: Not having any of these new requirements doesn't break the code but throws TS errors and without the wrapper, it breaks the a11y.

Docs

The docs were updated to reflect the changes and two new sections were added:

Screenshot 2022-04-28 at 17 07 55

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • [ ] Checked for breaking changes and labeled appropriately
  • [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Things to look out for when moving styles

  • Anything in the backlog that could be a quick fix for that component?
  • [ ] Convert global Sass vars to JS version like sizing
  • [ ] Convert component-specific Sass vars to exported JS versions
  • Convert side specific padding, margin, and position to -inline and -block (Logical properties)
  • Reduce specificity where possible (usually by reducing class name chaining)
  • Use gap property to add margin between items if using flex
  • [ ] Can any still existing .js files be converted to TS?
  • [ ] All animations or transitions are wrapped in euiCanAnimate

QA

  • Does the output CSS match the previous CSS / as expected
  • Does the rendered class read as expected

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@elizabetdev elizabetdev changed the title [EuiComment] Add type "custom" and comment system example [EuiComment] Add "custom" option to EuiComment.type and comment system docs example Mar 7, 2022
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@elizabetdev elizabetdev marked this pull request as ready for review March 7, 2022 15:08
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@cchaos cchaos self-requested a review March 8, 2022 16:16
@snide
Copy link
Contributor

snide commented Mar 8, 2022

Hey @miukimiu. Thanks for working on this. I've actually been working on a slight rework of cases in the Security app and one thing @dimadavid and I had trouble with is why the avatar icon pattern flip flops.

In Github flows this can make sense because of the indents and "child" representation of things, but the way we use it (with a linear line) makes it a little difficult to grok. Part of me wonders if we should just keep avatars on one side, and actions on the other.

There are generally going to be three styles of feed items coming in the stream:

  • Actions that resolve to a person
  • Comments that resolve to a person
  • Actions that revolve to a system (like an outside system or automated event)

Another state that we needed to cover was:

  • Actions that are very important (like an alert) and need to be called out from the feed.

^^ we don't have a good pattern for this, and I was likely going to do it through custom css.

In any case, this screen shows a bit of the trouble:

image

@cchaos
Copy link
Contributor

cchaos commented Mar 8, 2022

Let's also not forget to do any updates to the Figma Library if we change component configurations.

@elizabetdev
Copy link
Contributor Author

Hi @snide and @cchaos,

Here are a few ideas to solve the issues @snide mentioned:

  • The avatars would always be on the same side and the update icon goes on top of the avatar.
  • Comments type="update" can receive an avatar and an icon that represents the update. If no update icon is passed they just get the icon="dot".
  • Comments type="update" can have a panel with a color (to be called out from the feed).


Frame 41@2x

@snide it would be really helpful if you could give me an example of a real timeline. Just the text examples.

The Figma prototype can be found here.

Let me know what you think.

@cchaos
Copy link
Contributor

cchaos commented Mar 9, 2022

Thanks @miukimiu ! I added comments to the FIgma.

@elizabetdev
Copy link
Contributor Author

@snide @cchaos and @dimadavid just to keep the API conversation here and after going through the Figma comments here are my proposed changes:

1 - In the current implementation, the avatar with the user is the default. I propose to change it to avatar initials. The username is required so we can always get the initials. All the implementations I've seen so far use the initials. And it makes sense because is a good way to distinguish users. Why would the avatar be the default?

2 - When the EuiComment.type is update and no icon is specified it gets the dot. Why do I’m insisting on always having this update icon? Because without it then it gets a mess. Some updates get an icon... Others don’t... And visually they don’t get aligned. The icons could also be in the middle of the text. But it would add too much visual noise (IMO). They wouldn't get aligned. So I vote to let it just before the username.

3 - Be able to pass a EuiPanel.color to be called out from the feed. In these cases, I would remove the default update icon dot or any other update icon that is passed should be omitted.

4 - Custom actions should be aligned on the right side.



comment stream@2x



New icons (probably not needed)

1 - I noticed that in Observability -> Cases an arrow right is being used to show the alert details (opens in a flyout).

Screenshot 2022-03-10 at 19 00 32

What should be the right icon for this scenario? I created a new one called for now documentOpen. Well... Any suggestions for what should be the right icon. Would this one work?

Screenshot 2022-03-10 at 19 06 10

2 - If we change to avatars for the initials we won't require to show the icon user anymore... But I notice that we don't have an icon that represents a bot or a service. So I created a new icon called bot.



comment stream 2@2x

These new designs are in the prototype (pages 3 and 4). You can add your design comments there.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@chandlerprall
Copy link
Contributor

I re-enabled the shouldRenderCustomStyles check with an updated regex test to allow arbitrary additions to the generated classname. @constancecchen if you wouldn't mind checking that regex change in d25ed5c

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

I love the final output of this. Very uniform and easy to scan. Here is some early feedback just looking at the component code and output for now. I'm also happy to pair on any of these that aren't particularly clear.

Mobile

I would see if you can get the event details items to all wrap in some fashion otherwise they'll need sort of overflow scroll on them or something.
Screen Shot 2022-05-09 at 15 49 17 PM

@@ -45,7 +45,6 @@ export const EuiTimelineItem: FunctionComponent<EuiTimelineItemProps> = ({
verticalAlign = 'center',
icon,
iconAriaLabel,
className,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice catch

@@ -31,6 +31,7 @@ export const euiTimelineItemStyles = ({ euiTheme }: UseEuiTheme) => ({
}

&:not(:only-child) > [class*='euiTimelineItemIcon-center']::before {
display: flex;
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 you'll find that you'll be fighting with this override quite a bit if you ever change the default display of EuiTimelineItemIcon. You may want to mvoe this set of styles to outside of :last-of-type.

src/components/comment_list/comment_timeline.tsx Outdated Show resolved Hide resolved
let iconRender;
if (typeof timelineIcon === 'string') {
iconRender = (
<EuiIcon size={type === 'update' ? 'm' : 'l'} type={timelineIcon} />
<EuiAvatar
className="euiCommentTimeline"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just looking at the rendered DOM output, this classname no longer seems appropriate. Since there's already a breaking change on this component, I'd suggest changing this to be EuiCommentIcon or EuiCommentTimelineIcon or even avatar instead of icon. But leaving it at simply timeline I think mis-represents what and where it renders.

Comment on lines 35 to 36
username="someuser"
timelineIcon={<EuiAvatar size="l" name="Mario" />}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, do we think this is duplicative? Mostly meaning, if username is required, but they want to pass a custom Avatar, they're most likely duplicating username on both but the timeline icon doesn't actually render / use the username anymore in the custom case.

*/
comments?: EuiCommentProps[];
};
export type EuiCommentListProps = EuiTimelineProps & {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's showing both items and comments props allowed, but I'd suggest restricting to just comments.

Suggested change
export type EuiCommentListProps = EuiTimelineProps & {
export type EuiCommentListProps = Omit<EuiTimelineProps, 'items'> & {

Screen Shot 2022-05-09 at 16 09 12 PM

src/components/comment_list/comment_event.tsx Outdated Show resolved Hide resolved
src/components/comment_list/comment_event.styles.ts Outdated Show resolved Hide resolved
src/components/comment_list/comment_event.styles.ts Outdated Show resolved Hide resolved
src/components/comment_list/comment_event.styles.ts Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@cchaos cchaos added this to the Elastic Stack 8.4 milestone May 16, 2022
@cchaos
Copy link
Contributor

cchaos commented May 16, 2022

I'm pushing this PR off to Stack 8.4 as it's a major breaking change for all consumers of this component.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5692/

@elizabetdev
Copy link
Contributor Author

Closing in favor of #6030

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.

6 participants