-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# What this PR does #118 ## Checklist - [x] Tests updated - [ ] Documentation added - [x] `CHANGELOG.md` updated
- Loading branch information
Showing
28 changed files
with
1,135 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/components/ScheduleQuality/ScheduleQuality.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
$score-primary: rgba(27, 133, 94, 0.15); | ||
$score-warning: rgba(245, 183, 61, 0.18); | ||
$score-danger: rgba(209, 14, 92, 0.15); | ||
|
||
.root { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 5px; | ||
} | ||
|
||
.quality { | ||
line-height: 16px; | ||
} | ||
|
||
.link { | ||
text-decoration: none !important; | ||
} | ||
|
||
.tag { | ||
font-size: 12px; | ||
padding: 4px 10px 3px 10px; | ||
|
||
&--danger { | ||
background-color: $score-danger; | ||
color: var(--tag-text-danger); | ||
border: 1px solid var(--tag-border-danger); | ||
} | ||
&--warning { | ||
background-color: $score-warning; | ||
color: var(--tag-text-warning); | ||
border: 1px solid var(--tag-border-warning); | ||
} | ||
&--primary { | ||
background-color: $score-primary; | ||
color: var(--tag-text-success); | ||
border: 1px solid var(--tag-border-success); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,131 @@ | ||
import React, { FC, useCallback, useState } from 'react'; | ||
import React, { FC, useEffect, useState } from 'react'; | ||
|
||
import { HorizontalGroup, VerticalGroup, Icon, IconButton, Tooltip } from '@grafana/ui'; | ||
import { Tooltip, VerticalGroup } from '@grafana/ui'; | ||
import cn from 'classnames/bind'; | ||
|
||
import PluginLink from 'components/PluginLink/PluginLink'; | ||
import ScheduleCounter from 'components/ScheduleCounter/ScheduleCounter'; | ||
import { ScheduleQualityDetails } from 'components/ScheduleQualityDetails/ScheduleQualityDetails'; | ||
import Tag from 'components/Tag/Tag'; | ||
import Text from 'components/Text/Text'; | ||
import { Schedule, ScheduleScoreQualityResponse, ScheduleScoreQualityResult } from 'models/schedule/schedule.types'; | ||
import { useStore } from 'state/useStore'; | ||
|
||
import styles from './ScheduleQuality.module.css'; | ||
import styles from './ScheduleQuality.module.scss'; | ||
|
||
const cx = cn.bind(styles); | ||
|
||
interface ScheduleQualityProps { | ||
quality: number; | ||
schedule: Schedule; | ||
lastUpdated: number; | ||
} | ||
|
||
const cx = cn.bind(styles); | ||
const ScheduleQuality: FC<ScheduleQualityProps> = ({ schedule, lastUpdated }) => { | ||
const { scheduleStore } = useStore(); | ||
const [qualityResponse, setQualityResponse] = useState<ScheduleScoreQualityResponse>(undefined); | ||
|
||
const ScheduleQuality: FC<ScheduleQualityProps> = (props) => { | ||
const { quality } = props; | ||
useEffect(() => { | ||
if (schedule.id) { | ||
fetchScoreQuality(); | ||
} | ||
}, [schedule.id, lastUpdated]); | ||
|
||
return ( | ||
<Tooltip placement="bottom-end" interactive content={<SheduleQualityDetails quality={quality} />}> | ||
<div className={cx('root')}> | ||
<HorizontalGroup spacing="sm"> | ||
<Text type="secondary">Quality:</Text> | ||
<Text type="primary">{Math.floor(quality * 100)}%</Text> | ||
</HorizontalGroup> | ||
</div> | ||
</Tooltip> | ||
); | ||
}; | ||
if (!qualityResponse) { | ||
return null; | ||
} | ||
|
||
interface ScheduleQualityDetailsProps { | ||
quality: number; | ||
} | ||
const relatedEscalationChains = scheduleStore.relatedEscalationChains[schedule.id]; | ||
|
||
const SheduleQualityDetails = (props: ScheduleQualityDetailsProps) => { | ||
const { quality } = props; | ||
return ( | ||
<> | ||
<div className={cx('root')}> | ||
{relatedEscalationChains?.length > 0 && schedule?.number_of_escalation_chains > 0 && ( | ||
<ScheduleCounter | ||
type="link" | ||
addPadding | ||
count={schedule.number_of_escalation_chains} | ||
tooltipTitle="Used in escalations" | ||
tooltipContent={ | ||
<VerticalGroup spacing="sm"> | ||
{relatedEscalationChains.map((escalationChain) => ( | ||
<div key={escalationChain.pk}> | ||
<PluginLink query={{ page: 'escalations', id: escalationChain.pk }} className={cx('link')}> | ||
<Text type="link">{escalationChain.name}</Text> | ||
</PluginLink> | ||
</div> | ||
))} | ||
</VerticalGroup> | ||
} | ||
/> | ||
)} | ||
|
||
const [expanded, setExpanded] = useState<boolean>(false); | ||
{schedule.warnings?.length > 0 && ( | ||
<ScheduleCounter | ||
type="warning" | ||
addPadding | ||
count={schedule.warnings.length} | ||
tooltipTitle="Warnings" | ||
tooltipContent={ | ||
<VerticalGroup spacing="none"> | ||
{schedule.warnings.map((warning, index) => ( | ||
<Text type="primary" key={index}> | ||
{warning} | ||
</Text> | ||
))} | ||
</VerticalGroup> | ||
} | ||
/> | ||
)} | ||
|
||
const type = quality > 0.8 ? 'success' : 'warning'; | ||
<Tooltip | ||
placement="bottom-start" | ||
interactive | ||
content={ | ||
<ScheduleQualityDetails quality={qualityResponse} getScheduleQualityString={getScheduleQualityString} /> | ||
} | ||
> | ||
<div className={cx('u-cursor-default')}> | ||
<Tag className={cx('tag', getTagClass())}> | ||
Quality: <strong>{getScheduleQualityString(qualityResponse.total_score)}</strong> | ||
</Tag> | ||
</div> | ||
</Tooltip> | ||
</div> | ||
</> | ||
); | ||
|
||
const qualityPercent = quality * 100; | ||
function getScheduleQualityString(score: number): ScheduleScoreQualityResult { | ||
if (score < 20) { | ||
return ScheduleScoreQualityResult.Bad; | ||
} | ||
if (score < 40) { | ||
return ScheduleScoreQualityResult.Low; | ||
} | ||
if (score < 60) { | ||
return ScheduleScoreQualityResult.Medium; | ||
} | ||
if (score < 80) { | ||
return ScheduleScoreQualityResult.Good; | ||
} | ||
return ScheduleScoreQualityResult.Great; | ||
} | ||
|
||
const handleExpandClick = useCallback(() => { | ||
setExpanded((expanded) => !expanded); | ||
}, []); | ||
async function fetchScoreQuality() { | ||
await Promise.all([ | ||
scheduleStore.getScoreQuality(schedule.id).then((qualityResponse) => setQualityResponse(qualityResponse)), | ||
scheduleStore.updateRelatedEscalationChains(schedule.id), | ||
]); | ||
} | ||
|
||
return ( | ||
<div className={cx('details')}> | ||
<VerticalGroup> | ||
<Text type="secondary">Schedule quality</Text> | ||
<div className={cx('progress')}> | ||
<div | ||
style={{ width: `${qualityPercent}%` }} | ||
className={cx('progress-filler', { | ||
[`progress-filler__type_${type}`]: true, | ||
})} | ||
> | ||
<div | ||
className={cx('quality-text', { | ||
[`quality-text__type_${type}`]: true, | ||
})} | ||
> | ||
{qualityPercent}% | ||
</div>{' '} | ||
</div> | ||
</div> | ||
{type === 'success' && ( | ||
<Text type="primary"> | ||
You are doing a great job! <br /> | ||
Schedule is well balanced for all members. | ||
</Text> | ||
)} | ||
{type === 'warning' && <Text type="primary">Your schedule has balance problems.</Text>} | ||
<hr style={{ width: '100%' }} /> | ||
<VerticalGroup> | ||
<HorizontalGroup justify="space-between"> | ||
<HorizontalGroup spacing="sm"> | ||
<Icon name="info-circle" /> | ||
<Text type="secondary">Calculation methodology</Text> | ||
</HorizontalGroup> | ||
<IconButton name="angle-down" onClick={handleExpandClick} /> | ||
</HorizontalGroup> | ||
{expanded && ( | ||
<Text type="secondary"> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer elementum purus egestas porta ultricies. | ||
Sed quis maximus sem. Phasellus semper pulvinar sapien ac euismod. | ||
</Text> | ||
)} | ||
</VerticalGroup> | ||
</VerticalGroup> | ||
</div> | ||
); | ||
function getTagClass() { | ||
if (qualityResponse?.total_score < 20) { | ||
return 'tag--danger'; | ||
} | ||
if (qualityResponse?.total_score < 60) { | ||
return 'tag--warning'; | ||
} | ||
return 'tag--primary'; | ||
} | ||
}; | ||
|
||
export default ScheduleQuality; |
Oops, something went wrong.