-
Notifications
You must be signed in to change notification settings - Fork 615
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
Add Status component to @console/shared #1697
Merged
openshift-merge-robot
merged 3 commits into
openshift:master
from
jtomasek:add-status-component
Jul 18, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as TechPreviewBadge } from './TechPreviewBadge'; | ||
export * from './status'; |
23 changes: 23 additions & 0 deletions
23
frontend/packages/console-shared/src/components/status/ErrorStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
|
||
import PopoverStatus from './PopoverStatus'; | ||
import StatusIconAndText from './StatusIconAndText'; | ||
import { RedExclamationCircleIcon } from './Icons'; | ||
|
||
type ErrorStatusProps = { | ||
title?: string; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const ErrorStatus: React.FC<ErrorStatusProps> = ({ title, iconOnly, children }) => { | ||
const icon = <RedExclamationCircleIcon />; | ||
return children ? ( | ||
<PopoverStatus icon={icon} title={title} iconOnly={iconOnly}> | ||
{children} | ||
</PopoverStatus> | ||
) : ( | ||
<StatusIconAndText icon={icon} title={title} iconOnly={iconOnly} /> | ||
); | ||
}; | ||
|
||
export default ErrorStatus; |
27 changes: 27 additions & 0 deletions
27
frontend/packages/console-shared/src/components/status/Icons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
import { | ||
CheckCircleIcon, | ||
ExclamationCircleIcon, | ||
ExclamationTriangleIcon, | ||
} from '@patternfly/react-icons'; | ||
import { | ||
global_success_color_100 as successColor, | ||
global_warning_color_100 as warningColor, | ||
global_danger_color_100 as dangerColor, | ||
} from '@patternfly/react-tokens'; | ||
|
||
export type ColoredIconProps = { | ||
className?: string; | ||
}; | ||
|
||
export const GreenCheckCircleIcon: React.FC<ColoredIconProps> = ({ className }) => { | ||
return <CheckCircleIcon color={successColor.value} className={className} />; | ||
}; | ||
|
||
export const RedExclamationCircleIcon: React.FC<ColoredIconProps> = ({ className }) => { | ||
return <ExclamationCircleIcon color={dangerColor.value} className={className} />; | ||
}; | ||
|
||
export const YellowExclamationTriangleIcon: React.FC<ColoredIconProps> = ({ className }) => { | ||
return <ExclamationTriangleIcon color={warningColor.value} className={className} />; | ||
}; |
23 changes: 23 additions & 0 deletions
23
frontend/packages/console-shared/src/components/status/InfoStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { InfoCircleIcon } from '@patternfly/react-icons'; | ||
|
||
import PopoverStatus from './PopoverStatus'; | ||
import StatusIconAndText from './StatusIconAndText'; | ||
|
||
type InfoStatusProps = { | ||
title?: string; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const InfoStatus: React.FC<InfoStatusProps> = ({ title, iconOnly, children }) => { | ||
const icon = <InfoCircleIcon />; | ||
return children ? ( | ||
<PopoverStatus icon={icon} title={title} iconOnly={iconOnly}> | ||
{children} | ||
</PopoverStatus> | ||
) : ( | ||
<StatusIconAndText icon={icon} title={title} iconOnly={iconOnly} /> | ||
); | ||
}; | ||
|
||
export default InfoStatus; |
28 changes: 28 additions & 0 deletions
28
frontend/packages/console-shared/src/components/status/LinkStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
import * as History from 'history'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import StatusIconAndText from './StatusIconAndText'; | ||
|
||
type LinkStatusProps = React.ComponentProps<typeof StatusIconAndText> & { | ||
linkTitle?: string; | ||
linkTo?: History.LocationDescriptor; | ||
}; | ||
|
||
const LinkStatus: React.FC<LinkStatusProps> = ({ | ||
icon, | ||
title, | ||
spin, | ||
linkTitle, | ||
linkTo, | ||
iconOnly, | ||
}) => | ||
linkTo ? ( | ||
<Link to={linkTo} title={linkTitle}> | ||
<StatusIconAndText icon={icon} title={title} spin={spin} iconOnly={iconOnly} /> | ||
</Link> | ||
) : ( | ||
<StatusIconAndText icon={icon} title={title} spin={spin} iconOnly={iconOnly} /> | ||
); | ||
|
||
export default LinkStatus; |
21 changes: 21 additions & 0 deletions
21
frontend/packages/console-shared/src/components/status/PopoverStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react'; | ||
import { Popover, PopoverPosition } from '@patternfly/react-core'; | ||
import { Button } from 'patternfly-react'; | ||
|
||
import StatusIconAndText from './StatusIconAndText'; | ||
|
||
const PopoverStatus: React.FC<React.ComponentProps<typeof StatusIconAndText>> = ({ | ||
icon, | ||
title, | ||
spin, | ||
children, | ||
iconOnly, | ||
}) => ( | ||
<Popover position={PopoverPosition.right} headerContent={title} bodyContent={children}> | ||
<Button bsStyle="link"> | ||
<StatusIconAndText icon={icon} title={title} spin={spin} iconOnly={iconOnly} /> | ||
</Button> | ||
</Popover> | ||
); | ||
|
||
export default PopoverStatus; |
15 changes: 15 additions & 0 deletions
15
frontend/packages/console-shared/src/components/status/ProgressStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react'; | ||
import { InProgressIcon } from '@patternfly/react-icons'; | ||
|
||
import StatusIconAndText from './StatusIconAndText'; | ||
|
||
type ProgressStatusProps = { | ||
title?: string; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const ProgressStatus: React.FC<ProgressStatusProps> = ({ title, iconOnly }) => ( | ||
<StatusIconAndText icon={<InProgressIcon />} title={title} iconOnly={iconOnly} /> | ||
); | ||
|
||
export default ProgressStatus; |
82 changes: 82 additions & 0 deletions
82
frontend/packages/console-shared/src/components/status/Status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as React from 'react'; | ||
import { | ||
HourglassStartIcon, | ||
HourglassHalfIcon, | ||
SyncAltIcon, | ||
BanIcon, | ||
ExclamationTriangleIcon, | ||
UnknownIcon, | ||
} from '@patternfly/react-icons'; | ||
|
||
import StatusIconAndText from './StatusIconAndText'; | ||
import ProgressStatus from './ProgressStatus'; | ||
import ErrorStatus from './ErrorStatus'; | ||
import SuccessStatus from './SuccessStatus'; | ||
import InfoStatus from './InfoStatus'; | ||
import { DASH } from '../../constants'; | ||
|
||
export type StatusProps = { | ||
status?: string; | ||
title?: string; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const Status: React.FC<StatusProps> = ({ status, title, children, iconOnly }) => { | ||
const statusProps = { title: title || status, iconOnly }; | ||
switch (status) { | ||
case 'New': | ||
return <StatusIconAndText {...statusProps} icon={<HourglassStartIcon />} />; | ||
|
||
case 'Pending': | ||
return <StatusIconAndText {...statusProps} icon={<HourglassHalfIcon />} />; | ||
|
||
case 'ContainerCreating': | ||
return <ProgressStatus {...statusProps} />; | ||
|
||
case 'In Progress': | ||
case 'Running': | ||
case 'Updating': | ||
case 'Upgrading': | ||
return <StatusIconAndText {...statusProps} icon={<SyncAltIcon />} />; | ||
|
||
case 'Cancelled': | ||
case 'Expired': | ||
case 'Not Ready': | ||
case 'Terminating': | ||
return <StatusIconAndText {...statusProps} icon={<BanIcon />} />; | ||
|
||
case 'Warning': | ||
return <StatusIconAndText {...statusProps} icon={<ExclamationTriangleIcon />} />; | ||
|
||
case 'ContainerCannotRun': | ||
case 'CrashLoopBackOff': | ||
case 'Critical': | ||
case 'Error': | ||
case 'Failed': | ||
case 'InstallCheckFailed': | ||
case 'Lost': | ||
case 'Rejected': | ||
return <ErrorStatus {...statusProps}>{children}</ErrorStatus>; | ||
|
||
case 'Accepted': | ||
case 'Active': | ||
case 'Bound': | ||
case 'Complete': | ||
case 'Completed': | ||
case 'Enabled': | ||
case 'Ready': | ||
case 'Up to date': | ||
return <SuccessStatus {...statusProps} />; | ||
|
||
case 'Info': | ||
return <InfoStatus {...statusProps}>{children}</InfoStatus>; | ||
|
||
case 'Unknown': | ||
return <StatusIconAndText {...statusProps} icon={<UnknownIcon />} />; | ||
|
||
default: | ||
return <>{DASH}</>; | ||
} | ||
}; | ||
|
||
export default Status; |
6 changes: 6 additions & 0 deletions
6
frontend/packages/console-shared/src/components/status/StatusIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react'; | ||
import Status from './Status'; | ||
|
||
const StatusIcon = ({ status }) => <Status status={status} iconOnly />; | ||
|
||
export default StatusIcon; |
34 changes: 34 additions & 0 deletions
34
frontend/packages/console-shared/src/components/status/StatusIconAndText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { CamelCaseWrap } from '@console/internal/components/utils'; | ||
import { DASH } from '../../constants'; | ||
|
||
type StatusIconAndTextProps = { | ||
icon?: React.ReactElement; | ||
title?: string; | ||
spin?: boolean; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const StatusIconAndText: React.FC<StatusIconAndTextProps> = ({ icon, title, spin, iconOnly }) => { | ||
if (!title) { | ||
return <>{DASH}</>; | ||
} | ||
|
||
return ( | ||
<span className="co-icon-and-text" title={title}> | ||
{icon && | ||
React.cloneElement(icon, { | ||
className: classNames( | ||
spin && 'fa-spin', | ||
icon.props.className, | ||
!iconOnly && 'co-icon-and-text__icon', | ||
), | ||
})} | ||
{!iconOnly && <CamelCaseWrap value={title} />} | ||
</span> | ||
); | ||
}; | ||
|
||
export default StatusIconAndText; |
15 changes: 15 additions & 0 deletions
15
frontend/packages/console-shared/src/components/status/SuccessStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react'; | ||
|
||
import { GreenCheckCircleIcon } from './Icons'; | ||
import StatusIconAndText from './StatusIconAndText'; | ||
|
||
type SuccessStatusProps = { | ||
title?: string; | ||
iconOnly?: boolean; | ||
}; | ||
|
||
const SuccessStatus: React.FC<SuccessStatusProps> = ({ title, iconOnly }) => ( | ||
<StatusIconAndText icon={<GreenCheckCircleIcon />} title={title} iconOnly={iconOnly} /> | ||
); | ||
|
||
export default SuccessStatus; |
10 changes: 10 additions & 0 deletions
10
frontend/packages/console-shared/src/components/status/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export { default as Status } from './Status'; | ||
export { default as StatusIcon } from './StatusIcon'; | ||
export { default as StatusIconAndText } from './StatusIconAndText'; | ||
export { default as PopoverStatus } from './PopoverStatus'; | ||
export { default as LinkStatus } from './LinkStatus'; | ||
export { default as SuccessStatus } from './SuccessStatus'; | ||
export { default as ErrorStatus } from './ErrorStatus'; | ||
export { default as InfoStatus } from './InfoStatus'; | ||
export { default as ProgressStatus } from './ProgressStatus'; | ||
export * from './Icons'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, if
title
isn't defined buticon
is, we'll still render a dash - is this an expected behavior?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, I'll revisit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is intentional as it allows to handle the case when
StatusIconAndText
component is used and the status (title
prop) is not yet set. There is expliciticonOnly
prop to render an icon without text.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for clarification.