Repository navigation
Assignable Keyboard Shortcuts Updates - #4532
Conversation
📝 WalkthroughWalkthroughAdds a keyboard-shortcut configuration system: default shortcuts seeded via migration, library accessors expose defaults and options, admin UI to view/save bindings with validation, controller endpoint to persist changes, and sales views/controllers updated to display and apply configured shortcuts. ChangesKeyboard Shortcut Configuration System
Sequence DiagramsequenceDiagram
actor Admin
participant ConfigUI as Config UI
participant ConfigCtrl as Config Controller
participant DB as Database
participant SalesUI as Sales Register
participant SalesCtrl as Sales Controller
participant SaleLib as Sale_lib
rect rgba(100, 150, 255, 0.5)
Note over Admin,DB: Keyboard Shortcut Configuration Flow
Admin->>ConfigUI: Load shortcuts configuration tab
ConfigUI->>ConfigCtrl: GET config/manage
ConfigCtrl->>SaleLib: getKeyShortcuts()
SaleLib->>DB: Read current key_* values
DB-->>SaleLib: Return configured shortcuts
SaleLib-->>ConfigCtrl: Return parsed shortcuts
ConfigCtrl->>ConfigUI: Render manage view with shortcuts
ConfigUI-->>Admin: Display shortcut configuration form
Admin->>ConfigUI: Update shortcut bindings & submit
ConfigUI->>ConfigCtrl: POST config/saveShortcuts
ConfigCtrl->>ConfigCtrl: Validate against allowed options
ConfigCtrl->>ConfigCtrl: Detect duplicate bindings
alt Validation passes
ConfigCtrl->>DB: batch_save key_* values
DB-->>ConfigCtrl: Save successful
ConfigCtrl-->>ConfigUI: Return JSON success
ConfigUI-->>Admin: Show success notification
else Duplicates detected
ConfigCtrl-->>ConfigUI: Return JSON error
ConfigUI-->>Admin: Show error message
end
end
rect rgba(150, 255, 100, 0.5)
Note over SalesUI,SaleLib: Keyboard Shortcut Usage Flow
SalesCtrl->>SalesCtrl: _reload()
SalesCtrl->>SaleLib: getKeyShortcuts()
SaleLib->>DB: Read current key_* values
DB-->>SaleLib: Return configured shortcuts
SaleLib-->>SalesCtrl: Return parsed shortcuts
SalesCtrl->>SalesUI: Render register with keyboardShortcuts
SalesUI-->>SalesUI: Build shortcutCodes map from config
Admin->>SalesUI: Press ALT + configured key
SalesUI->>SalesUI: onkeyup handler maps code to action
alt Action is "complete"
SalesUI->>SalesUI: Check if payments cover total
alt Payments cover total
SalesUI->>SalesUI: Trigger finish sale
else Insufficient payment
SalesUI->>SalesUI: Trigger add payment
end
else Other action
SalesUI->>SalesUI: Execute mapped action
end
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
app/Views/configs/shortcuts_config.php (1)
7-23: ⚡ Quick win
$shortcut_defaultsduplicatesSale_lib::KEY_SHORTCUT_DEFAULTS— eliminatable.This view re-implements the same default-resolution logic that
Sale_lib::get_key_shortcuts()already provides. Adding a new shortcut in the future requires updating bothSale_lib.phpand this view.The Config controller's
getIndex()should pass the output of$this->sale_lib->get_key_shortcuts()(which already returns resolvedvalue/code/labelper shortcut) so the view can use$keyboard_shortcuts[$name]['value']for the dropdown selection, removing the need for$shortcut_defaultsentirely.♻️ Proposed refactor (view-side change)
In
Config::getIndex(), add alongside$key_shortcuts_options:// (additional code block, not a diff — goes in Config::getIndex()) $data['keyboard_shortcuts'] = $this->sale_lib->get_key_shortcuts();Then in
shortcuts_config.php:-$shortcut_defaults = [ - 'cancel' => '27 | ESC', - 'items' => '49 | ALT + 1', - 'customers' => '50 | ALT + 2', - 'suspend' => '51 | ALT + 3', - 'suspended' => '52 | ALT + 4', - 'amount' => '53 | ALT + 5', - 'payment' => '54 | ALT + 6', - 'complete' => '55 | ALT + 7', - 'finish' => '56 | ALT + 8', - 'help' => '57 | ALT + 9', -]; - -$shortcut_values = []; -foreach ($shortcut_defaults as $name => $default_value) { - $shortcut_values[$name] = $config['key_' . $name] ?? $default_value; -} +/** + * `@var` array $keyboard_shortcuts resolved by Sale_lib::get_key_shortcuts() + */And in the dropdown call:
- $shortcut_values[$name], + $keyboard_shortcuts[$name]['value'] ?? '',🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Views/configs/shortcuts_config.php` around lines 7 - 23, Remove the duplicated $shortcut_defaults and resolution logic in shortcuts_config.php and instead consume the resolved shortcuts provided by Sale_lib::get_key_shortcuts(); update Config::getIndex() to set $data['keyboard_shortcuts'] = $this->sale_lib->get_key_shortcuts(); then in the view replace any use of $shortcut_defaults/$shortcut_values with $keyboard_shortcuts (e.g. use $keyboard_shortcuts[$name]['value'] for the dropdown selection and build any needed mapping from that array), ensuring all references to shortcut names use the keys in $keyboard_shortcuts so the view no longer maintains its own defaults.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Controllers/Config.php`:
- Around line 962-973: Before calling
$this->appconfig->batch_save($batch_save_data) ensure no duplicate shortcut
values exist: after populating $batch_save_data from $current_shortcuts (and
using $this->request->getPost('key_'.$name) and $allowed_shortcuts), scan the
values for duplicates (the 'key_'.$name entries) and if any duplicates are
found, abort and return a validation error response indicating duplicate
shortcut bindings instead of calling batch_save(); this enforces uniqueness
server-side for current_shortcuts and prevents conflicting hotkeys.
In `@app/Database/Migrations/20260506000000_add_shortcut_keys.php`:
- Around line 30-35: The migration's down() is empty so rollback leaves the 10
inserted key_* rows in app_config; implement down() to undo what up() did by
deleting those rows and reversing any schema changes: in the migration class
(methods up() and down()) add logic in down() to remove the inserted app_config
entries (e.g., DB::table('app_config')->where('name', 'LIKE', 'key_%')->delete()
or explicitly whereIn(['key_1',...'key_10'])) and revert any other alterations
made in up() so a migrate:rollback returns the database to its prior state.
In `@app/Views/configs/manage.php`:
- Around line 32-34: The shortcuts child view expects $config but
Config::getIndex() never includes it in the view data; update the getIndex()
method to add the controller's config to the data array (set $data['config'] =
$this->config) before calling view()/render so the shortcuts_config.php child
view can access $config (refer to Config::getIndex(), $data array, and
$this->config).
In `@app/Views/configs/shortcuts_config.php`:
- Around line 86-91: Replace the hardcoded English fallback string used in the
AJAX error handler (the literal 'Unable to save Shortcut Settings.' used with
xhr.responseJSON?.message ?? xhr.responseText ?? ...) with a PHP-rendered
language string; add a key (e.g. "shortcuts_save_error") to the Config language
files (app/Language/*/Config.php) and echo that localized string into the script
block so the fallback becomes the PHP i18n value instead of the hardcoded text.
In `@app/Views/sales/register.php`:
- Around line 868-871: The hotkey handler for keyboardShortcuts.complete.code
currently triggers $("#add_payment_button").click() then immediately sets
window.location.href which can bypass the payment POST; change this to route
through the same form-submit flow used by the UI buttons (i.e., invoke the
payment form's submit handler or trigger the exact submit button/action that
performs the POST and wait for its success callback) instead of hard-redirecting
to site_url('sales/complete'); ensure the code waits for the add-payment
submission to finish (or its success callback) and only then calls the
completion routine or redirects to the completion endpoint.
- Around line 844-883: The shortcut handler dereferences
keyboardShortcuts.<action>.code directly inside document.body.onkeyup, which can
throw if entries are missing; fix by guarding lookups before comparing to
event.keyCode—e.g., in document.body.onkeyup (the Alt branch and the non-Alt
switch) first resolve each code with optional chaining or null-checks (e.g.,
const itemsCode = keyboardShortcuts?.items?.code) and then use those local
variables in the switch/case tests (or skip cases when code is undefined);
ensure all references like keyboardShortcuts.items.code,
keyboardShortcuts.customers.code, keyboardShortcuts.complete.code, etc., are
accessed via the guarded variables so missing shortcuts won’t cause a runtime
TypeError.
---
Nitpick comments:
In `@app/Views/configs/shortcuts_config.php`:
- Around line 7-23: Remove the duplicated $shortcut_defaults and resolution
logic in shortcuts_config.php and instead consume the resolved shortcuts
provided by Sale_lib::get_key_shortcuts(); update Config::getIndex() to set
$data['keyboard_shortcuts'] = $this->sale_lib->get_key_shortcuts(); then in the
view replace any use of $shortcut_defaults/$shortcut_values with
$keyboard_shortcuts (e.g. use $keyboard_shortcuts[$name]['value'] for the
dropdown selection and build any needed mapping from that array), ensuring all
references to shortcut names use the keys in $keyboard_shortcuts so the view no
longer maintains its own defaults.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e3596562-2f35-489e-96b5-5c22305f4e22
📒 Files selected for processing (10)
app/Config/Routes.phpapp/Controllers/Config.phpapp/Controllers/Sales.phpapp/Database/Migrations/20260506000000_add_shortcut_keys.phpapp/Language/en/Config.phpapp/Libraries/Sale_lib.phpapp/Views/configs/manage.phpapp/Views/configs/shortcuts_config.phpapp/Views/sales/help.phpapp/Views/sales/register.php
078414f to
328bde0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/sales/register.php`:
- Around line 408-409: The hidden field complete_after_payment is never
set/consumed, so the Alt+Complete hotkey stops after adding a payment; update
the hotkey handler that triggers `#add_payment_button` to set
complete_after_payment=1 before submitting and modify Sales::postAddPayment() to
read and consume that flag (on successful payment create, proceed to complete
the sale/invoice flow and reset the flag) so the flow continues to completion;
reference the complete_after_payment hidden input, the `#add_payment_button`
handler, and Sales::postAddPayment() when making the changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3317aed0-7209-49d3-94b7-3b0a40d00aa7
📒 Files selected for processing (9)
app/Controllers/Config.phpapp/Controllers/Sales.phpapp/Database/Migrations/20260506000000_AddShortcutKeys.phpapp/Language/en/Config.phpapp/Libraries/Sale_lib.phpapp/Views/configs/manage.phpapp/Views/configs/shortcuts_config.phpapp/Views/sales/help.phpapp/Views/sales/register.php
🚧 Files skipped from review as they are similar to previous changes (1)
- app/Language/en/Config.php
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Controllers/Sales.php`:
- Around line 475-478: The branch that auto-completes a sale when
$complete_after_payment is true unconditionally calls postComplete() even if
prior validation set errors (e.g., $data['error'] from the giftcard or
amount_tendered handling), so change the conditional to only call postComplete()
when there are no validation errors and amount_due is <= 0; specifically check
that empty($data['error']) (or equivalent validation flag) before invoking
postComplete(), and ensure you pass a string to bccomp by casting
$this->sale_lib->get_amount_due() to (string) to avoid implicit conversion
warnings.
In `@app/Views/sales/register.php`:
- Around line 570-571: The inline JSON emitted for keyboardShortcuts and
paymentsCoverTotal is not hardened for script context; update the calls to
json_encode in the register view (the lines setting keyboardShortcuts and
paymentsCoverTotal) to pass JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT |
JSON_HEX_AMP (and ensure a safe default like [] or false is used before
encoding) so characters like </script>, quotes and ampersands are escaped and
cannot break out into stored-XSS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5870b1f-3895-478f-9ae8-d986e8e35437
📒 Files selected for processing (2)
app/Controllers/Sales.phpapp/Views/sales/register.php
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/sales/register.php`:
- Around line 884-889: The complete hotkey handler (shortcutCodes.complete) only
clicks `#finish_sale_button` when paymentsCoverTotal is true, but in non-POS flows
where `#finish_sale_button` is absent it falls back to submitting
`#add_payment_form` which is disabled and calls postAddPayment() incorrectly;
change the logic so when paymentsCoverTotal is true and `#finish_sale_button` does
not exist but `#finish_invoice_quote_button` exists (the active non-POS completion
action), trigger/click `#finish_invoice_quote_button` instead of submitting
`#add_payment_form`, otherwise preserve the existing branch that sets
complete_after_payment and submits `#add_payment_form`; ensure references to
shortcutCodes.complete, paymentsCoverTotal, `#finish_sale_button`,
`#finish_invoice_quote_button`, `#add_payment_form` and postAddPayment() are updated
accordingly.
- Around line 877-879: In the switch branch for shortcutCodes.amount in
register.php, replace the hard-coded selector "#amount_tendered" with a selector
that targets the currently enabled/visible tender input (e.g., the first enabled
input inside the tender inputs container) so the handler focuses and selects the
active tender field instead of a possibly disabled gift-card field; update the
focus/select calls in that case to query for an enabled input under the tender
controls (e.g., first enabled .tender input) and call focus() and select() on
it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 31bb14db-79a8-4efa-853a-2a0f90c5b728
📒 Files selected for processing (2)
app/Controllers/Sales.phpapp/Views/sales/register.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/sales/register.php`:
- Around line 907-910: The cancel shortcut branch in the keyup handler (the
switch on event.keyCode that checks shortcutCodes.cancel and triggers
$("#cancel_sale_button").click()) runs for every bare key and will fire while
typing; change the logic so the configurable cancel binding only triggers when
combined with a modifier (e.g. require event.altKey) or keep Escape as a fixed
cancel (check for keyCode 27) and ignore plain printable keys — update the
switch/condition around shortcutCodes.cancel to test event.altKey (or explicitly
match Escape) before calling cancel_sale_button.click(), leaving existing cancel
button invocation unchanged.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 37800e32-de90-44d1-9ac6-f6ac735448dc
📒 Files selected for processing (1)
app/Views/sales/register.php
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 3 file(s) based on 1 unresolved review comment. Files modified:
Commit: The changes have been pushed to the Time taken: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/sales/register.php`:
- Around line 860-910: The key handler in document.body.onkeyup currently fires
shortcuts and the Escape cancel regardless of modals; update the handler to
first detect visible BootstrapDialog modals by checking $('.modal.in').length
and, if any modal is open, skip/return early so shortcuts (including the Escape
→ $("#cancel_sale_button").click()) are ignored while a modal (e.g., the
shortcuts help or modal-dlg) is active. Place this check at the top of the
document.body.onkeyup function (before the switch and before the Escape cancel
branch) so all shortcutCodes and the cancel behavior are suppressed when a
'.modal.in' exists.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 456636a8-3207-48cc-a3cf-b79d2c31f74a
📒 Files selected for processing (3)
app/Views/login.phpapp/Views/partial/header.phpapp/Views/sales/register.php
f62097a to
328bde0
Compare
194c86b to
253954d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
app/Views/configs/shortcuts_config.php (1)
31-31:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winEscape rendered language output in view markup
On Line 31, render the language string through
esc()for consistency with view output-escaping rules.Suggested fix
- <div id="required_fields_message"><?= lang('Common.fields_required_message') ?></div> + <div id="required_fields_message"><?= esc(lang('Common.fields_required_message')) ?></div>As per coding guidelines, "Sanitize user input; escape output using
esc()helper".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Views/configs/shortcuts_config.php` at line 31, The view currently outputs the language string directly in the div with id "required_fields_message"; wrap the lang('Common.fields_required_message') call with the esc() helper to ensure consistent output escaping (i.e., replace the direct lang(...) use inside the div#required_fields_message with esc(lang(...))).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/configs/shortcuts_config.php`:
- Around line 74-79: The AJAX error handler passes unescaped xhr.responseText
(and possibly xhr.responseJSON.message) into $.notify which can lead to XSS;
update the error callback that builds the notify message (the block referencing
xhr and $.notify) to sanitize/escape any user-supplied text before
rendering—either call a shared escapeHtml(text) utility or convert the string
into a plain-text node (use textContent/createTextNode) and then pass the
escaped/plain-text string to $.notify, ensuring the fallback <?=
json_encode(lang('Config.shortcuts_save_error')) ?> remains unchanged.
---
Duplicate comments:
In `@app/Views/configs/shortcuts_config.php`:
- Line 31: The view currently outputs the language string directly in the div
with id "required_fields_message"; wrap the
lang('Common.fields_required_message') call with the esc() helper to ensure
consistent output escaping (i.e., replace the direct lang(...) use inside the
div#required_fields_message with esc(lang(...))).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f40cd178-2dc0-4abb-9fd2-c33dc5f49bb3
📒 Files selected for processing (9)
app/Controllers/Config.phpapp/Controllers/Sales.phpapp/Database/Migrations/20260506000000_AddShortcutKeys.phpapp/Language/en/Config.phpapp/Libraries/Sale_lib.phpapp/Views/configs/manage.phpapp/Views/configs/shortcuts_config.phpapp/Views/sales/help.phpapp/Views/sales/register.php
✅ Files skipped from review due to trivial changes (1)
- app/Database/Migrations/20260506000000_AddShortcutKeys.php
🚧 Files skipped from review as they are similar to previous changes (7)
- app/Views/configs/manage.php
- app/Views/sales/help.php
- app/Language/en/Config.php
- app/Views/sales/register.php
- app/Controllers/Sales.php
- app/Libraries/Sale_lib.php
- app/Controllers/Config.php
objecttothis
left a comment
There was a problem hiding this comment.
Take a look at the two suggestions I made. Fix them if you want. Otherwise we are ready for you to squash and merge.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Views/configs/shortcuts_config.php`:
- Around line 67-72: The success callback currently passes response.message
directly into $.notify (in the success handler), creating an XSS risk; update
that handler to sanitize the message using DOMPurify.sanitize() before passing
it to $.notify (mirror the sanitization used in the error handler), i.e.,
replace direct use of response.message in the success handler with a sanitized
variable via DOMPurify.sanitize(response.message) so $.notify receives only the
cleaned string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7f79f21b-83d3-415d-ac01-90ecba88cb2c
📒 Files selected for processing (3)
app/Controllers/Config.phpapp/Language/en/Config.phpapp/Views/configs/shortcuts_config.php
🚧 Files skipped from review as they are similar to previous changes (2)
- app/Language/en/Config.php
- app/Controllers/Config.php
Few updates regarding HotKeys/ Keyboard Shortcut section.
. Added Shortcut TAB under config section where user can re-assign the shortcuts as needed
. Shortcuts Help Modal in Sales Register now reflects the assigned shortcuts
. Updates JS section in register in order to retreive assigned keys from database.
. Migration file
. Success message on submit
. Added the needed language strings and routes.
. CI4 Support shortcut configuration for sales hotkeys.
Updated version of #3720
Summary by CodeRabbit
New Features
Localization
Database