Skip to content

Conversation

@seanforyou23
Copy link
Contributor

@seanforyou23 seanforyou23 commented Feb 24, 2020

What: Splitting out some work from #3771 - allowing actions to be any custom content, not just our action/close buttons.

Additional issues: #3771

Screen Shot 2020-02-24 at 6 50 16 PM

Breaking changes

  1. Alert: Alert action prop uses new type of AlertActionRenderer | React.ReactNode. Previous valid values remain valid, but the type applied may need to be updated accordingly.

@seanforyou23 seanforyou23 added Breaking change 💥 this change requires a major release and has API changes. enhancement 🚀 labels Feb 24, 2020
@patternfly-build
Copy link
Collaborator

patternfly-build commented Feb 24, 2020

@codecov-io
Copy link

codecov-io commented Feb 25, 2020

Codecov Report

Merging #3822 into master will increase coverage by 0.02%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3822      +/-   ##
==========================================
+ Coverage      71%   71.02%   +0.02%     
==========================================
  Files         785      785              
  Lines       10638    10639       +1     
  Branches     2314     2313       -1     
==========================================
+ Hits         7553     7556       +3     
+ Misses       2655     2653       -2     
  Partials      430      430
Flag Coverage Δ
#misc 95.45% <ø> (ø) ⬆️
#patternfly3 85.89% <ø> (ø) ⬆️
#patternfly4 60.05% <83.33%> (+0.03%) ⬆️
Impacted Files Coverage Δ
...eact-core/src/components/Alert/AlertActionLink.tsx 100% <ø> (+25%) ⬆️
...ernfly-4/react-core/src/components/Alert/Alert.tsx 87.5% <100%> (+1.13%) ⬆️
...re/src/components/Alert/AlertActionCloseButton.tsx 57.14% <66.66%> (+14.28%) ⬆️

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 f7f9fbe...29a3707. Read the comment docs.

karelhala
karelhala previously approved these changes Feb 25, 2020
Copy link
Contributor

@karelhala karelhala left a comment

Choose a reason for hiding this comment

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

Ooooh nice! This looks really nice!

dlabrecq
dlabrecq previously approved these changes Feb 25, 2020
@seanforyou23 seanforyou23 dismissed stale reviews from dlabrecq and karelhala via b291f09 March 10, 2020 18:52
@seanforyou23 seanforyou23 force-pushed the alert-action-enhancement branch from 29a3707 to b291f09 Compare March 10, 2020 18:52
@seanforyou23 seanforyou23 changed the base branch from master to v4 March 13, 2020 17:26
@jschuler
Copy link
Collaborator

needs to be rebased

@seanforyou23 seanforyou23 force-pushed the alert-action-enhancement branch 2 times, most recently from 9972df6 to cff4c7d Compare March 31, 2020 19:27
Copy link
Member

@ddonahue007 ddonahue007 left a comment

Choose a reason for hiding this comment

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

LGTM

@seanforyou23 seanforyou23 force-pushed the alert-action-enhancement branch from cff4c7d to b1e5043 Compare April 7, 2020 14:52
@seanforyou23 seanforyou23 force-pushed the alert-action-enhancement branch from b1e5043 to 41ed8d4 Compare April 8, 2020 16:56
/** Action button to put in the Alert. Should be <AlertActionLink> or <AlertActionCloseButton> */
action?: React.ReactNode;
/** Action button to put in the Alert. Often <AlertActionLink> or <AlertActionCloseButton> */
action?: AlertActionRenderer | React.ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this really React.FunctionComponent<{ title: React.ReactNode, variantLabel: string }>?

<h4 className={css(styles.alertTitle)}>{getHeadingContent}</h4>
{children && <div className={css(styles.alertDescription)}>{children}</div>}
<AlertContext.Provider value={{ title, variantLabel }}>
{action && (typeof action === 'object' || typeof action === 'string') && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a better API would be to leave action's type as React.ReactNode and use React.cloneElement to add the title and variantLabel props? This way class components could be passed as well, and we don't have to amend the API.

{React.isValidElement(action) && (
  <div className={css(styles.alertAction)}>
    {React.cloneElement(action as React.ReactElement, {
      title,
      variantLabel
    })}
  </div>
)}

Consumers would then be able to use added title and variantLabel props like this:

<Alert action={({title, variantLabel}) => <div>{title}{variantLabel}</div>} />

OR like this:

class MyAlertAction extends React.Component {
  render() {
    return <div>{this.props.title}{this.props.variantLabel}</div>;
  }
}

<Alert action={<MyAction />} />

export interface AlertActionLinkProps extends ButtonProps {
/** Content rendered inside the AlertLinkAction */
children?: string;
children: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be ReactNode so it could work with i18n libraries for example

<div className={css(styles.alertAction)}>{action}</div>
)}
{action && typeof action === 'function' && (
<div className={css(styles.alertAction)}>{action({ title, variantLabel })}</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand, couldn't this be
<div className={css(styles.alertAction)}>{action}</div> and since consumer is passing in title and variantLabel as props they already have knowledge of the props so aren't we just giving it back to them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking change 💥 this change requires a major release and has API changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants