open-nomad/ui/app/components/task-group-row.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.2 KiB
JavaScript
Raw Normal View History

import Component from '@ember/component';
2020-06-29 22:53:52 +00:00
import { inject as service } from '@ember/service';
import { computed, action } from '@ember/object';
import { alias, oneWay } from '@ember/object/computed';
import { debounce } from '@ember/runloop';
ui: fix an error when navigating to a task group (#12832) Clicking in a task group row in the job details page would throw the error: Uncaught Error: You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route jobs.job.task-group. Missing params: name createParamHandlerInfo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4814 applyToHandlers http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4804 applyToState http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4801 getTransitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4843 transitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4836 refresh http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4885 refresh http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2254 queryParamsDidChange http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2326 k http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2423 triggerEvent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2349 fireQueryParamDidChange http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4863 getTransitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4848 transitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4836 doTransition http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4853 transitionTo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4882 _doTransition http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2392 transitionTo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2177 gotoTaskGroup http://localhost:4646/ui/assets/nomad-ui-4a2c1941e03e60e1feef715f23cf268c.js:623 ... This was caused because the attribute being passed to the transitionTo function was not the task group name, but the whole model.
2022-05-02 15:01:19 +00:00
import {
classNames,
tagName,
attributeBindings,
} from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
import { lazyClick } from '../helpers/lazy-click';
2017-09-19 14:47:10 +00:00
@classic
@tagName('tr')
@classNames('task-group-row', 'is-interactive')
ui: fix an error when navigating to a task group (#12832) Clicking in a task group row in the job details page would throw the error: Uncaught Error: You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route jobs.job.task-group. Missing params: name createParamHandlerInfo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4814 applyToHandlers http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4804 applyToState http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4801 getTransitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4843 transitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4836 refresh http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4885 refresh http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2254 queryParamsDidChange http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2326 k http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2423 triggerEvent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2349 fireQueryParamDidChange http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4863 getTransitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4848 transitionByIntent http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4836 doTransition http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4853 transitionTo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:4882 _doTransition http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2392 transitionTo http://localhost:4646/ui/assets/vendor-194b1e0d68d11ef7a4bf334eb30ba74d.js:2177 gotoTaskGroup http://localhost:4646/ui/assets/nomad-ui-4a2c1941e03e60e1feef715f23cf268c.js:623 ... This was caused because the attribute being passed to the transitionTo function was not the task group name, but the whole model.
2022-05-02 15:01:19 +00:00
@attributeBindings('data-test-task-group')
export default class TaskGroupRow extends Component {
2020-06-29 22:53:52 +00:00
@service can;
taskGroup = null;
2020-06-18 20:19:25 +00:00
debounce = 500;
@oneWay('taskGroup.count') count;
@alias('taskGroup.job.runningDeployment') runningDeployment;
2017-09-19 14:47:10 +00:00
get namespace() {
return this.get('taskGroup.job.namespace.name');
}
@computed('runningDeployment', 'namespace')
2020-06-29 22:53:52 +00:00
get tooltipText() {
if (this.can.cannot('scale job', null, { namespace: this.namespace }))
return "You aren't allowed to scale task groups";
2021-12-28 16:08:12 +00:00
if (this.runningDeployment)
return 'You cannot scale task groups during a deployment';
2020-06-29 22:53:52 +00:00
return undefined;
}
onClick() {}
2017-09-19 14:47:10 +00:00
click(event) {
2019-03-26 07:46:44 +00:00
lazyClick([this.onClick, event]);
}
@computed('count', 'taskGroup.scaling.min')
get isMinimum() {
const scaling = this.taskGroup.scaling;
if (!scaling || scaling.min == null) return false;
return this.count <= scaling.min;
}
@computed('count', 'taskGroup.scaling.max')
get isMaximum() {
const scaling = this.taskGroup.scaling;
if (!scaling || scaling.max == null) return false;
return this.count >= scaling.max;
}
@action
countUp() {
const scaling = this.taskGroup.scaling;
if (!scaling || scaling.max == null || this.count < scaling.max) {
this.incrementProperty('count');
this.scale(this.count);
}
}
@action
countDown() {
const scaling = this.taskGroup.scaling;
if (!scaling || scaling.min == null || this.count > scaling.min) {
this.decrementProperty('count');
this.scale(this.count);
}
}
scale(count) {
debounce(this, sendCountAction, count, this.debounce);
}
}
function sendCountAction(count) {
return this.taskGroup.scale(count);
}