From aa12ecd509b22de046042b4231c6e134b37a9a61 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 26 Jan 2025 07:34:36 -0500 Subject: [PATCH] feat: user setting to wrap notification titles Signed-off-by: Adam Setch --- src/renderer/__mocks__/state-mocks.ts | 13 ++++-- .../notifications/NotificationRow.tsx | 12 +++-- .../AccountNotifications.test.tsx.snap | 24 +++++----- .../NotificationRow.test.tsx.snap | 36 +++++++-------- .../settings/AppearanceSettings.test.tsx | 25 +++++++++++ .../settings/AppearanceSettings.tsx | 14 ++++++ src/renderer/context/App.tsx | 13 ++++-- .../__snapshots__/Settings.test.tsx.snap | 45 +++++++++++++++++++ src/renderer/types.ts | 9 ++-- 9 files changed, 146 insertions(+), 45 deletions(-) diff --git a/src/renderer/__mocks__/state-mocks.ts b/src/renderer/__mocks__/state-mocks.ts index a4e7cf584..640110c6e 100644 --- a/src/renderer/__mocks__/state-mocks.ts +++ b/src/renderer/__mocks__/state-mocks.ts @@ -1,13 +1,17 @@ import { type Account, + type AppearanceSettingsState, type AuthState, + type FilterSettingsState, type GitifyState, type GitifyUser, GroupBy, type Hostname, type Link, + type NotificationSettingsState, OpenPreference, type SettingsState, + type SystemSettingsState, Theme, type Token, } from '../types'; @@ -80,16 +84,17 @@ export const mockAuth: AuthState = { export const mockToken = 'token-123-456' as Token; -const mockAppearanceSettings = { +const mockAppearanceSettings: AppearanceSettingsState = { theme: Theme.SYSTEM, zoomPercentage: 100, detailedNotifications: true, showPills: true, showNumber: true, showAccountHeader: false, + wrapNotificationTitle: false, }; -const mockNotificationSettings = { +const mockNotificationSettings: NotificationSettingsState = { groupBy: GroupBy.REPOSITORY, fetchAllNotifications: true, participating: false, @@ -98,7 +103,7 @@ const mockNotificationSettings = { delayNotificationState: false, }; -const mockSystemSettings = { +const mockSystemSettings: SystemSettingsState = { openLinks: OpenPreference.FOREGROUND, keyboardShortcut: true, showNotificationsCountInTray: true, @@ -108,7 +113,7 @@ const mockSystemSettings = { openAtStartup: false, }; -const mockFilters = { +const mockFilters: FilterSettingsState = { hideBots: false, filterReasons: [], }; diff --git a/src/renderer/components/notifications/NotificationRow.tsx b/src/renderer/components/notifications/NotificationRow.tsx index 31dd24b1f..0fcfcd6b2 100644 --- a/src/renderer/components/notifications/NotificationRow.tsx +++ b/src/renderer/components/notifications/NotificationRow.tsx @@ -115,7 +115,10 @@ export const NotificationRow: FC = ({ handleNotification()} > @@ -126,10 +129,13 @@ export const NotificationRow: FC = ({ justify="space-between" gap="condensed" title={notificationTitle} - className="text-sm mb-0.5 truncate" + className={cn( + 'mb-0.5', + !settings.wrapNotificationTitle && 'truncate', + )} data-testid="notification-row" > - + {notification.subject.title}
I am a robot and this is a test! @@ -1214,7 +1214,7 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende
Improve the UI @@ -1732,7 +1732,7 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende
I am a robot and this is a test! @@ -2113,7 +2113,7 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende
Improve the UI diff --git a/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap index 33eb3a69f..1be49f0f4 100644 --- a/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap @@ -45,7 +45,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! @@ -429,7 +429,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! @@ -870,7 +870,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! @@ -1205,7 +1205,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! @@ -1597,7 +1597,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! @@ -1932,7 +1932,7 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its
I am a robot and this is a test! diff --git a/src/renderer/components/settings/AppearanceSettings.test.tsx b/src/renderer/components/settings/AppearanceSettings.test.tsx index 6ad51e4e7..19447762b 100644 --- a/src/renderer/components/settings/AppearanceSettings.test.tsx +++ b/src/renderer/components/settings/AppearanceSettings.test.tsx @@ -216,4 +216,29 @@ describe('renderer/routes/components/settings/AppearanceSettings.tsx', () => { expect(updateSetting).toHaveBeenCalledTimes(1); expect(updateSetting).toHaveBeenCalledWith('showAccountHeader', true); }); + + it('should toggle wrap notification title checkbox', async () => { + await act(async () => { + render( + + + + + , + ); + }); + + fireEvent.click(screen.getByTestId('checkbox-wrapNotificationTitle')); + + expect(updateSetting).toHaveBeenCalledTimes(1); + expect(updateSetting).toHaveBeenCalledWith('wrapNotificationTitle', true); + }); }); diff --git a/src/renderer/components/settings/AppearanceSettings.tsx b/src/renderer/components/settings/AppearanceSettings.tsx index 17ec47bbe..a2cfb3210 100644 --- a/src/renderer/components/settings/AppearanceSettings.tsx +++ b/src/renderer/components/settings/AppearanceSettings.tsx @@ -290,6 +290,20 @@ export const AppearanceSettings: FC = () => { updateSetting('showAccountHeader', evt.target.checked) } /> + + + updateSetting('wrapNotificationTitle', evt.target.checked) + } + tooltip={ + + Wrap long notification titles instead of truncating them. + + } + /> ); diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index a9764ead3..bc477aba5 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -16,13 +16,17 @@ import { useNotifications } from '../hooks/useNotifications'; import { type Account, type AccountNotifications, + type AppearanceSettingsState, type AuthState, + type FilterSettingsState, type GitifyError, GroupBy, + type NotificationSettingsState, OpenPreference, type SettingsState, type SettingsValue, type Status, + type SystemSettingsState, Theme, } from '../types'; import type { Notification } from '../typesGitHub'; @@ -65,16 +69,17 @@ export const defaultAuth: AuthState = { user: null, }; -const defaultAppearanceSettings = { +const defaultAppearanceSettings: AppearanceSettingsState = { theme: Theme.SYSTEM, zoomPercentage: 100, detailedNotifications: true, showPills: true, showNumber: true, showAccountHeader: false, + wrapNotificationTitle: false, }; -const defaultNotificationSettings = { +const defaultNotificationSettings: NotificationSettingsState = { groupBy: GroupBy.REPOSITORY, fetchAllNotifications: true, participating: false, @@ -83,7 +88,7 @@ const defaultNotificationSettings = { delayNotificationState: false, }; -const defaultSystemSettings = { +const defaultSystemSettings: SystemSettingsState = { openLinks: OpenPreference.FOREGROUND, keyboardShortcut: true, showNotificationsCountInTray: true, @@ -93,7 +98,7 @@ const defaultSystemSettings = { openAtStartup: false, }; -export const defaultFilters = { +export const defaultFilters: FilterSettingsState = { hideBots: false, filterReasons: [], }; diff --git a/src/renderer/routes/__snapshots__/Settings.test.tsx.snap b/src/renderer/routes/__snapshots__/Settings.test.tsx.snap index 843d8055d..e47d7138d 100644 --- a/src/renderer/routes/__snapshots__/Settings.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/Settings.test.tsx.snap @@ -542,6 +542,51 @@ exports[`renderer/routes/Settings.tsx should render itself & its children 1`] = Show account header
+
+ + +
+ +
+
diff --git a/src/renderer/types.ts b/src/renderer/types.ts index b0ee83ec4..bdcf7ef78 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -66,16 +66,17 @@ export type SettingsState = AppearanceSettingsState & SystemSettingsState & FilterSettingsState; -interface AppearanceSettingsState { +export interface AppearanceSettingsState { theme: Theme; zoomPercentage: number; detailedNotifications: boolean; showAccountHeader: boolean; showPills: boolean; showNumber: boolean; + wrapNotificationTitle: boolean; } -interface NotificationSettingsState { +export interface NotificationSettingsState { groupBy: GroupBy; fetchAllNotifications: boolean; participating: boolean; @@ -84,7 +85,7 @@ interface NotificationSettingsState { delayNotificationState: boolean; } -interface SystemSettingsState { +export interface SystemSettingsState { openLinks: OpenPreference; keyboardShortcut: boolean; showNotificationsCountInTray: boolean; @@ -94,7 +95,7 @@ interface SystemSettingsState { openAtStartup: boolean; } -interface FilterSettingsState { +export interface FilterSettingsState { hideBots: boolean; filterReasons: Reason[]; }