From c91e82ec9b43f700f432e7b4193f1df7f569e538 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Fri, 24 Jun 2022 17:01:23 -0400 Subject: [PATCH 1/6] Multiple tables init --- ui/app/modifiers/keyboard-shortcut.js | 40 +++++---------- ui/app/services/keyboard.js | 49 ++++++++++++++++++- ui/app/templates/clients/index.hbs | 4 +- .../components/job-page/parts/children.hbs | 4 +- .../job-page/parts/recent-allocations.hbs | 4 ++ .../components/job-page/parts/task-groups.hbs | 4 ++ ui/app/templates/components/job-row.hbs | 2 +- .../templates/components/server-agent-row.hbs | 2 +- ui/app/templates/csi/volumes/index.hbs | 4 +- ui/app/templates/evaluations/index.hbs | 4 +- ui/app/templates/jobs/index.hbs | 4 +- ui/app/templates/jobs/job/allocations.hbs | 4 ++ ui/app/templates/servers/index.hbs | 4 +- 13 files changed, 86 insertions(+), 43 deletions(-) diff --git a/ui/app/modifiers/keyboard-shortcut.js b/ui/app/modifiers/keyboard-shortcut.js index 3fb552ac42c..6ea5b91bff5 100644 --- a/ui/app/modifiers/keyboard-shortcut.js +++ b/ui/app/modifiers/keyboard-shortcut.js @@ -1,48 +1,34 @@ import { inject as service } from '@ember/service'; import Modifier from 'ember-modifier'; import { registerDestructor } from '@ember/destroyable'; -import { assert } from '@ember/debug'; export default class KeyboardShortcutModifier extends Modifier { @service keyboard; - /** - * For Dynamic/iterative keyboard shortcuts, our patterns look like "Shift+0" by default - * Do a couple things to make them more human-friendly: - * 1. Make them 1-based, instead of 0-based - * 2. Prefix numbers 1-9 with "0" to make it so "Shift+10" doesn't trigger "Shift+1" then "0", etc. - * ^--- stops being a good solution with 100+ row lists/tables, but a better UX than waiting for shift key-up otherwise - * - * @param {string[]} pattern - */ - cleanPattern(pattern) { - let patternNumber = pattern.length === 1 && pattern[0].match(/\d+/g); - if (!patternNumber) { - return pattern; - } else { - patternNumber = +patternNumber[0]; // regex'd string[0] to num - patternNumber = patternNumber + 1; // first item should be Shift+1, not Shift+0 - assert( - 'Dynamic keyboard shortcuts only work up to 99 digits', - patternNumber < 100 - ); - pattern = [`Shift+${('0' + patternNumber).slice(-2)}`]; // Shift+01, not Shift+1 + modify( + element, + [eventName], + { + label, + pattern = '', + action = () => {}, + menuLevel = false, + enumerated = false, } - return pattern; - } - - modify(element, [eventName], { label, pattern, action, menuLevel = false }) { + ) { let commands = [ { label, action, - pattern: this.cleanPattern(pattern), + pattern, element, menuLevel, + enumerated, }, ]; this.keyboard.addCommands(commands); registerDestructor(this, () => { + console.log('regDest', commands); this.keyboard.removeCommands(commands); }); } diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 822a60780ca..e4e0c96aac6 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -8,6 +8,8 @@ import EmberRouter from '@ember/routing/router'; import { schedule } from '@ember/runloop'; import { action } from '@ember/object'; import { guidFor } from '@ember/object/internals'; +import { assert } from '@ember/debug'; +import { isDestroying, isDestroyed } from '@ember/destroyable'; const DEBOUNCE_MS = 750; @@ -146,12 +148,55 @@ export default class KeyboardService extends Service { }, ]; + /** + * For Dynamic/iterative keyboard shortcuts, our patterns look like "Shift+0" by default + * Do a couple things to make them more human-friendly: + * 1. Make them 1-based, instead of 0-based + * 2. Prefix numbers 1-9 with "0" to make it so "Shift+10" doesn't trigger "Shift+1" then "0", etc. + * ^--- stops being a good solution with 100+ row lists/tables, but a better UX than waiting for shift key-up otherwise + * + * @param {string[]} pattern + */ + cleanPattern(pattern) { + console.log('paterrnnnn', pattern); + let patternNumber = pattern.length === 1 && pattern[0].match(/\d+/g); + if (!patternNumber) { + return pattern; + } else { + patternNumber = +patternNumber[0]; // regex'd string[0] to num + patternNumber = patternNumber + 1; // first item should be Shift+1, not Shift+0 + assert( + 'Dynamic keyboard shortcuts only work up to 99 digits', + patternNumber < 100 + ); + pattern = [`Shift+${('0' + patternNumber).slice(-2)}`]; // Shift+01, not Shift+1 + } + return pattern; + } + addCommands(commands) { - // Filter out those commands that don't have a label (they're only being added for at-a-glance hinting/highlights) - this.keyCommands.pushObjects(commands); + commands.forEach((command) => { + if (command.enumerated) { + // TODO: Monday: New enumerates are being added before old ones are being removed. + // Either add a route qualifier in, or wait for keyCommands.filterBy('enumerated') to be empty in order to solve. + console.log( + 'enumerated and currently have', + this.keyCommands.map((x) => isDestroying(x)), + this.keyCommands.map((x) => isDestroyed(x)), + this.keyCommands.filterBy('enumerated').length + ); + command.pattern = this.cleanPattern([ + `${this.keyCommands.filterBy('enumerated').length}`, + ]); + this.keyCommands.pushObjects(commands); + } else { + this.keyCommands.pushObjects(commands); + } + }); } removeCommands(commands) { + console.log('removing', commands); this.keyCommands.removeObjects(commands); } diff --git a/ui/app/templates/clients/index.hbs b/ui/app/templates/clients/index.hbs index 1a4e0801b4c..13b80fec7d7 100644 --- a/ui/app/templates/clients/index.hbs +++ b/ui/app/templates/clients/index.hbs @@ -81,13 +81,13 @@ # Volumes # Allocs - + diff --git a/ui/app/templates/components/job-page/parts/children.hbs b/ui/app/templates/components/job-page/parts/children.hbs index c9a1553885f..9df07ebeab6 100644 --- a/ui/app/templates/components/job-page/parts/children.hbs +++ b/ui/app/templates/components/job-page/parts/children.hbs @@ -65,8 +65,8 @@ Summary - - + +
diff --git a/ui/app/templates/components/job-page/parts/recent-allocations.hbs b/ui/app/templates/components/job-page/parts/recent-allocations.hbs index b28080c9d85..c08679f816c 100644 --- a/ui/app/templates/components/job-page/parts/recent-allocations.hbs +++ b/ui/app/templates/components/job-page/parts/recent-allocations.hbs @@ -52,6 +52,10 @@ @allocation={{row.model}} @context="job" @onClick={{action "gotoAllocation" row.model}} + {{keyboard-shortcut + enumerated=true + action=(action "gotoAllocation" row.model) + }} /> diff --git a/ui/app/templates/components/job-page/parts/task-groups.hbs b/ui/app/templates/components/job-page/parts/task-groups.hbs index 0e419f88132..fdc4839844f 100644 --- a/ui/app/templates/components/job-page/parts/task-groups.hbs +++ b/ui/app/templates/components/job-page/parts/task-groups.hbs @@ -36,6 +36,10 @@ @data-test-task-group={{row.model.name}} @taskGroup={{row.model}} @onClick={{fn this.gotoTaskGroup row.model}} + {{keyboard-shortcut + enumerated=true + action=(fn this.gotoTaskGroup row.model) + }} /> diff --git a/ui/app/templates/components/job-row.hbs b/ui/app/templates/components/job-row.hbs index 983a7efa22f..f2212ebdf7e 100644 --- a/ui/app/templates/components/job-row.hbs +++ b/ui/app/templates/components/job-row.hbs @@ -1,6 +1,6 @@ diff --git a/ui/app/templates/components/server-agent-row.hbs b/ui/app/templates/components/server-agent-row.hbs index 2d04d5f9f11..b4ed53fb60a 100644 --- a/ui/app/templates/components/server-agent-row.hbs +++ b/ui/app/templates/components/server-agent-row.hbs @@ -1,6 +1,6 @@ {{this.agent.name}} diff --git a/ui/app/templates/csi/volumes/index.hbs b/ui/app/templates/csi/volumes/index.hbs index 462c1dde84a..e7ec1419048 100644 --- a/ui/app/templates/csi/volumes/index.hbs +++ b/ui/app/templates/csi/volumes/index.hbs @@ -67,7 +67,7 @@ # Allocs - + diff --git a/ui/app/templates/evaluations/index.hbs b/ui/app/templates/evaluations/index.hbs index f7a2b27733d..f9e19c979ae 100644 --- a/ui/app/templates/evaluations/index.hbs +++ b/ui/app/templates/evaluations/index.hbs @@ -67,7 +67,7 @@ Placement Failures - + diff --git a/ui/app/templates/jobs/index.hbs b/ui/app/templates/jobs/index.hbs index ded9f0e4876..e08aa1335e7 100644 --- a/ui/app/templates/jobs/index.hbs +++ b/ui/app/templates/jobs/index.hbs @@ -147,8 +147,8 @@ Summary - - + +
diff --git a/ui/app/templates/jobs/job/allocations.hbs b/ui/app/templates/jobs/job/allocations.hbs index 2dff6a224fd..d7d63e9b7d5 100644 --- a/ui/app/templates/jobs/job/allocations.hbs +++ b/ui/app/templates/jobs/job/allocations.hbs @@ -62,6 +62,10 @@ Datacenter Version - - + +
From b2f332543520fe9c10f06f1eb18272c9ad7d5a57 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 27 Jun 2022 11:11:33 -0400 Subject: [PATCH 2/6] URL-bind enumerable keyboard commands and add to more taskRow and allocationRows --- ui/app/modifiers/keyboard-shortcut.js | 5 +++-- ui/app/services/keyboard.js | 19 ++++++++----------- .../allocations/allocation/index.hbs | 4 ++++ ui/app/templates/clients/client/index.hbs | 4 ++++ ui/app/templates/csi/volumes/volume.hbs | 8 ++++++++ ui/app/templates/jobs/job/task-group.hbs | 4 ++++ 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ui/app/modifiers/keyboard-shortcut.js b/ui/app/modifiers/keyboard-shortcut.js index 6ea5b91bff5..1704a487c3b 100644 --- a/ui/app/modifiers/keyboard-shortcut.js +++ b/ui/app/modifiers/keyboard-shortcut.js @@ -4,10 +4,11 @@ import { registerDestructor } from '@ember/destroyable'; export default class KeyboardShortcutModifier extends Modifier { @service keyboard; + @service router; modify( element, - [eventName], + _positional, { label, pattern = '', @@ -24,11 +25,11 @@ export default class KeyboardShortcutModifier extends Modifier { element, menuLevel, enumerated, + url: this.router.currentURL, }, ]; this.keyboard.addCommands(commands); registerDestructor(this, () => { - console.log('regDest', commands); this.keyboard.removeCommands(commands); }); } diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index e4e0c96aac6..1e7d15465a3 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -158,7 +158,6 @@ export default class KeyboardService extends Service { * @param {string[]} pattern */ cleanPattern(pattern) { - console.log('paterrnnnn', pattern); let patternNumber = pattern.length === 1 && pattern[0].match(/\d+/g); if (!patternNumber) { return pattern; @@ -177,16 +176,15 @@ export default class KeyboardService extends Service { addCommands(commands) { commands.forEach((command) => { if (command.enumerated) { - // TODO: Monday: New enumerates are being added before old ones are being removed. - // Either add a route qualifier in, or wait for keyCommands.filterBy('enumerated') to be empty in order to solve. - console.log( - 'enumerated and currently have', - this.keyCommands.map((x) => isDestroying(x)), - this.keyCommands.map((x) => isDestroyed(x)), - this.keyCommands.filterBy('enumerated').length - ); + // Ember's registerDestructor on destroyables fires AFTER a page load, meaning our enumerated array will be full of both old and new commands. + // Filter not only by enumerated, but also make sure we're only counting by those commands with our new command's URL. + // Without this second filterBy, moving from tabled-page to tabled-page will start your new commands at a number greater than 01. command.pattern = this.cleanPattern([ - `${this.keyCommands.filterBy('enumerated').length}`, + `${ + this.keyCommands + .filterBy('enumerated') + .filter((c) => c.url === command.url).length + }`, ]); this.keyCommands.pushObjects(commands); } else { @@ -196,7 +194,6 @@ export default class KeyboardService extends Service { } removeCommands(commands) { - console.log('removing', commands); this.keyCommands.removeObjects(commands); } diff --git a/ui/app/templates/allocations/allocation/index.hbs b/ui/app/templates/allocations/allocation/index.hbs index 6519c3629aa..7ebec44e7c5 100644 --- a/ui/app/templates/allocations/allocation/index.hbs +++ b/ui/app/templates/allocations/allocation/index.hbs @@ -184,6 +184,10 @@ Date: Mon, 27 Jun 2022 11:50:07 -0400 Subject: [PATCH 3/6] Type safety and lint fixes --- ui/app/components/keyboard-hooks.js | 0 ui/app/components/keyboard-shortcuts-modal.js | 5 +- ui/app/controllers/application.js | 3 ++ ui/app/services/keyboard.js | 48 ++++++++----------- .../components/keyboard-hooks-test.js | 26 ---------- .../keyboard-shortcuts-modal-test.js | 12 ++--- 6 files changed, 29 insertions(+), 65 deletions(-) delete mode 100644 ui/app/components/keyboard-hooks.js delete mode 100644 ui/tests/integration/components/keyboard-hooks-test.js diff --git a/ui/app/components/keyboard-hooks.js b/ui/app/components/keyboard-hooks.js deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ui/app/components/keyboard-shortcuts-modal.js b/ui/app/components/keyboard-shortcuts-modal.js index 7cd20646906..bb99eacda46 100644 --- a/ui/app/components/keyboard-shortcuts-modal.js +++ b/ui/app/components/keyboard-shortcuts-modal.js @@ -1,6 +1,5 @@ import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; -import { htmlSafe } from '@ember/template'; import { computed } from '@ember/object'; import Tether from 'tether'; @@ -28,7 +27,7 @@ export default class KeyboardShortcutsModalComponent extends Component { * hints: filter keyCommands to those that have an element property, * and then compute a position on screen to place the hint. */ - @computed('keyboard.keyCommands.length', 'keyboard.displayHints') + @computed('keyboard.{keyCommands.length,displayHints}') get hints() { if (this.keyboard.displayHints) { return this.keyboard.keyCommands.filter((c) => c.element); @@ -47,7 +46,7 @@ export default class KeyboardShortcutsModalComponent extends Component { }); hint.binder = binder; } - untetherFromElement(self, _, { element, hint }) { + untetherFromElement(self, _, { hint }) { hint.binder.destroy(); } } diff --git a/ui/app/controllers/application.js b/ui/app/controllers/application.js index a688f4e4b44..4bb89427449 100644 --- a/ui/app/controllers/application.js +++ b/ui/app/controllers/application.js @@ -9,6 +9,7 @@ import codesForError from '../utils/codes-for-error'; import NoLeaderError from '../utils/no-leader-error'; import OTTExchangeError from '../utils/ott-exchange-error'; import classic from 'ember-classic-decorator'; +// eslint-disable-next-line no-unused-vars import KeyboardService from '../services/keyboard'; @classic export default class ApplicationController extends Controller { @@ -21,8 +22,10 @@ export default class ApplicationController extends Controller { */ @service keyboard; + // eslint-disable-next-line ember/classic-decorator-hooks constructor() { super(...arguments); + console.log('do i listen for keypress'); this.keyboard.listenForKeypress(); } diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 1e7d15465a3..8b04070cf7b 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -1,15 +1,18 @@ +// @ts-check import Service from '@ember/service'; import { inject as service } from '@ember/service'; import { timeout, restartableTask } from 'ember-concurrency'; import { tracked } from '@glimmer/tracking'; import { compare } from '@ember/utils'; import { A } from '@ember/array'; +// eslint-disable-next-line no-unused-vars import EmberRouter from '@ember/routing/router'; import { schedule } from '@ember/runloop'; import { action } from '@ember/object'; import { guidFor } from '@ember/object/internals'; import { assert } from '@ember/debug'; -import { isDestroying, isDestroyed } from '@ember/destroyable'; +// eslint-disable-next-line no-unused-vars +import MutableArray from '@ember/array/mutable'; const DEBOUNCE_MS = 750; @@ -39,7 +42,10 @@ export default class KeyboardService extends Service { @tracked buffer = A([]); @tracked displayHints = false; - keyCommands = [ + /** + * @type {MutableArray} + */ + keyCommands = A([ { label: 'Go to Jobs', pattern: ['g', 'j'], @@ -146,31 +152,21 @@ export default class KeyboardService extends Service { console.log('Extra Lives +30'); }, }, - ]; + ]); /** - * For Dynamic/iterative keyboard shortcuts, our patterns look like "Shift+0" by default - * Do a couple things to make them more human-friendly: + * For Dynamic/iterative keyboard shortcuts, we want to do a couple things to make them more human-friendly: * 1. Make them 1-based, instead of 0-based * 2. Prefix numbers 1-9 with "0" to make it so "Shift+10" doesn't trigger "Shift+1" then "0", etc. * ^--- stops being a good solution with 100+ row lists/tables, but a better UX than waiting for shift key-up otherwise * - * @param {string[]} pattern + * @param {number} iter + * @returns {string[]} */ - cleanPattern(pattern) { - let patternNumber = pattern.length === 1 && pattern[0].match(/\d+/g); - if (!patternNumber) { - return pattern; - } else { - patternNumber = +patternNumber[0]; // regex'd string[0] to num - patternNumber = patternNumber + 1; // first item should be Shift+1, not Shift+0 - assert( - 'Dynamic keyboard shortcuts only work up to 99 digits', - patternNumber < 100 - ); - pattern = [`Shift+${('0' + patternNumber).slice(-2)}`]; // Shift+01, not Shift+1 - } - return pattern; + cleanPattern(iter) { + iter = iter + 1; // first item should be Shift+1, not Shift+0 + assert('Dynamic keyboard shortcuts only work up to 99 digits', iter < 100); + return [`Shift+${('0' + iter).slice(-2)}`]; // Shift+01, not Shift+1 } addCommands(commands) { @@ -179,13 +175,11 @@ export default class KeyboardService extends Service { // Ember's registerDestructor on destroyables fires AFTER a page load, meaning our enumerated array will be full of both old and new commands. // Filter not only by enumerated, but also make sure we're only counting by those commands with our new command's URL. // Without this second filterBy, moving from tabled-page to tabled-page will start your new commands at a number greater than 01. - command.pattern = this.cleanPattern([ - `${ - this.keyCommands - .filterBy('enumerated') - .filter((c) => c.url === command.url).length - }`, - ]); + command.pattern = this.cleanPattern( + this.keyCommands + .filterBy('enumerated') + .filter((c) => c.url === command.url).length + ); this.keyCommands.pushObjects(commands); } else { this.keyCommands.pushObjects(commands); diff --git a/ui/tests/integration/components/keyboard-hooks-test.js b/ui/tests/integration/components/keyboard-hooks-test.js deleted file mode 100644 index 542c0caf225..00000000000 --- a/ui/tests/integration/components/keyboard-hooks-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Component | keyboard-hooks', function (hooks) { - setupRenderingTest(hooks); - - test('it renders', async function (assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); - - await render(hbs``); - - assert.dom(this.element).hasText(''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.dom(this.element).hasText('template block text'); - }); -}); diff --git a/ui/tests/integration/components/keyboard-shortcuts-modal-test.js b/ui/tests/integration/components/keyboard-shortcuts-modal-test.js index 9f904652e5d..c6ad8d9cec6 100644 --- a/ui/tests/integration/components/keyboard-shortcuts-modal-test.js +++ b/ui/tests/integration/components/keyboard-shortcuts-modal-test.js @@ -2,25 +2,19 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; +import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; module('Integration | Component | keyboard-shortcuts-modal', function (hooks) { setupRenderingTest(hooks); test('it renders', async function (assert) { + assert.expect(2); // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.set('myAction', function(val) { ... }); await render(hbs``); assert.dom(this.element).hasText(''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.dom(this.element).hasText('template block text'); + await componentA11yAudit(this.element, assert); }); }); From f880be9eee6cf9d0f1142d51f3b370cc38332609 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Tue, 28 Jun 2022 15:43:31 -0400 Subject: [PATCH 4/6] Consolidated push to keyCommands --- ui/app/services/keyboard.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 8b04070cf7b..803841b232a 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -180,11 +180,9 @@ export default class KeyboardService extends Service { .filterBy('enumerated') .filter((c) => c.url === command.url).length ); - this.keyCommands.pushObjects(commands); - } else { - this.keyCommands.pushObjects(commands); } }); + this.keyCommands.pushObjects(commands); } removeCommands(commands) { From ca9100e380490b915bd4b882cc02a255f7a83334 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 13 Jul 2022 10:58:36 -0400 Subject: [PATCH 5/6] Default value when removing keyCommands --- ui/app/services/keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 803841b232a..1edfb99cd8d 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -185,7 +185,7 @@ export default class KeyboardService extends Service { this.keyCommands.pushObjects(commands); } - removeCommands(commands) { + removeCommands(commands = A([])) { this.keyCommands.removeObjects(commands); } From 48f02e0a33959938e9eb349b9c2033c690667ea4 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 13 Jul 2022 15:08:55 -0400 Subject: [PATCH 6/6] Remove the URL-based removal method and perform a recompute on any add --- ui/app/controllers/application.js | 1 - ui/app/helpers/keyboard-commands.js | 2 -- ui/app/modifiers/keyboard-shortcut.js | 2 +- ui/app/services/keyboard.js | 35 +++++++++++---------------- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/ui/app/controllers/application.js b/ui/app/controllers/application.js index 4bb89427449..be1756c0ee8 100644 --- a/ui/app/controllers/application.js +++ b/ui/app/controllers/application.js @@ -25,7 +25,6 @@ export default class ApplicationController extends Controller { // eslint-disable-next-line ember/classic-decorator-hooks constructor() { super(...arguments); - console.log('do i listen for keypress'); this.keyboard.listenForKeypress(); } diff --git a/ui/app/helpers/keyboard-commands.js b/ui/app/helpers/keyboard-commands.js index f048ebb658b..f03fd4b92e7 100644 --- a/ui/app/helpers/keyboard-commands.js +++ b/ui/app/helpers/keyboard-commands.js @@ -10,12 +10,10 @@ export default class keyboardCommands extends Helper { @service keyboard; constructor() { - console.log('kc const', ...arguments); super(...arguments); } compute([commands]) { - console.log('computing', commands); if (commands) { this.commands = commands; this.keyboard.addCommands(commands); diff --git a/ui/app/modifiers/keyboard-shortcut.js b/ui/app/modifiers/keyboard-shortcut.js index 1704a487c3b..1ddcaaa6535 100644 --- a/ui/app/modifiers/keyboard-shortcut.js +++ b/ui/app/modifiers/keyboard-shortcut.js @@ -25,9 +25,9 @@ export default class KeyboardShortcutModifier extends Modifier { element, menuLevel, enumerated, - url: this.router.currentURL, }, ]; + this.keyboard.addCommands(commands); registerDestructor(this, () => { this.keyboard.removeCommands(commands); diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 1edfb99cd8d..a35619bee5c 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -169,35 +169,28 @@ export default class KeyboardService extends Service { return [`Shift+${('0' + iter).slice(-2)}`]; // Shift+01, not Shift+1 } + recomputeEnumeratedCommands() { + this.keyCommands.filterBy('enumerated').forEach((command, iter) => { + command.pattern = this.cleanPattern(iter); + }); + } + addCommands(commands) { - commands.forEach((command) => { - if (command.enumerated) { - // Ember's registerDestructor on destroyables fires AFTER a page load, meaning our enumerated array will be full of both old and new commands. - // Filter not only by enumerated, but also make sure we're only counting by those commands with our new command's URL. - // Without this second filterBy, moving from tabled-page to tabled-page will start your new commands at a number greater than 01. - command.pattern = this.cleanPattern( - this.keyCommands - .filterBy('enumerated') - .filter((c) => c.url === command.url).length - ); - } + schedule('afterRender', () => { + commands.forEach((command) => { + this.keyCommands.pushObject(command); + if (command.enumerated) { + // Recompute enumerated numbers to handle things like sort + this.recomputeEnumeratedCommands(); + } + }); }); - this.keyCommands.pushObjects(commands); } removeCommands(commands = A([])) { this.keyCommands.removeObjects(commands); } - @action - generateIteratorShortcut(element, [action, iter]) { - this.keyCommands.pushObject({ - label: `Hit up item ${iter}`, - pattern: [`Shift+${iter}`], - action, - }); - } - //#region Nav Traversal subnavLinks = [];