-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8207 from hashicorp/f-ui/manual-scaling-controls
UI: Task Group Scaling Controls
- Loading branch information
Showing
31 changed files
with
982 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import AbstractAbility from './abstract'; | ||
import { computed, get } from '@ember/object'; | ||
import { computed } from '@ember/object'; | ||
import { or } from '@ember/object/computed'; | ||
|
||
export default class Job extends AbstractAbility { | ||
@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesSupportRunning') | ||
canRun; | ||
|
||
@or( | ||
'bypassAuthorization', | ||
'selfTokenIsManagement', | ||
'policiesSupportRunning', | ||
'policiesSupportScaling' | ||
) | ||
canScale; | ||
|
||
@computed('[email protected]') | ||
get policiesSupportRunning() { | ||
return this.rulesForActiveNamespace.some(rules => { | ||
let capabilities = get(rules, 'Capabilities') || []; | ||
return capabilities.includes('submit-job'); | ||
}); | ||
return this.activeNamespaceIncludesCapability('submit-job'); | ||
} | ||
|
||
@computed('[email protected]') | ||
get policiesSupportScaling() { | ||
return this.activeNamespaceIncludesCapability('scale-job'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Component from '@ember/component'; | ||
import { action } from '@ember/object'; | ||
import { debounce } from '@ember/runloop'; | ||
import { oneWay } from '@ember/object/computed'; | ||
import { classNames, classNameBindings } from '@ember-decorators/component'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
const ESC = 27; | ||
|
||
@classic | ||
@classNames('stepper-input') | ||
@classNameBindings('class', 'disabled:is-disabled') | ||
export default class StepperInput extends Component { | ||
min = 0; | ||
max = 10; | ||
value = 0; | ||
debounce = 500; | ||
onChange() {} | ||
|
||
// Internal value changes immediately for instant visual feedback. | ||
// Value is still the public API and is expected to mutate and re-render | ||
// On onChange which is debounced. | ||
@oneWay('value') internalValue; | ||
|
||
@action | ||
increment() { | ||
if (this.internalValue < this.max) { | ||
this.incrementProperty('internalValue'); | ||
this.update(this.internalValue); | ||
} | ||
} | ||
|
||
@action | ||
decrement() { | ||
if (this.internalValue > this.min) { | ||
this.decrementProperty('internalValue'); | ||
this.update(this.internalValue); | ||
} | ||
} | ||
|
||
@action | ||
setValue(e) { | ||
const newValue = Math.min(this.max, Math.max(this.min, e.target.value)); | ||
this.set('internalValue', newValue); | ||
this.update(this.internalValue); | ||
} | ||
|
||
@action | ||
resetTextInput(e) { | ||
if (e.keyCode === ESC) { | ||
e.target.value = this.internalValue; | ||
} | ||
} | ||
|
||
update(value) { | ||
debounce(this, sendUpdateAction, value, this.debounce); | ||
} | ||
} | ||
|
||
function sendUpdateAction(value) { | ||
return this.onChange(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,64 @@ | ||
import Component from '@ember/component'; | ||
import { lazyClick } from '../helpers/lazy-click'; | ||
import { computed, action } from '@ember/object'; | ||
import { alias, oneWay } from '@ember/object/computed'; | ||
import { debounce } from '@ember/runloop'; | ||
import { classNames, tagName } from '@ember-decorators/component'; | ||
import classic from 'ember-classic-decorator'; | ||
import { lazyClick } from '../helpers/lazy-click'; | ||
|
||
@classic | ||
@tagName('tr') | ||
@classNames('task-group-row', 'is-interactive') | ||
export default class TaskGroupRow extends Component { | ||
taskGroup = null; | ||
debounce = 500; | ||
|
||
@oneWay('taskGroup.count') count; | ||
@alias('taskGroup.job.runningDeployment') runningDeployment; | ||
|
||
onClick() {} | ||
|
||
click(event) { | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Fragment from 'ember-data-model-fragments/fragment'; | ||
import attr from 'ember-data/attr'; | ||
import { fragmentOwner } from 'ember-data-model-fragments/attributes'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
export default class TaskGroup extends Fragment { | ||
@fragmentOwner() taskGroup; | ||
|
||
@attr('boolean') enabled; | ||
@attr('number') max; | ||
@attr('number') min; | ||
|
||
@attr() policy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { computed } from '@ember/object'; | ||
import Fragment from 'ember-data-model-fragments/fragment'; | ||
import attr from 'ember-data/attr'; | ||
import { fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes'; | ||
import { fragmentOwner, fragmentArray, fragment } from 'ember-data-model-fragments/attributes'; | ||
import sumAggregation from '../utils/properties/sum-aggregation'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
|
@@ -20,6 +20,8 @@ export default class TaskGroup extends Fragment { | |
|
||
@fragmentArray('volume-definition') volumes; | ||
|
||
@fragment('group-scaling') scaling; | ||
|
||
@computed('[email protected]') | ||
get drivers() { | ||
return this.tasks.mapBy('driver').uniq(); | ||
|
@@ -51,4 +53,8 @@ export default class TaskGroup extends Fragment { | |
get summary() { | ||
return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name); | ||
} | ||
|
||
scale(count, reason) { | ||
return this.job.scale(this.name, count, reason); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.