2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-04-30 13:15:19 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { sort } from '@ember/object/computed';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class LifecycleChart extends Component {
|
|
|
|
tasks = null;
|
|
|
|
taskStates = null;
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('tasks.@each.lifecycle', 'taskStates.@each.state')
|
|
|
|
get lifecyclePhases() {
|
2020-04-30 13:15:19 +00:00
|
|
|
const tasksOrStates = this.taskStates || this.tasks;
|
|
|
|
const lifecycles = {
|
2020-08-25 17:17:18 +00:00
|
|
|
'prestart-ephemerals': [],
|
|
|
|
'prestart-sidecars': [],
|
|
|
|
'poststart-ephemerals': [],
|
|
|
|
'poststart-sidecars': [],
|
|
|
|
poststops: [],
|
2020-04-30 13:15:19 +00:00
|
|
|
mains: [],
|
|
|
|
};
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
tasksOrStates.forEach((taskOrState) => {
|
2020-04-30 13:15:19 +00:00
|
|
|
const task = taskOrState.task || taskOrState;
|
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
|
|
|
|
|
|
|
if (task.lifecycleName) {
|
|
|
|
lifecycles[`${task.lifecycleName}s`].push(taskOrState);
|
|
|
|
}
|
2020-04-30 13:15:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const phases = [];
|
2021-12-28 14:45:20 +00:00
|
|
|
const stateActiveIterator = (state) => state.state === 'running';
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
if (lifecycles.mains.length < tasksOrStates.length) {
|
2020-04-30 13:15:19 +00:00
|
|
|
phases.push({
|
|
|
|
name: 'Prestart',
|
2020-08-25 17:17:18 +00:00
|
|
|
isActive: lifecycles['prestart-ephemerals'].some(stateActiveIterator),
|
2020-04-30 13:15:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
phases.push({
|
|
|
|
name: 'Main',
|
2020-08-25 17:17:18 +00:00
|
|
|
isActive:
|
|
|
|
lifecycles.mains.some(stateActiveIterator) ||
|
|
|
|
lifecycles['poststart-ephemerals'].some(stateActiveIterator),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Poststart is rendered as a subphase of main and therefore has no independent active state
|
|
|
|
phases.push({
|
|
|
|
name: 'Poststart',
|
|
|
|
});
|
2020-09-01 16:49:36 +00:00
|
|
|
|
|
|
|
phases.push({
|
|
|
|
name: 'Poststop',
|
|
|
|
isActive: lifecycles.poststops.some(stateActiveIterator),
|
|
|
|
});
|
2020-04-30 13:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return phases;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@sort('taskStates', function (a, b) {
|
2020-04-30 13:15:19 +00:00
|
|
|
return getTaskSortPrefix(a.task).localeCompare(getTaskSortPrefix(b.task));
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
sortedLifecycleTaskStates;
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@sort('tasks', function (a, b) {
|
2020-04-30 13:15:19 +00:00
|
|
|
return getTaskSortPrefix(a).localeCompare(getTaskSortPrefix(b));
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
sortedLifecycleTasks;
|
|
|
|
}
|
2020-04-30 13:15:19 +00:00
|
|
|
|
|
|
|
const lifecycleNameSortPrefix = {
|
2020-08-25 17:17:18 +00:00
|
|
|
'prestart-ephemeral': 0,
|
|
|
|
'prestart-sidecar': 1,
|
2020-04-30 13:15:19 +00:00
|
|
|
main: 2,
|
2020-08-25 17:17:18 +00:00
|
|
|
'poststart-sidecar': 3,
|
|
|
|
'poststart-ephemeral': 4,
|
|
|
|
poststop: 5,
|
2020-04-30 13:15:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function getTaskSortPrefix(task) {
|
|
|
|
return `${lifecycleNameSortPrefix[task.lifecycleName]}-${task.name}`;
|
|
|
|
}
|