Skip to content

Commit f9e360e

Browse files
committed
chore: centralized icon rendering tool
Signed-off-by: Vladimir Belousov <vbelouso@redhat.com>
1 parent b076a47 commit f9e360e

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

src/app/Overview/components/ActivityTable.tsx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,14 @@ import { EmptyState } from '@patternfly/react-core';
44
import { SystemEventResponseApi } from '@api';
55
import { Link } from 'react-router-dom';
66
import { resolveResourcePath } from '@app/utils/parseFuncs';
7-
import { CheckCircleIcon, ErrorCircleOIcon, WarningTriangleIcon, InboxIcon } from '@patternfly/react-icons';
7+
import { InboxIcon } from '@patternfly/react-icons';
8+
import { getResultIcon } from '@app/utils/renderUtils';
9+
import { ResultStatus } from '@app/types/types';
810

911
interface ActivityTableProps {
1012
events: SystemEventResponseApi[];
1113
}
1214

13-
const getResultIcon = (result: string) => {
14-
const PATTERNFLY_COLORS = {
15-
success: 'var(--pf-t--global--color--status--success--default)',
16-
danger: 'var(--pf-t--global--color--status--danger--default)',
17-
warning: 'var(--pf-t--global--color--status--warning--default)',
18-
} as const;
19-
20-
switch (result.toLowerCase()) {
21-
case 'ok':
22-
case 'success':
23-
return <CheckCircleIcon color={PATTERNFLY_COLORS.success} />;
24-
case 'failed':
25-
case 'failure':
26-
case 'error':
27-
return <ErrorCircleOIcon color={PATTERNFLY_COLORS.danger} />;
28-
case 'warning':
29-
case 'partial':
30-
case 'pending':
31-
return <WarningTriangleIcon color={PATTERNFLY_COLORS.warning} />;
32-
default:
33-
return <WarningTriangleIcon color={PATTERNFLY_COLORS.warning} />;
34-
}
35-
};
36-
3715
export const ActivityTable: React.FunctionComponent<ActivityTableProps> = ({ events }) => {
3816
if (events.length === 0) {
3917
return <EmptyState headingLevel="h4" icon={InboxIcon} titleText="No recent events"></EmptyState>;
@@ -56,7 +34,7 @@ export const ActivityTable: React.FunctionComponent<ActivityTableProps> = ({ eve
5634
<Td>{event.timestamp ? new Date(event.timestamp).toLocaleString('es-ES') : '-'}</Td>
5735
<Td>{event.action}</Td>
5836
<Td>
59-
{getResultIcon(event.result)} {event.result}
37+
{getResultIcon(event.result as ResultStatus)} {event.result}
6038
</Td>
6139
<Td>
6240
<Link to={resolveResourcePath(event.resourceType ?? '-', event.resourceId ?? '-')}>

src/app/utils/renderUtils.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ActionTypes, ActionStatus, ActionOperations, ResultStatus } from '@app/types/types';
32
import { ResourceStatusApi } from '@api';
43
import { Label } from '@patternfly/react-core';
@@ -67,15 +66,19 @@ export const getResultIcon = (result: ResultStatus) => {
6766
return (
6867
{
6968
[ResultStatus.Success]: (
70-
<InfoCircleIcon color="var(--pf-t--global--icon--color--status--success)" title="Success" />
69+
<InfoCircleIcon color="var(--pf-t--global--color--status--success--default)" title="Success" />
70+
),
71+
[ResultStatus.Running]: (
72+
<OnRunningIcon color="var(--pf-t--global--color--status--info--default)" title="Running" />
73+
),
74+
[ResultStatus.Pending]: (
75+
<PendingIcon color="var(--pf-t--global--color--status--warning--default)" title="Pending" />
7176
),
72-
[ResultStatus.Running]: <OnRunningIcon color="var(--pf-t--global--icon--color--status--info)" title="Running" />,
73-
[ResultStatus.Pending]: <PendingIcon color="var(--pf-t--global--icon--color--status--warning)" title="Pending" />,
7477
[ResultStatus.Failed]: (
75-
<ExclamationTriangleIcon color="var(--pf-t--global--icon--color--status--danger)" title="Error" />
78+
<ExclamationTriangleIcon color="var(--pf-t--global--color--status--danger--default)" title="Error" />
7679
),
7780
[ResultStatus.Warning]: (
78-
<ExclamationCircleIcon color="var(--pf-t--global--icon--color--status--warning)" title="Warning" />
81+
<ExclamationCircleIcon color="var(--pf-t--global--color--status--warning--default)" title="Warning" />
7982
),
8083
[ResultStatus.Unknown]: <UnknownIcon color="gray" title="Unknown" />,
8184
}[result] || <UnknownIcon color="gray" title="Unknown" />

0 commit comments

Comments
 (0)