Skip to content

Commit

Permalink
Fixed global-search keyboard shortcut for non-english keyboard layouts.
Browse files Browse the repository at this point in the history
Closes #10646
  • Loading branch information
apollo13 committed Jun 7, 2021
1 parent bdf2555 commit 3c82363
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BUG FIXES:
* drivers/exec: Fixed a bug where `exec` and `java` tasks inherit the Nomad agent's `oom_score_adj` value [[GH-10698](https://github.com/hashicorp/nomad/issues/10698)]
* quotas (Enterprise): Fixed a bug where stopped allocations for a failed deployment can be double-credited to quota limits, resulting in a quota limit bypass. [[GH-10694](https://github.com/hashicorp/nomad/issues/10694)]
* ui: Fixed a bug where exec would not work across regions. [[GH-10539](https://github.com/hashicorp/nomad/issues/10539)]
* ui: Fixed global-search shortcut for non-english keyboards. [[GH-10646](https://github.com/hashicorp/nomad/issues/10646)]

## 1.1.0 (May 18, 2021)

Expand Down
87 changes: 55 additions & 32 deletions ui/app/components/global-search/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { action, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { debounce, run } from '@ember/runloop';

const SLASH_KEY = 191;
const SLASH_KEY = '/';
const MAXIMUM_RESULTS = 10;

@classNames('global-search-container')
Expand All @@ -24,7 +24,7 @@ export default class GlobalSearchControl extends Component {
const targetElementName = e.target.nodeName.toLowerCase();

if (targetElementName != 'input' && targetElementName != 'textarea') {
if (e.keyCode === SLASH_KEY) {
if (e.key === SLASH_KEY) {
e.preventDefault();
this.open();
}
Expand Down Expand Up @@ -57,32 +57,40 @@ export default class GlobalSearchControl extends Component {
const allTaskGroupResults = results.Matches.groups || [];
const allCSIPluginResults = results.Matches.plugins || [];

const jobResults = allJobResults.slice(0, MAXIMUM_RESULTS).map(({ ID: name, Scope: [ namespace, id ]}) => ({
type: 'job',
id,
namespace,
label: name,
}));

const nodeResults = allNodeResults.slice(0, MAXIMUM_RESULTS).map(({ ID: name, Scope: [ id ]}) => ({
type: 'node',
id,
label: name,
}));

const allocationResults = allAllocationResults.slice(0, MAXIMUM_RESULTS).map(({ ID: name, Scope: [ , id ]}) => ({
type: 'allocation',
id,
label: name,
}));

const taskGroupResults = allTaskGroupResults.slice(0, MAXIMUM_RESULTS).map(({ ID: id, Scope: [ namespace, jobId ]}) => ({
type: 'task-group',
id,
namespace,
jobId,
label: id,
}));
const jobResults = allJobResults
.slice(0, MAXIMUM_RESULTS)
.map(({ ID: name, Scope: [namespace, id] }) => ({
type: 'job',
id,
namespace,
label: name,
}));

const nodeResults = allNodeResults
.slice(0, MAXIMUM_RESULTS)
.map(({ ID: name, Scope: [id] }) => ({
type: 'node',
id,
label: name,
}));

const allocationResults = allAllocationResults
.slice(0, MAXIMUM_RESULTS)
.map(({ ID: name, Scope: [, id] }) => ({
type: 'allocation',
id,
label: name,
}));

const taskGroupResults = allTaskGroupResults
.slice(0, MAXIMUM_RESULTS)
.map(({ ID: id, Scope: [namespace, jobId] }) => ({
type: 'task-group',
id,
namespace,
jobId,
label: id,
}));

const csiPluginResults = allCSIPluginResults.slice(0, MAXIMUM_RESULTS).map(({ ID: id }) => ({
type: 'plugin',
Expand All @@ -108,17 +116,32 @@ export default class GlobalSearchControl extends Component {
options: nodeResults,
},
{
groupName: resultsGroupLabel('Allocations', allocationResults, allAllocationResults, allocationsTruncated),
groupName: resultsGroupLabel(
'Allocations',
allocationResults,
allAllocationResults,
allocationsTruncated
),
options: allocationResults,
},
{
groupName: resultsGroupLabel('Task Groups', taskGroupResults, allTaskGroupResults, taskGroupsTruncated),
groupName: resultsGroupLabel(
'Task Groups',
taskGroupResults,
allTaskGroupResults,
taskGroupsTruncated
),
options: taskGroupResults,
},
{
groupName: resultsGroupLabel('CSI Plugins', csiPluginResults, allCSIPluginResults, csiPluginsTruncated),
groupName: resultsGroupLabel(
'CSI Plugins',
csiPluginResults,
allCSIPluginResults,
csiPluginsTruncated
),
options: csiPluginResults,
}
},
];
})
search;
Expand Down

0 comments on commit 3c82363

Please sign in to comment.