2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-08-06 21:16:34 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2018-08-06 21:16:34 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class RegionSwitcher extends Component {
|
|
|
|
@service system;
|
|
|
|
@service router;
|
|
|
|
@service store;
|
2018-08-06 21:16:34 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('system.regions')
|
|
|
|
get sortedRegions() {
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.get('system.regions').toArray().sort();
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-08-06 21:16:34 +00:00
|
|
|
|
|
|
|
gotoRegion(region) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.router.transitionTo('jobs', {
|
2018-08-10 01:12:26 +00:00
|
|
|
queryParams: { region },
|
2018-08-06 21:16:34 +00:00
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2023-05-12 15:46:00 +00:00
|
|
|
|
|
|
|
get keyCommands() {
|
|
|
|
if (this.sortedRegions.length <= 1) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return this.sortedRegions.map((region, iter) => {
|
|
|
|
return {
|
|
|
|
label: `Switch to ${region} region`,
|
|
|
|
pattern: ['r', `${iter + 1}`],
|
|
|
|
action: () => this.gotoRegion(region),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|