Repository navigation
Add start/stop timer buttons to the Chronos report header - #86690
Conversation
🦜 Polyglot Parrot! 🦜Squawk! Looks like you added some shiny new English strings. Allow me to parrot them back to you in other tongues: View the translation diffdiff --git a/src/languages/ja.ts b/src/languages/ja.ts
index b2986305..bcf2fe74 100644
--- a/src/languages/ja.ts
+++ b/src/languages/ja.ts
@@ -7522,7 +7522,7 @@ ${reportName}
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary}(${date} までの ${dayCount} ${dayCount === 1 ? '日' : '日数'} 分)`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${date}の${timePeriod}の${summary}`,
startTimer: 'タイマー開始',
- stopTimer: 'タイマー停止',
+ stopTimer: 'タイマーを停止',
},
footer: {
features: '機能',
diff --git a/src/languages/pl.ts b/src/languages/pl.ts
index b194c494..6557c590 100644
--- a/src/languages/pl.ts
+++ b/src/languages/pl.ts
@@ -7580,8 +7580,8 @@ Wymagaj szczegółów wydatków, takich jak paragony i opisy, ustawiaj limity i
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} za ${dayCount} ${dayCount === 1 ? 'dzień' : 'dni'} do ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} z ${timePeriod} z dnia ${date}`,
- startTimer: 'Uruchom timer',
- stopTimer: 'Zatrzymaj timer',
+ startTimer: 'Startuj licznik',
+ stopTimer: 'Zatrzymaj licznik czasu',
},
footer: {
features: 'Funkcje',
diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts
index 30672141..d6528f75 100644
--- a/src/languages/zh-hans.ts
+++ b/src/languages/zh-hans.ts
@@ -7393,7 +7393,7 @@ ${reportName}
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary},共计 ${dayCount} ${dayCount === 1 ? '天' : '天'},截至 ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary},时间范围:${timePeriod},日期:${date}`,
startTimer: '开始计时',
- stopTimer: '停止计时',
+ stopTimer: '停止计时器',
},
footer: {
features: '功能',
Note You can apply these changes to your branch by copying the patch to your clipboard, then running |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb45a41161
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const CHRONOS_TIMER_COMMAND_STOP_REGEX = /stop(?:ped|ping)?(?:\snow)?/i; | ||
| const CHRONOS_TIMER_COMMAND_START_REGEX = /start(?:ed|ing)?(?:\snow)?/i; |
There was a problem hiding this comment.
Restrict Chronos command matching to standalone commands
isChronosStartOrStopMessage() uses unanchored regexes, so any comment containing substrings like "starting", "nonstop", or "kickstart" is treated as a timer command. getLatestUserChronosTimerCommand() then uses that match to infer timer state, which can flip the header button to the wrong action and send the opposite command on click in normal conversations with Chronos. Match against whole-command text (or at least word-bounded tokens) to avoid false positives.
Useful? React with 👍 / 👎.
|
@ahmedGaber93 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
|
||
| const reportActionsOnyxKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}` as OnyxKey; | ||
| const [sortedVisibleReportActions = getEmptyArray<OnyxTypes.ReportAction>()] = useOnyx<OnyxKey, OnyxTypes.ReportAction[]>( | ||
| reportActionsOnyxKey, |
There was a problem hiding this comment.
❌ PERF-11 (docs)
The useOnyx selector on REPORT_ACTIONS returns a full ReportAction[] array via getSortedReportActionsForDisplay. Onyx runs deepEqual on the selector output to decide whether to re-render, and comparing an entire array of report actions is expensive. Additionally, the selector closes over visibleReportActionsData (the entire VISIBLE_REPORT_ACTIONS for ALL reports), meaning any change to visible actions in ANY report triggers re-execution of this expensive selector.
The component only needs to know whether the timer is running (a boolean). Compute the final boolean directly in the selector instead of returning the full array:
const [isTimerRunning] = useOnyx<OnyxKey, boolean>(
reportActionsOnyxKey,
{
selector: (reportActions: unknown): boolean => {
const sorted = getSortedReportActionsForDisplay(
reportActions as OnyxEntry<ReportActions>,
canPerformWriteAction,
false,
visibleReportActionsData,
report.reportID,
);
return isChronosTimerRunningFromVisibleActions(sorted, currentUserAccountID);
},
},
[canPerformWriteAction, visibleReportActionsData, report.reportID, currentUserAccountID],
);This reduces deepEqual to a trivial boolean comparison and eliminates the intermediate array allocation.
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| notifyReportID: report.reportID, | ||
| ancestors, | ||
| text: isTimerRunning ? 'stop' : 'start', | ||
| timezoneParam: timezoneParam ?? CONST.DEFAULT_TIME_ZONE, |
There was a problem hiding this comment.
❌ CONSISTENCY-2 (docs)
The literal strings 'stop' and 'start' are timer command strings sent as chat messages and also matched by the regexes in ReportActionsUtils.ts. These are domain-specific command values that should be defined as named constants to avoid typos and maintain a single source of truth.
Define constants in CONST, for example:
// In CONST
CHRONOS: {
TIMER_COMMAND: {
START: 'start',
STOP: 'stop',
},
},Then use them in the component:
text: isTimerRunning ? CONST.CHRONOS.TIMER_COMMAND.STOP : CONST.CHRONOS.TIMER_COMMAND.START,And in ReportActionsUtils.ts for comparing return values:
return getLatestUserChronosTimerCommand(...) === CONST.CHRONOS.TIMER_COMMAND.START;Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ee5f2337b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const CHRONOS_TIMER_COMMAND_STOP_REGEX = /\bstop(?:ped|ping)?(?:\s+now)?\b/i; | ||
| const CHRONOS_TIMER_COMMAND_START_REGEX = /\bstart(?:ed|ing)?(?:\s+now)?\b/i; |
There was a problem hiding this comment.
Anchor Chronos timer command matching to whole message
The new command patterns still match any message that contains start/stop as a standalone word, so normal conversation like “I will start later” is interpreted as a timer command and flips the header button state incorrectly. That can make the next tap send the opposite action from what the user expects. Fresh evidence: the new unit test intentionally treats "stop then start" as a valid command, which confirms matching is not restricted to command-only input.
Useful? React with 👍 / 👎.
|
Thanks @ahmedGaber93, that's a good idea! I've added support for those now. |
|
@tgolen I recently noticed from Chronos replay that any sentence containing start or stop is treated as a command.
So all these sentences trigger start/stop tracking: start - start now - started now - started at - have started - I have started Some typos also works: stoped - stopped Should we handle those here? |
|
I also found that on a new account (first time chat with chronos), commands don’t work until the user answers questions like “How many hours per week?”. So sending start doesn’t trigger tracking. Should we update the button text accordingly? 20260402180137315.mp4 |
|
Thanks @ahmedGaber93 I think both of those things are fine to leave as-is for now. This is just a simple feature built for internal use mostly, so I don't think those will really become a factor. |
|
@roryabraham Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
@tgolen All yours! |
|
@tgolen looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here. |
|
Oops, I did not see that. There was a TypeScript error. I will put up a PR to fix that. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.53-0 🚀
Bundle Size Analysis (Sentry): |
|
After reviewing the PR changes and the existing help site articles under Here's my reasoning:
If you'd like a new help site article created specifically for the Chronos timer feature (covering both the chat commands and these new buttons), let me know and I can draft one. |
|
🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.53-0 🚀
Bundle Size Analysis (Sentry): |
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.53-7 🚀
|

Explanation of Change
This PR adds some buttons to the header of the chat with chronos@expensify.com. There is a "Start Timer" and a "Stop Timer" button.
In order to easily determine which button to show, the code looks at the chat history and which commands have been previously sent.
Fixed Issues
$ #86742
Tests
Offline tests
Doesn't really work offline, because it requires Chronos responses.
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps./** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari