[ui] Keyboard shortcuts to switch regions (#17169)

* Regions keynav

* Dont show if you only have a single region (global by default)
This commit is contained in:
Phil Renaud 2023-05-12 11:46:00 -04:00 committed by GitHub
parent e55edf58ff
commit 9a5d67d475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

3
.changelog/17169.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: adds keyboard nav for switching between regions by pressing "r 1", "r 2", etc.
```

View File

@ -24,4 +24,17 @@ export default class RegionSwitcher extends Component {
queryParams: { region },
});
}
get keyCommands() {
if (this.sortedRegions.length <= 1) {
return [];
}
return this.sortedRegions.map((region, iter) => {
return {
label: `Switch to ${region} region`,
pattern: ['r', `${iter + 1}`],
action: () => this.gotoRegion(region),
};
});
}
}

View File

@ -3,6 +3,8 @@
SPDX-License-Identifier: MPL-2.0
~}}
{{keyboard-commands this.keyCommands}}
{{#if this.system.shouldShowRegions}}
<span data-test-region-switcher-parent>
<PowerSelect

View File

@ -361,5 +361,41 @@ module('Acceptance | keyboard', function (hooks) {
'Shift+ArrowRight takes you to the first tab in the loop'
);
});
test('Region switching', async function (assert) {
['Detroit', 'Halifax', 'Phoenix', 'Toronto', 'Windsor'].forEach((id) => {
server.create('region', { id });
});
await visit('/jobs');
// Regions are in the keynav modal
await triggerEvent('.page-layout', 'keydown', { key: '?' });
await triggerEvent('.page-layout', 'keydown', { key: '?' });
assert.ok(Layout.keyboard.modalShown);
assert
.dom('[data-test-command-label="Switch to Detroit region"]')
.exists('First created region is in the modal');
assert
.dom('[data-test-command-label="Switch to Windsor region"]')
.exists('Last created region is in the modal');
// Triggers a region switch to Halifax
triggerEvent('.page-layout', 'keydown', { key: 'r' });
await triggerEvent('.page-layout', 'keydown', { key: '2' });
assert.ok(
currentURL().includes('region=Halifax'),
'r 2 command takes you to the second region'
);
// Triggers a region switch to Phoenix
triggerEvent('.page-layout', 'keydown', { key: 'r' });
await triggerEvent('.page-layout', 'keydown', { key: '3' });
assert.ok(
currentURL().includes('region=Phoenix'),
'r 3 command takes you to the third region'
);
});
});
});