Skip to content

A local-first personal finance app

[AI] Long note values will show a full tooltip on hover in the transactions table (#8759)

DavidGrinberg935d2b5064e0
diff --git a/packages/desktop-client/e2e/transactions.test.ts b/packages/desktop-client/e2e/transactions.test.ts
index d9961d675e..1495fcfdaf 100644
--- a/packages/desktop-client/e2e/transactions.test.ts
+++ b/packages/desktop-client/e2e/transactions.test.ts
@@ -290,6 +290,41 @@ test.describe('Transactions', () => {
await expect(page).toMatchThemeScreenshots();
});
+ test.describe('notes tooltip', () => {
+ test('shows the full note and its tags only when the note is truncated', async () => {
+ const longNote =
+ 'This is a deliberately long note about a grocery run that should overflow the notes column and get truncated with an ellipsis #groceries at the very end of the note text.';
+
+ await accountPage.createSingleTransaction({
+ payee: 'Home Depot',
+ notes: longNote,
+ });
+ await accountPage.createSingleTransaction({
+ payee: 'Kroger',
+ notes: 'short note',
+ });
+
+ const truncatedNotes = accountPage.getNthTransaction(1).notes;
+ const shortNotes = accountPage.getNthTransaction(0).notes;
+
+ // A short note that fits in the column never shows a tooltip, even
+ // after waiting past the tooltip's hover delay.
+ await shortNotes.hover();
+ await page.waitForTimeout(700);
+ await expect(page.getByRole('tooltip')).not.toBeVisible();
+
+ // A truncated note shows the full text, with tags rendered as pills,
+ // in a tooltip.
+ await truncatedNotes.hover();
+ const tooltip = page.getByRole('tooltip');
+ await expect(tooltip).toBeVisible();
+ await expect(tooltip).toContainText(longNote);
+ await expect(
+ tooltip.getByRole('button', { name: '#groceries' }),
+ ).toBeVisible();
+ });
+ });
+
test.describe('column manager', () => {
test('hides and reorders columns', async () => {
const header = page.getByTestId('transaction-table-header');
diff --git a/packages/desktop-client/src/components/table.tsx b/packages/desktop-client/src/components/table.tsx
index 95be609fb9..a30f1cc65b 100644
--- a/packages/desktop-client/src/components/table.tsx
+++ b/packages/desktop-client/src/components/table.tsx
@@ -125,14 +125,13 @@ export const Field = forwardRef<HTMLDivElement, FieldProps>(function Field(
);
});
-export function UnexposedCellContent({
- value,
- formatter,
- style,
- ...props
-}: Pick<CellProps, 'value' | 'formatter' | 'style'>) {
+export const UnexposedCellContent = forwardRef<
+ HTMLSpanElement,
+ Pick<CellProps, 'value' | 'formatter' | 'style'>
+>(function UnexposedCellContent({ value, formatter, style, ...props }, ref) {
return (
<Text
+ innerRef={ref}
style={{
flexGrow: 1,
whiteSpace: 'nowrap',
@@ -145,7 +144,7 @@ export function UnexposedCellContent({
{formatter ? formatter(value) : value}
</Text>
);
-}
+});
type CellProps = Omit<ComponentProps<typeof View>, 'children' | 'value'> & {
formatter?: (value: string, type?: unknown) => string | JSX.Element;
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
index 655ca89337..3444aec54f 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
@@ -23,6 +23,7 @@ import type {
TransactionEntity,
} from '@actual-app/core/types/models';
import {
+ act,
fireEvent,
render,
renderHook,
@@ -1747,6 +1748,85 @@ describe('Transactions', () => {
expect(getTransactions()[2].notes).toBe('spending on #coffee');
});
});
+
+ describe('Notes tooltip', () => {
+ // jsdom doesn't lay out elements, so scrollWidth/clientWidth are always
+ // 0. Stub them so the truncation check has something meaningful to read.
+ let isOverflowing = false;
+ const originalScrollWidth = Object.getOwnPropertyDescriptor(
+ Element.prototype,
+ 'scrollWidth',
+ )!;
+ const originalClientWidth = Object.getOwnPropertyDescriptor(
+ Element.prototype,
+ 'clientWidth',
+ )!;
+
+ beforeAll(() => {
+ Object.defineProperty(Element.prototype, 'scrollWidth', {
+ configurable: true,
+ get() {
+ return isOverflowing ? 200 : 100;
+ },
+ });
+ Object.defineProperty(Element.prototype, 'clientWidth', {
+ configurable: true,
+ get() {
+ return 100;
+ },
+ });
+ });
+
+ afterAll(() => {
+ Object.defineProperty(
+ Element.prototype,
+ 'scrollWidth',
+ originalScrollWidth,
+ );
+ Object.defineProperty(
+ Element.prototype,
+ 'clientWidth',
+ originalClientWidth,
+ );
+ });
+
+ test('shows the full note and renders tags when the note is truncated', async () => {
+ isOverflowing = true;
+ const transactions = generateTransactions(1);
+ transactions[0].notes =
+ 'a very long note about weekend spending #groceries that overflows the column';
+
+ const { container } = renderTransactions({ transactions });
+ const notesText = queryField(container, 'notes', 'span', 0);
+
+ await userEvent.hover(notesText);
+
+ const tooltip = await screen.findByRole('tooltip', {}, { timeout: 1000 });
+ expect(tooltip.textContent).toContain(
+ 'a very long note about weekend spending',
+ );
+ expect(
+ within(tooltip).getByRole('button', { name: '#groceries' }),
+ ).toBeInTheDocument();
+ });
+
+ test('does not show a tooltip when the note fits without truncation', async () => {
+ isOverflowing = false;
+ const transactions = generateTransactions(1);
+ transactions[0].notes = 'short note';
+
+ const { container } = renderTransactions({ transactions });
+ const notesText = queryField(container, 'notes', 'span', 0);
+
+ await userEvent.hover(notesText);
+
+ // Wait past the tooltip's hover delay to make sure it never opens
+ await act(async () => {
+ await new Promise(resolve => setTimeout(resolve, 700));
+ });
+ expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
+ });
+ });
});
describe('useAmountColumnWidths', () => {
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index ee58a28547..e92e618d62 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -5,6 +5,7 @@ import {
memo,
useCallback,
useEffect,
+ useLayoutEffect,
useMemo,
useRef,
useState,
@@ -127,6 +128,7 @@ import { useLocalPref } from '#hooks/useLocalPref';
import { useMergedRefs } from '#hooks/useMergedRefs';
import { usePrevious } from '#hooks/usePrevious';
import { useProperFocus } from '#hooks/useProperFocus';
+import { useResizeObserver } from '#hooks/useResizeObserver';
import { useSelectedDispatch, useSelectedItems } from '#hooks/useSelected';
import { SheetNameProvider } from '#hooks/useSheetName';
import { useSplitsExpanded } from '#hooks/useSplitsExpanded';
@@ -2235,12 +2237,26 @@ function NotesCell({
onClickTag,
onExpose,
}: NotesCellProps) {
- const cellRef = useRef<HTMLDivElement | null>(null);
const [inputValue, setInputValue] = useState(note);
useEffect(() => {
setInputValue(note);
}, [note, setInputValue]);
+ const textRef = useRef<HTMLSpanElement | null>(null);
+ const [isTruncated, setIsTruncated] = useState(false);
+ const checkTruncated = useCallback(() => {
+ const el = textRef.current;
+ setIsTruncated(el != null && el.scrollWidth > el.clientWidth);
+ }, []);
+ const resizeRef = useResizeObserver<HTMLSpanElement>(checkTruncated);
+ const setTextRef = useCallback(
+ (el: HTMLSpanElement | null) => {
+ textRef.current = el;
+ resizeRef(el as HTMLSpanElement);
+ },
+ [resizeRef],
+ );
+
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Enter' || e.key === 'Tab') {
onUpdate(inputValue);
@@ -2251,9 +2267,12 @@ function NotesCell({
const displayedNote = note || scheduleNote || '';
+ useLayoutEffect(() => {
+ checkTruncated();
+ }, [displayedNote, checkTruncated]);
+
return (
<CustomCell
- innerRef={cellRef}
width="flex"
name="notes"
value={displayedNote}
@@ -2267,6 +2286,25 @@ function NotesCell({
onUpdate={onUpdate}
onKeyDown={onKeyDown}
onBlur={() => onUpdate(inputValue)}
+ unexposedContent={props => (
+ <Tooltip
+ content={
+ <View style={{ padding: 10, maxWidth: 400 }}>
+ <Text style={{ whiteSpace: 'pre-wrap' }}>
+ <NotesTagFormatter
+ notes={displayedNote}
+ onNotesTagClick={onClickTag}
+ />
+ </Text>
+ </View>
+ }
+ style={{ ...styles.tooltip }}
+ placement="bottom start"
+ triggerProps={{ delay: 500, isDisabled: !isTruncated }}
+ >
+ <UnexposedCellContent {...props} ref={setTextRef} />
+ </Tooltip>
+ )}
>
{({ inputStyle, onKeyDown, onBlur }) => (
<TagAutocomplete
diff --git a/packages/desktop-client/src/setupTests.ts b/packages/desktop-client/src/setupTests.ts
index f3068cb8c7..48c3840b60 100644
--- a/packages/desktop-client/src/setupTests.ts
+++ b/packages/desktop-client/src/setupTests.ts
@@ -6,6 +6,21 @@ import { resetTestProviders } from './mocks';
global.IS_TESTING = true;
global.Actual = {} as typeof global.Actual;
+// jsdom doesn't implement ResizeObserver. Components that only use it to
+// react to layout changes (rather than asserting on it) can run against a
+// no-op stub.
+global.ResizeObserver = class {
+ observe() {
+ // no-op
+ }
+ unobserve() {
+ // no-op
+ }
+ disconnect() {
+ // no-op
+ }
+};
+
type Size = { height: number; width: number };
type AutoSizerProps = {
diff --git a/upcoming-release-notes/tx-notes-tooltip.md b/upcoming-release-notes/tx-notes-tooltip.md
new file mode 100644
index 0000000000..030ca5b56a
--- /dev/null
+++ b/upcoming-release-notes/tx-notes-tooltip.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [DavidGrinberg]
+---
+
+Notes which are long enough to be truncated in the transaction table can now be hovered over to show a tooltip with the full contents of the note.