Skip to content

Commit be6dad8

Browse files
committed
fix: use semantic tokens, fix styling, delete cullingInfoUtils
1 parent 9656851 commit be6dad8

File tree

4 files changed

+101
-61
lines changed

4 files changed

+101
-61
lines changed
Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
import React from 'react';
22
import CullingInformation from '@patternfly/react-component-groups/dist/dynamic/CullingInfo';
3+
import { Stack, StackItem } from '@patternfly/react-core';
34

45

56
export const CustomizedRenderExample: React.FunctionComponent = () => {
67
const staleDate = new Date('Sun Jan 26 2020');
78
const warningDate = new Date('Mon Feb 03 2025');
89
const cullingDate = new Date('Fri Feb 07 2025');
910
return <>
10-
<CullingInformation
11-
stale={staleDate}
12-
currDate={new Date()}
13-
culled={cullingDate}
14-
staleWarning={warningDate}
15-
render={({ msg }) => (<React.Fragment>{msg} Hello there. Last seen: {` `}</React.Fragment>)}>
16-
</CullingInformation>
11+
<Stack>
12+
<StackItem>
13+
<CullingInformation
14+
stale={staleDate}
15+
currDate={new Date()}
16+
culled={cullingDate}
17+
staleWarning={warningDate}
18+
render={({ msg }) => (<React.Fragment>{msg}</React.Fragment>)}>
19+
</CullingInformation>
20+
</StackItem>
21+
22+
<StackItem>
23+
<CullingInformation
24+
stale={staleDate}
25+
currDate={new Date()}
26+
culled={new Date('Fri Feb 07 2024')}
27+
staleWarning={new Date('Mon Feb 03 2024')}
28+
render={() => (<React.Fragment>This is an error message. Item is past due</React.Fragment>)}>
29+
</CullingInformation>
30+
</StackItem>
31+
</Stack>
32+
33+
34+
1735
</>
1836
};
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import React from 'react';
22
import CullingInformation from '@patternfly/react-component-groups/dist/dynamic/CullingInfo';
3+
import { Stack, StackItem } from '@patternfly/react-core';
34

45
export const BasicExample: React.FunctionComponent = () => {
56
const staleDate = new Date('Sun Jan 26 2020');
67
const warningDate = new Date('Mon Feb 03 2025');
78
const cullingDate = new Date('Fri Feb 07 2025');
89
return <>
9-
<CullingInformation
10-
stale={staleDate}
11-
currDate={new Date()}
12-
culled={cullingDate}
13-
staleWarning={warningDate}>
14-
</CullingInformation>
10+
<Stack>
11+
<StackItem>
12+
<CullingInformation
13+
stale={staleDate}
14+
currDate={new Date()}
15+
culled={cullingDate}
16+
staleWarning={warningDate}>
17+
</CullingInformation>
18+
</StackItem>
19+
20+
<StackItem>
21+
<CullingInformation
22+
stale={staleDate}
23+
currDate={new Date()}
24+
culled={new Date('Fri Feb 07 2024')}
25+
staleWarning={new Date('Mon Feb 03 2024')}
26+
>
27+
</CullingInformation>
28+
</StackItem>
29+
</Stack>
30+
31+
1532
</>
1633
};

packages/module/src/CullingInfo/CullingInfo.tsx

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,39 @@ import { ExclamationCircleIcon, ExclamationTriangleIcon } from '@patternfly/reac
33
import { Tooltip, TooltipProps } from '@patternfly/react-core';
44
import clsx from 'clsx';
55
import { 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

1023
const 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 */
2739
export 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

4458
const 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
}

packages/module/src/CullingInfo/CullingInfoUtils.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)