Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 4d29d3a

Browse files
committed
Refactoring TotalHours.tsx
1 parent a4204b1 commit 4d29d3a

File tree

3 files changed

+78
-17
lines changed

3 files changed

+78
-17
lines changed

src/screens/hours/HoursScreen.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export default observer(function HoursView() {
4646
return (
4747
<Layout className={classes.hours}>
4848
<Space direction="vertical">
49-
{`${process.env.NODE_ENV} ${process.env.NODE_ENV === 'production'}`}
5049
<SelectDate date={date} onChange={setDate} />
5150
<TotalHours timeItems={timeItems} />
5251
<div className={classes.cards}>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { createUseStyles } from 'react-jss';
3+
import clsx from 'clsx';
4+
import { Tooltip } from 'antd';
5+
6+
export interface ILabelWithTooltipProps {
7+
icon?: string;
8+
label: string;
9+
tooltip: string;
10+
}
11+
12+
const LabelWithTooltip: React.VFC<ILabelWithTooltipProps> = (
13+
props: ILabelWithTooltipProps
14+
) => {
15+
const { icon, label, tooltip } = props;
16+
const classes = useStyles();
17+
18+
return (
19+
<Tooltip title={tooltip} placement="bottom">
20+
<div className={classes.iconAndLabel}>
21+
{icon && <span className={clsx('mi', icon, classes.icon)} />}
22+
<span>{label}</span>
23+
</div>
24+
</Tooltip>
25+
);
26+
};
27+
28+
const useStyles = createUseStyles({
29+
iconAndLabel: {
30+
display: 'flex',
31+
alignItems: 'center',
32+
},
33+
icon: {
34+
fontSize: 18,
35+
color: '#5f6368',
36+
marginRight: 4,
37+
},
38+
});
39+
40+
export default LabelWithTooltip;

src/screens/hours/components/TotalHours/TotalHours.tsx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { observer } from 'mobx-react';
3-
import { Space } from 'antd';
3+
import { Space, Tooltip } from 'antd';
44

55
import * as TaskHooks from '../../../../hooks/TaskHooks';
66
import TaskTimeItemModel from '../../../../models/TaskTimeItemModel';
@@ -12,6 +12,7 @@ import {
1212
} from '../../../../helpers/DateTime';
1313
import { createUseStyles } from 'react-jss';
1414
import clsx from 'clsx';
15+
import LabelWithTooltip, { ILabelWithTooltipProps } from './LabelWithTooltip';
1516

1617
interface TotalHoursProps {
1718
timeItems: TaskTimeItemModel[];
@@ -33,29 +34,50 @@ const TotalHours = observer((props: TotalHoursProps) => {
3334
return null;
3435
}
3536

37+
const items: ILabelWithTooltipProps[] = [
38+
{
39+
label: getTime(startWorkingTime),
40+
tooltip: 'Start time',
41+
},
42+
{
43+
icon: 'mi-work-outline',
44+
label: msToTime(durationMs, false),
45+
tooltip: 'Working hours',
46+
},
47+
{
48+
icon: 'mi-local-cafe',
49+
label: msToTime(gapsMs, false),
50+
tooltip: 'Rest hours',
51+
},
52+
{
53+
icon: 'mi-notifications',
54+
label: getTime(estimatedWorkingTimeEnd),
55+
tooltip: 'Estimated end of working hours',
56+
},
57+
{
58+
label: msToTime(restHoursMs, false),
59+
tooltip: 'Left to work',
60+
},
61+
];
62+
3663
return (
37-
<Space>
38-
<span>{getTime(startWorkingTime)}</span>
39-
<div>
40-
<span className={clsx('mi mi-work-outline', classes.icon)} />
41-
<span>{msToTime(durationMs, false)}</span>
42-
</div>
43-
<div>
44-
<span className={clsx('mi mi-local-cafe', classes.icon)} />
45-
<span>{msToTime(gapsMs, false)}</span>
46-
</div>
47-
<div>
48-
<span className={clsx('mi mi-notifications', classes.icon)} />
49-
<span>{getTime(estimatedWorkingTimeEnd)}</span>
50-
</div>
51-
<span>{msToTime(restHoursMs, false)}</span>
64+
<Space size="middle">
65+
{items.map((props, index) => (
66+
<LabelWithTooltip key={index} {...props} />
67+
))}
5268
</Space>
5369
);
5470
});
5571

5672
const useStyle = createUseStyles({
73+
iconAndLabel: {
74+
display: 'flex',
75+
alignItems: 'center',
76+
},
5777
icon: {
5878
fontSize: 18,
79+
color: '#5f6368',
80+
marginRight: 4,
5981
},
6082
});
6183

0 commit comments

Comments
 (0)