Skip to content
Snippets Groups Projects
Unverified Commit 58eeee82 authored by Matt Fiddaman's avatar Matt Fiddaman Committed by GitHub
Browse files

add goal tooltip to balance in budget table (#3123)

* add goal tooltip to balance in budget table

* release note

* fix long goals over multiple months
parent 6653dca7
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,12 @@ import React, { type ComponentPropsWithoutRef } from 'react'; ...@@ -3,10 +3,12 @@ import React, { type ComponentPropsWithoutRef } from 'react';
import { useFeatureFlag } from '../../hooks/useFeatureFlag'; import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { SvgArrowThinRight } from '../../icons/v1'; import { SvgArrowThinRight } from '../../icons/v1';
import { type CSSProperties } from '../../style'; import { type CSSProperties, theme, styles } from '../../style';
import { Tooltip } from '../common/Tooltip';
import { View } from '../common/View'; import { View } from '../common/View';
import { type Binding } from '../spreadsheet'; import { type Binding } from '../spreadsheet';
import { CellValue } from '../spreadsheet/CellValue'; import { CellValue } from '../spreadsheet/CellValue';
import { useFormat } from '../spreadsheet/useFormat';
import { useSheetValue } from '../spreadsheet/useSheetValue'; import { useSheetValue } from '../spreadsheet/useSheetValue';
import { makeBalanceAmountStyle } from './util'; import { makeBalanceAmountStyle } from './util';
...@@ -50,6 +52,21 @@ export function DefaultCarryoverIndicator({ style }: CarryoverIndicatorProps) { ...@@ -50,6 +52,21 @@ export function DefaultCarryoverIndicator({ style }: CarryoverIndicatorProps) {
); );
} }
function GoalTooltipRow({ children }) {
return (
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
gap: 10,
}}
>
{children}
</div>
);
}
export function BalanceWithCarryover({ export function BalanceWithCarryover({
carryover, carryover,
balance, balance,
...@@ -71,6 +88,34 @@ export function BalanceWithCarryover({ ...@@ -71,6 +88,34 @@ export function BalanceWithCarryover({
isGoalTemplatesEnabled ? goalValue : null, isGoalTemplatesEnabled ? goalValue : null,
longGoalValue === 1 ? balanceValue : budgetedValue, longGoalValue === 1 ? balanceValue : budgetedValue,
); );
const format = useFormat();
const differenceToGoal =
longGoalValue === 1 ? balanceValue - goalValue : budgetedValue - goalValue;
const balanceCellValue = (
<CellValue
{...props}
binding={balance}
type="financial"
getStyle={value =>
makeBalanceAmountStyle(
value,
isGoalTemplatesEnabled ? goalValue : null,
longGoalValue === 1 ? balanceValue : budgetedValue,
)
}
style={{
overflow: 'hidden',
textOverflow: 'ellipsis',
textAlign: 'right',
...(!disabled && {
cursor: 'pointer',
}),
...props.style,
}}
/>
);
return ( return (
<span <span
...@@ -81,27 +126,55 @@ export function BalanceWithCarryover({ ...@@ -81,27 +126,55 @@ export function BalanceWithCarryover({
maxWidth: '100%', maxWidth: '100%',
}} }}
> >
<CellValue {isGoalTemplatesEnabled && goalValue !== null ? (
{...props} <Tooltip
binding={balance} content={
type="financial" <View style={{ padding: 10 }}>
getStyle={value => <span style={{ fontWeight: 'bold' }}>
makeBalanceAmountStyle( {differenceToGoal === 0 ? (
value, <span style={{ color: theme.noticeText }}>Fully funded</span>
isGoalTemplatesEnabled ? goalValue : null, ) : differenceToGoal > 0 ? (
longGoalValue === 1 ? balanceValue : budgetedValue, <span style={{ color: theme.noticeText }}>
) Overfunded ({format(differenceToGoal, 'financial')})
} </span>
style={{ ) : (
overflow: 'hidden', <span style={{ color: theme.errorText }}>
textOverflow: 'ellipsis', Underfunded ({format(differenceToGoal, 'financial')})
textAlign: 'right', </span>
...(!disabled && { )}
cursor: 'pointer', </span>
}), <GoalTooltipRow>
...props.style, <div>Goal Type:</div>
}} <div>{longGoalValue === 1 ? 'Long' : 'Template'}</div>
/> </GoalTooltipRow>
<GoalTooltipRow>
<div>Goal:</div>
<div>{format(goalValue, 'financial')}</div>
</GoalTooltipRow>
<GoalTooltipRow>
{longGoalValue !== 1 ? (
<>
<div>Budgeted:</div>
<div>{format(budgetedValue, 'financial')}</div>
</>
) : (
<>
<div>Balance:</div>
<div>{format(balanceValue, 'financial')}</div>
</>
)}
</GoalTooltipRow>
</View>
}
style={{ ...styles.tooltip, borderRadius: '0px 5px 5px 0px' }}
placement="bottom"
triggerProps={{ delay: 750 }}
>
{balanceCellValue}
</Tooltip>
) : (
balanceCellValue
)}
{carryoverValue && carryoverIndicator({ style: valueStyle })} {carryoverValue && carryoverIndicator({ style: valueStyle })}
</span> </span>
); );
......
---
category: Enhancements
authors: [matt-fidd]
---
Add a goal information tooltip to the balance on the budget table
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment