UI : Add Feedback text for kpi (#8871)

* UI : Add Feedback text for kpi

* Add util method for kpi result feedback.

* Address comment
This commit is contained in:
Sachin Chaurasiya 2022-11-18 17:58:16 +05:30 committed by GitHub
parent eb55a2a20e
commit e3ea6d0699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 10 deletions

View File

@ -205,12 +205,12 @@ const KPIChart: FC<Props> = ({ chartFilter }) => {
{kpiList.length ? ( {kpiList.length ? (
<Row> <Row>
{!isUndefined(kpiLatestResults) && !isEmpty(kpiLatestResults) && ( {!isUndefined(kpiLatestResults) && !isEmpty(kpiLatestResults) && (
<Col span={6}> <Col span={5}>
<KPILatestResults kpiLatestResultsRecord={kpiLatestResults} /> <KPILatestResults kpiLatestResultsRecord={kpiLatestResults} />
</Col> </Col>
)} )}
<Col span={18}> <Col span={19}>
<ResponsiveContainer debounce={1} minHeight={400}> <ResponsiveContainer debounce={1} minHeight={400}>
<LineChart data={graphData} margin={BAR_CHART_MARGIN}> <LineChart data={graphData} margin={BAR_CHART_MARGIN}>
<CartesianGrid strokeDasharray="3 3" /> <CartesianGrid strokeDasharray="3 3" />

View File

@ -4,7 +4,7 @@ import { toNumber, uniqueId } from 'lodash';
import React, { FC, useMemo } from 'react'; import React, { FC, useMemo } from 'react';
import { KpiTargetType } from '../../generated/api/dataInsight/kpi/createKpiRequest'; import { KpiTargetType } from '../../generated/api/dataInsight/kpi/createKpiRequest';
import { UIKpiResult } from '../../interface/data-insight.interface'; import { UIKpiResult } from '../../interface/data-insight.interface';
import { pluralize } from '../../utils/CommonUtils'; import { getKpiResultFeedback } from '../../utils/DataInsightUtils';
import { getNumberOfDaysForTimestamp } from '../../utils/TimeUtils'; import { getNumberOfDaysForTimestamp } from '../../utils/TimeUtils';
interface Props { interface Props {
@ -46,6 +46,10 @@ const KPILatestResults: FC<Props> = ({ kpiLatestResultsRecord }) => {
// value for number metric // value for number metric
const calculatedNumberValue = (targetValue / targetMetValue) * 100; const calculatedNumberValue = (targetValue / targetMetValue) * 100;
const daysLeft = getNumberOfDaysForTimestamp(resultData.endDate);
const isTargetMet = targetResult.targetMet;
return ( return (
<Space className="w-full" direction="vertical" key={uniqueId()}> <Space className="w-full" direction="vertical" key={uniqueId()}>
<Typography.Text className="data-insight-label-text"> <Typography.Text className="data-insight-label-text">
@ -63,14 +67,10 @@ const KPILatestResults: FC<Props> = ({ kpiLatestResultsRecord }) => {
percent={ percent={
isPercentage ? calculatedPercentage : calculatedNumberValue isPercentage ? calculatedPercentage : calculatedNumberValue
} }
showInfo={false} showInfo={isTargetMet}
/> />
<Typography.Text> <Typography.Text className="data-insight-label-text">
{pluralize( {getKpiResultFeedback(daysLeft, Boolean(isTargetMet))}
getNumberOfDaysForTimestamp(resultData.endDate),
'day'
)}{' '}
left
</Typography.Text> </Typography.Text>
</Space> </Space>
); );

View File

@ -282,6 +282,10 @@
"insights": "Insights", "insights": "Insights",
"govern": "Govern", "govern": "Govern",
"usage": "Usage", "usage": "Usage",
"kpi-target-achieved": "Congratulations on achieving your goals!",
"kpi-target-achieved-before-time": "Awesome! Youve reached your target well before time.",
"kpi-target-overdue": "Never mind. Its time to restructure your goals and progress faster.",
"day-left": "{{day}} left",
"edit-connection": "Edit Connection", "edit-connection": "Edit Connection",
"test-connection": "Test Connection", "test-connection": "Test Connection",
"database-name": "Database Name", "database-name": "Database Name",

View File

@ -13,6 +13,7 @@
import { Card, Typography } from 'antd'; import { Card, Typography } from 'antd';
import { RangePickerProps } from 'antd/lib/date-picker'; import { RangePickerProps } from 'antd/lib/date-picker';
import { t } from 'i18next';
import { import {
groupBy, groupBy,
isEmpty, isEmpty,
@ -44,6 +45,7 @@ import {
ChartValue, ChartValue,
DataInsightChartTooltipProps, DataInsightChartTooltipProps,
} from '../interface/data-insight.interface'; } from '../interface/data-insight.interface';
import { pluralize } from './CommonUtils';
import { getFormattedDateFromMilliSeconds } from './TimeUtils'; import { getFormattedDateFromMilliSeconds } from './TimeUtils';
const checkIsPercentageGraph = (dataInsightChartType: DataInsightChartType) => const checkIsPercentageGraph = (dataInsightChartType: DataInsightChartType) =>
@ -505,3 +507,15 @@ export const getKpiTargetValueByMetricType = (
return metricValue; return metricValue;
}; };
export const getKpiResultFeedback = (day: number, isTargetMet: boolean) => {
if (day > 0 && isTargetMet) {
return t('label.kpi-target-achieved-before-time');
} else if (day <= 0 && !isTargetMet) {
return t('label.kpi-target-overdue');
} else if (isTargetMet) {
return t('label.kpi-target-achieved');
} else {
return t('label.day-left', { day: pluralize(day, 'day') });
}
};