-
Notifications
You must be signed in to change notification settings - Fork 30
feat(CullingInfo): add culling info component #568
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
Changes from 1 commit
9656851
be6dad8
20247da
dd1de82
86b71fd
9bdb4aa
fdf0487
9d6bf62
d5ee24d
fa0a227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| --- | ||||||
| # Sidenav top-level section | ||||||
| # should be the same for all markdown files | ||||||
| section: Component groups | ||||||
| subsection: Status and state indicators | ||||||
| # Sidenav secondary level section | ||||||
| # should be the same for all markdown files | ||||||
| id: Culling information | ||||||
| # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) | ||||||
| source: react | ||||||
| # If you use typescript, the name of the interface to display props for | ||||||
| # These are found through the sourceProps function provided in patternfly-docs.source.js | ||||||
| propComponents: ['CullingInformation'] | ||||||
| sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/CullingInfo/CullingInfo.md | ||||||
| --- | ||||||
|
|
||||||
| import CullingInformation from '@patternfly/react-component-groups/dist/dynamic/CullingInfo'; | ||||||
|
|
||||||
| A **culling information** component displays a warning for when an object will become culled or stale. It can display this as a tooltip or text. | ||||||
|
||||||
| A **culling information** component displays a warning for when an object will become culled or stale. It can display this as a tooltip or text. | |
| A **culling information** component displays a warning status when an object is stale and planned for removal. Additional warning details can be displayed a tooltip or text label. |
if we change the component name, update here as well
Outdated
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.
| A basic culling information example | |
| A basic culling information component displays a warning icon with additional details in a tooltip, including a timeline for data removal. |
Outdated
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.
| For further customization, you can choose to render the tooltip as a message beside the icon instead. And you can utilize all properties of the [Tooltip component](/components/tooltip), with the exception of `content`. | |
| Instead of sharing details in a tooltip, you can place a short message beside the icon instead. You can still utilize all properties of the PatternFly [tooltip component](/components/tooltip), with the exception of `content`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from 'react'; | ||
| import CullingInformation from '@patternfly/react-component-groups/dist/dynamic/CullingInfo'; | ||
|
|
||
|
|
||
| export const CustomizedRenderExample: React.FunctionComponent = () => { | ||
| const staleDate = new Date('Sun Jan 26 2020'); | ||
| const warningDate = new Date('Mon Feb 03 2025'); | ||
| const cullingDate = new Date('Fri Feb 07 2025'); | ||
| return <> | ||
| <CullingInformation | ||
| stale={staleDate} | ||
| currDate={new Date()} | ||
| culled={cullingDate} | ||
| staleWarning={warningDate} | ||
| render={({ msg }) => (<React.Fragment>{msg} Hello there. Last seen: {` `}</React.Fragment>)}> | ||
fhlavac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </CullingInformation> | ||
| </> | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from 'react'; | ||
| import CullingInformation from '@patternfly/react-component-groups/dist/dynamic/CullingInfo'; | ||
|
|
||
| export const BasicExample: React.FunctionComponent = () => { | ||
| const staleDate = new Date('Sun Jan 26 2020'); | ||
| const warningDate = new Date('Mon Feb 03 2025'); | ||
| const cullingDate = new Date('Fri Feb 07 2025'); | ||
| return <> | ||
| <CullingInformation | ||
| stale={staleDate} | ||
| currDate={new Date()} | ||
| culled={cullingDate} | ||
| staleWarning={warningDate}> | ||
| </CullingInformation> | ||
| </> | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import React from 'react'; | ||
| import { ExclamationCircleIcon, ExclamationTriangleIcon } from '@patternfly/react-icons'; | ||
| import { Tooltip, TooltipProps } from '@patternfly/react-core'; | ||
| import clsx from 'clsx'; | ||
| import { createUseStyles } from 'react-jss'; | ||
| import { CullingDate, CullingInfo, calculateTooltip } from './CullingInfoUtils'; | ||
|
|
||
| export type Render = (config: { msg: string }) => React.ReactElement<any, any> | null; | ||
|
Check warning on line 8 in packages/module/src/CullingInfo/CullingInfo.tsx
|
||
|
|
||
| const useStyles = createUseStyles({ | ||
| inventoryCullingWarning: { | ||
| color: 'var(--pf-v6-global--warning-color--200)', | ||
|
||
| fontWeight: 'var(--pf-v6-global--FontWeight--bold)', | ||
| svg: { | ||
| marginRight: 'var(--pf-v5-global--spacer--sm)' | ||
| } | ||
| }, | ||
| inventoryCullingDanger: { | ||
| color: 'var(--pf-v6-global--warning-color--200)', | ||
| fontWeight: 'var(--pf-v6-global--FontWeight--bold)', | ||
| svg: { | ||
| marginRight: 'var(--pf-v6-global--spacer--sm)' | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| export interface CullingInformation extends Omit<TooltipProps, 'content'> { | ||
fhlavac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** Option to add custom css classes */ | ||
| className?: string; | ||
| /** Warning date for when object becomes stale */ | ||
| staleWarning: CullingDate; | ||
| /** Date when object becomes culled */ | ||
| culled: CullingDate; | ||
| /** Date when object becomes stale */ | ||
| stale: CullingDate; | ||
| /** Current date */ | ||
| currDate: CullingDate; | ||
| /** Optional prop to add custom children */ | ||
| children?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined; | ||
|
Check warning on line 39 in packages/module/src/CullingInfo/CullingInfo.tsx
|
||
| /** Option to add custom message ReactElement */ | ||
| render?: Render; | ||
| } | ||
|
|
||
| const CullingInformation: React.FunctionComponent<CullingInformation> = ({ | ||
| culled = new Date(0), | ||
| className, | ||
| staleWarning = new Date(0), | ||
| stale = new Date(0), | ||
| currDate = new Date(0), | ||
| children, | ||
| render, | ||
| ...props | ||
| }) => { | ||
| const classes = useStyles(); | ||
|
|
||
| if (new Date(currDate).valueOf() - new Date(stale).valueOf() < 0) { | ||
| return render | ||
| ? render({ | ||
| msg: '', | ||
| }) | ||
| : children || null; | ||
| } | ||
|
|
||
| const { isWarn, isError, msg }: CullingInfo = calculateTooltip(culled, staleWarning, currDate); | ||
| if (render) { | ||
| return ( | ||
| <span | ||
| className={clsx({ [classes.inventoryCullingWarning]: isWarn, [classes.inventoryCullingDanger]: isError }, className)} | ||
| > | ||
| {isWarn && <ExclamationTriangleIcon className={classes.inventoryCullingWarning}/>} | ||
| {isError && <ExclamationCircleIcon />} | ||
| {render({ msg })} | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <React.Fragment> | ||
| <Tooltip {...props} content={msg} position="bottom"> | ||
| <span | ||
|
||
| className={clsx({ [classes.inventoryCullingWarning]: isWarn, [classes.inventoryCullingDanger]: isError }, className)} | ||
| > | ||
| {isError && <ExclamationCircleIcon />} | ||
| {isWarn && <ExclamationTriangleIcon />} | ||
| {children} | ||
|
||
| </span> | ||
| </Tooltip> | ||
| </React.Fragment> | ||
| ); | ||
| }; | ||
|
|
||
| export default CullingInformation; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| export type CullingDate = string | number | Date; | ||
|
|
||
| export interface CullingInfo { | ||
| isWarn?: boolean; | ||
| isError?: boolean; | ||
| msg: string; | ||
| } | ||
| export type CalculateTooltip = (culled: CullingDate, warning: CullingDate, currDate: CullingDate) => CullingInfo; | ||
|
|
||
| export const seconds = 1000; | ||
| export const minutes: number = seconds * 60; | ||
| export const hours: number = minutes * 60; | ||
| export const days: number = hours * 24; | ||
|
|
||
| export const calculateTooltip: CalculateTooltip = (culled, warning, currDate) => { | ||
| const culledDate: Date = new Date(culled); | ||
| const warningDate: Date = new Date(warning); | ||
| const diffTime: number = new Date(currDate).valueOf() - warningDate.valueOf(); | ||
| const removeIn: number = Math.ceil((culledDate.valueOf() - new Date(currDate).valueOf()) / days); | ||
| const msg = `System scheduled for inventory removal in ${removeIn} days`; | ||
fhlavac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (diffTime >= 0) { | ||
| return { | ||
| isError: true, | ||
| msg, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| isWarn: true, | ||
| msg, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default } from './CullingInfo'; | ||
| export * from './CullingInfo'; |

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.
Previously, (via this Miro), we considered renaming "culling info" to be "status timestamp" for easier understanding. I don't see a timestamp in the examples, though, so maybe the design has changed. Do we still want to do that?
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.
Another option could be "Stale warning", "Expiration warning", "Stale data warning"
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.
I'm not able to access the Miro link, but there isn't a timestamp. It is either a warning/danger tooltip or a warning/danger icon with a custom message. Is there a naming option you would prefer?
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.
Okay, let's go with "stale data warning" if that sounds okay with you? I also don't mind sticking with "culling" if that's more accurate, but if so I would suggest "culling warning" instead of "culling information"