2020-06-19 18:05:28 +00:00
|
|
|
import Component from '@ember/component';
|
2020-06-25 13:51:52 +00:00
|
|
|
import { classNames } from '@ember-decorators/component';
|
2020-06-19 18:05:28 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
import { action, set } from '@ember/object';
|
2020-06-19 18:05:28 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-25 13:51:52 +00:00
|
|
|
import { debounce, run } from '@ember/runloop';
|
2020-06-19 18:05:28 +00:00
|
|
|
|
2021-06-07 14:34:20 +00:00
|
|
|
const SLASH_KEY = '/';
|
2020-08-05 20:58:44 +00:00
|
|
|
const MAXIMUM_RESULTS = 10;
|
2020-06-19 18:05:28 +00:00
|
|
|
|
2020-06-25 13:51:52 +00:00
|
|
|
@classNames('global-search-container')
|
2020-06-19 18:05:28 +00:00
|
|
|
export default class GlobalSearchControl extends Component {
|
|
|
|
@service router;
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
@service token;
|
2020-06-19 18:05:28 +00:00
|
|
|
|
|
|
|
searchString = null;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2021-03-26 13:55:12 +00:00
|
|
|
this['data-test-search-parent'] = true;
|
2020-06-19 18:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keyDownHandler(e) {
|
|
|
|
const targetElementName = e.target.nodeName.toLowerCase();
|
|
|
|
|
|
|
|
if (targetElementName != 'input' && targetElementName != 'textarea') {
|
2021-06-07 14:34:20 +00:00
|
|
|
if (e.key === SLASH_KEY) {
|
2020-06-19 18:05:28 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
didInsertElement() {
|
2021-12-28 14:45:20 +00:00
|
|
|
super.didInsertElement(...arguments);
|
2020-06-22 18:23:28 +00:00
|
|
|
set(this, '_keyDownHandler', this.keyDownHandler.bind(this));
|
2020-06-19 18:05:28 +00:00
|
|
|
document.addEventListener('keydown', this._keyDownHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2021-12-28 14:45:20 +00:00
|
|
|
super.willDestroyElement(...arguments);
|
2020-06-19 18:05:28 +00:00
|
|
|
document.removeEventListener('keydown', this._keyDownHandler);
|
|
|
|
}
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@task(function* (string) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const searchResponse = yield this.token.authorizedRequest(
|
|
|
|
'/v1/search/fuzzy',
|
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
Text: string,
|
|
|
|
Context: 'all',
|
|
|
|
Namespace: '*',
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
|
|
|
|
const results = yield searchResponse.json();
|
|
|
|
|
|
|
|
const allJobResults = results.Matches.jobs || [];
|
|
|
|
const allNodeResults = results.Matches.nodes || [];
|
|
|
|
const allAllocationResults = results.Matches.allocs || [];
|
|
|
|
const allTaskGroupResults = results.Matches.groups || [];
|
|
|
|
const allCSIPluginResults = results.Matches.plugins || [];
|
|
|
|
|
2021-07-26 21:23:21 +00:00
|
|
|
const jobResults = allJobResults
|
|
|
|
.slice(0, MAXIMUM_RESULTS)
|
|
|
|
.map(({ ID: name, Scope: [namespace, id] }) => ({
|
|
|
|
type: 'job',
|
|
|
|
id,
|
|
|
|
namespace,
|
2021-08-09 21:50:49 +00:00
|
|
|
label: `${namespace} > ${name}`,
|
2021-07-26 21:23:21 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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: [namespace, id] }) => ({
|
|
|
|
type: 'allocation',
|
|
|
|
id,
|
2021-08-09 21:50:49 +00:00
|
|
|
label: `${namespace} > ${name}`,
|
2021-07-26 21:23:21 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
const taskGroupResults = allTaskGroupResults
|
|
|
|
.slice(0, MAXIMUM_RESULTS)
|
|
|
|
.map(({ ID: id, Scope: [namespace, jobId] }) => ({
|
|
|
|
type: 'task-group',
|
|
|
|
id,
|
|
|
|
namespace,
|
|
|
|
jobId,
|
2021-08-09 21:50:49 +00:00
|
|
|
label: `${namespace} > ${jobId} > ${id}`,
|
2021-07-26 21:23:21 +00:00
|
|
|
}));
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const csiPluginResults = allCSIPluginResults
|
|
|
|
.slice(0, MAXIMUM_RESULTS)
|
|
|
|
.map(({ ID: id }) => ({
|
|
|
|
type: 'plugin',
|
|
|
|
id,
|
|
|
|
label: id,
|
|
|
|
}));
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
jobs: jobsTruncated,
|
|
|
|
nodes: nodesTruncated,
|
|
|
|
allocs: allocationsTruncated,
|
|
|
|
groups: taskGroupsTruncated,
|
|
|
|
plugins: csiPluginsTruncated,
|
|
|
|
} = results.Truncations;
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2021-12-28 16:08:12 +00:00
|
|
|
groupName: resultsGroupLabel(
|
|
|
|
'Jobs',
|
|
|
|
jobResults,
|
|
|
|
allJobResults,
|
|
|
|
jobsTruncated
|
|
|
|
),
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
options: jobResults,
|
|
|
|
},
|
|
|
|
{
|
2021-12-28 16:08:12 +00:00
|
|
|
groupName: resultsGroupLabel(
|
|
|
|
'Clients',
|
|
|
|
nodeResults,
|
|
|
|
allNodeResults,
|
|
|
|
nodesTruncated
|
|
|
|
),
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
options: nodeResults,
|
|
|
|
},
|
|
|
|
{
|
2021-07-26 21:23:21 +00:00
|
|
|
groupName: resultsGroupLabel(
|
|
|
|
'Allocations',
|
|
|
|
allocationResults,
|
|
|
|
allAllocationResults,
|
|
|
|
allocationsTruncated
|
|
|
|
),
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
options: allocationResults,
|
|
|
|
},
|
|
|
|
{
|
2021-07-26 21:23:21 +00:00
|
|
|
groupName: resultsGroupLabel(
|
|
|
|
'Task Groups',
|
|
|
|
taskGroupResults,
|
|
|
|
allTaskGroupResults,
|
|
|
|
taskGroupsTruncated
|
|
|
|
),
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
options: taskGroupResults,
|
|
|
|
},
|
|
|
|
{
|
2021-07-26 21:23:21 +00:00
|
|
|
groupName: resultsGroupLabel(
|
|
|
|
'CSI Plugins',
|
|
|
|
csiPluginResults,
|
|
|
|
allCSIPluginResults,
|
|
|
|
csiPluginsTruncated
|
|
|
|
),
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
options: csiPluginResults,
|
2021-07-26 21:23:21 +00:00
|
|
|
},
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
];
|
2020-06-19 18:05:28 +00:00
|
|
|
})
|
|
|
|
search;
|
|
|
|
|
|
|
|
@action
|
|
|
|
open() {
|
|
|
|
if (this.select) {
|
|
|
|
this.select.actions.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
ensureMinimumLength(string) {
|
|
|
|
return string.length > 1;
|
|
|
|
}
|
2020-06-19 18:05:28 +00:00
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
@action
|
|
|
|
selectOption(model) {
|
|
|
|
if (model.type === 'job') {
|
|
|
|
this.router.transitionTo('jobs.job', model.id, {
|
|
|
|
queryParams: { namespace: model.namespace },
|
2020-06-19 18:05:28 +00:00
|
|
|
});
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
} else if (model.type === 'node') {
|
2020-06-19 18:05:28 +00:00
|
|
|
this.router.transitionTo('clients.client', model.id);
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
} else if (model.type === 'task-group') {
|
|
|
|
this.router.transitionTo('jobs.job.task-group', model.jobId, model.id, {
|
|
|
|
queryParams: { namespace: model.namespace },
|
|
|
|
});
|
|
|
|
} else if (model.type === 'plugin') {
|
|
|
|
this.router.transitionTo('csi.plugins.plugin', model.id);
|
|
|
|
} else if (model.type === 'allocation') {
|
|
|
|
this.router.transitionTo('allocations.allocation', model.id);
|
2020-06-19 18:05:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
storeSelect(select) {
|
|
|
|
if (select) {
|
|
|
|
this.select = select;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
openOnClickOrTab(select, { target }) {
|
|
|
|
// Bypass having to press enter to access search after clicking/tabbing
|
|
|
|
const targetClassList = target.classList;
|
2021-12-28 16:08:12 +00:00
|
|
|
const targetIsTrigger = targetClassList.contains(
|
|
|
|
'ember-power-select-trigger'
|
|
|
|
);
|
2020-06-19 18:05:28 +00:00
|
|
|
|
|
|
|
// Allow tabbing out of search
|
2021-12-28 16:08:12 +00:00
|
|
|
const triggerIsNotActive = !targetClassList.contains(
|
|
|
|
'ember-power-select-trigger--active'
|
|
|
|
);
|
2020-06-19 18:05:28 +00:00
|
|
|
|
|
|
|
if (targetIsTrigger && triggerIsNotActive) {
|
2020-06-25 13:51:52 +00:00
|
|
|
debounce(this, this.open, 150);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
onCloseEvent(select, event) {
|
|
|
|
if (event.key === 'Escape') {
|
2020-06-19 18:05:28 +00:00
|
|
|
run.next(() => {
|
2020-06-30 20:23:02 +00:00
|
|
|
this.element.querySelector('.ember-power-select-trigger').blur();
|
2020-06-19 18:05:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
calculatePosition(trigger) {
|
|
|
|
const { top, left, width } = trigger.getBoundingClientRect();
|
|
|
|
return {
|
|
|
|
style: {
|
|
|
|
left,
|
|
|
|
width,
|
|
|
|
top,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
function resultsGroupLabel(type, renderedResults, allResults, truncated) {
|
2020-08-05 20:58:44 +00:00
|
|
|
let countString;
|
|
|
|
|
|
|
|
if (renderedResults.length < allResults.length) {
|
|
|
|
countString = `showing ${renderedResults.length} of ${allResults.length}`;
|
|
|
|
} else {
|
|
|
|
countString = renderedResults.length;
|
|
|
|
}
|
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
const truncationIndicator = truncated ? '+' : '';
|
|
|
|
|
|
|
|
return `${type} (${countString}${truncationIndicator})`;
|
2020-08-05 20:58:44 +00:00
|
|
|
}
|