@@ -3,27 +3,39 @@ import { ExclamationCircleIcon, ExclamationTriangleIcon } from '@patternfly/reac
33import { Tooltip , TooltipProps } from '@patternfly/react-core' ;
44import clsx from 'clsx' ;
55import { createUseStyles } from 'react-jss' ;
6- import { CullingDate , CullingInfo , calculateTooltip } from './CullingInfoUtils' ;
76
8- export type Render = ( config : { msg : string } ) => React . ReactElement < any , any > | null ;
7+ type Render = ( config : { msg : string } ) => React . ReactElement < any , any > | null ;
8+ type CullingDate = string | number | Date ;
9+
10+ interface CullingInfo {
11+ isWarn ?: boolean ;
12+ isError ?: boolean ;
13+ msg : string ;
14+ }
15+
16+ const seconds = 1000 ;
17+ const minutes : number = seconds * 60 ;
18+ const hours : number = minutes * 60 ;
19+ const days : number = hours * 24 ;
20+
21+ type CalculateTooltip = ( culled : CullingDate , warning : CullingDate , currDate : CullingDate ) => CullingInfo ;
922
1023const useStyles = createUseStyles ( {
1124 inventoryCullingWarning : {
12- color : 'var(--pf-v6-global--warning-color--200)' ,
13- fontWeight : 'var(--pf-v6-global--FontWeight--bold)' ,
14- svg : {
15- marginRight : 'var(--pf-v5-global--spacer--sm)'
16- }
25+ color : 'var(--pf-t--global--icon--color--status--warning--default)' ,
1726 } ,
1827 inventoryCullingDanger : {
19- color : 'var(--pf-v6-global--warning-color--200)' ,
20- fontWeight : 'var(--pf-v6-global--FontWeight--bold)' ,
21- svg : {
22- marginRight : 'var(--pf-v6-global--spacer--sm)'
23- }
24- }
28+ color : 'var(--pf-t--global--icon--color--status--danger--default)' ,
29+ } ,
30+ iconMargin : {
31+ marginRight : 'var(--pf-t--global--spacer--sm)'
32+ } ,
33+ messageFont : {
34+ fontWeight : 'var(--pf-t--global--font--weight--200)' ,
35+ } ,
2536} ) ;
2637
38+ /** extends TooltipProps */
2739export interface CullingInformation extends Omit < TooltipProps , 'content' > {
2840 /** Option to add custom css classes */
2941 className ?: string ;
@@ -39,6 +51,8 @@ export interface CullingInformation extends Omit<TooltipProps, 'content'> {
3951 children ?: React . ReactElement < any , string | React . JSXElementConstructor < any > > | undefined ;
4052 /** Option to add custom message ReactElement */
4153 render ?: Render ;
54+ /** Optional custom warning message */
55+ message ?: string ;
4256}
4357
4458const CullingInformation : React . FunctionComponent < CullingInformation > = ( {
@@ -49,10 +63,30 @@ const CullingInformation: React.FunctionComponent<CullingInformation> = ({
4963 currDate = new Date ( 0 ) ,
5064 children,
5165 render,
66+ message,
5267 ...props
5368} ) => {
5469 const classes = useStyles ( ) ;
5570
71+ const calculateTooltip : CalculateTooltip = ( culled , warning , currDate ) => {
72+ const culledDate : Date = new Date ( culled ) ;
73+ const warningDate : Date = new Date ( warning ) ;
74+ const diffTime : number = new Date ( currDate ) . valueOf ( ) - warningDate . valueOf ( ) ;
75+ const removeIn : number = Math . ceil ( ( culledDate . valueOf ( ) - new Date ( currDate ) . valueOf ( ) ) / days ) ;
76+ const msg = message ? message : `System scheduled for inventory removal in ${ removeIn } days` ;
77+ if ( diffTime >= 0 ) {
78+ return {
79+ isError : true ,
80+ msg,
81+ } ;
82+ }
83+
84+ return {
85+ isWarn : true ,
86+ msg,
87+ } ;
88+ } ;
89+
5690 if ( new Date ( currDate ) . valueOf ( ) - new Date ( stale ) . valueOf ( ) < 0 ) {
5791 return render
5892 ? render ( {
@@ -67,9 +101,12 @@ const CullingInformation: React.FunctionComponent<CullingInformation> = ({
67101 < span
68102 className = { clsx ( { [ classes . inventoryCullingWarning ] : isWarn , [ classes . inventoryCullingDanger ] : isError } , className ) }
69103 >
70- { isWarn && < ExclamationTriangleIcon className = { classes . inventoryCullingWarning } /> }
71- { isError && < ExclamationCircleIcon /> }
72- { render ( { msg } ) }
104+ { isWarn && < ExclamationTriangleIcon className = { clsx ( classes . iconMargin ) } /> }
105+ { isError && < ExclamationCircleIcon className = { clsx ( classes . iconMargin ) } /> }
106+ < span className = { clsx ( classes . messageFont ) } >
107+ { render ( { msg } ) }
108+ </ span >
109+
73110 </ span >
74111 ) ;
75112 }
0 commit comments