ui: Show local datacenter by default on first visit (#9377)
* Add `Local` property to Datacenters * If you have not previous datacenter, redirect the user to the local dc * Add an `is-local` class to the local datacenter in the DC picker
This commit is contained in:
parent
493ebb0713
commit
a1b3f00a69
|
@ -90,7 +90,7 @@
|
|||
{{#each (sort-by 'Name' dcs) as |item|}}
|
||||
<MenuItem
|
||||
data-test-datacenter-picker
|
||||
class={{if (eq dc.Name item.Name) 'is-active'}}
|
||||
class={{concat (if (eq dc.Name item.Name) 'is-active') (if item.Local ' is-local') }}
|
||||
@href={{href-mut (hash dc=item.Name)}}
|
||||
>
|
||||
<BlockSlot @name="label">
|
||||
|
|
|
@ -7,6 +7,7 @@ export const SLUG_KEY = 'Name';
|
|||
export default class Datacenter extends Model {
|
||||
@attr('string') uid;
|
||||
@attr('string') Name;
|
||||
@attr('boolean') Local;
|
||||
|
||||
@attr('boolean', { defaultValue: () => true }) MeshEnabled;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { inject as service } from '@ember/service';
|
||||
import Serializer from './application';
|
||||
|
||||
export default class DcSerializer extends Serializer {
|
||||
@service('env') env;
|
||||
|
||||
primaryKey = 'Name';
|
||||
|
||||
respondForQuery(respond, query) {
|
||||
|
@ -14,6 +17,7 @@ export default class DcSerializer extends Serializer {
|
|||
case 'query':
|
||||
return payload.map(item => {
|
||||
return {
|
||||
Local: this.env.var('CONSUL_DATACENTER_LOCAL') === item,
|
||||
[this.primaryKey]: item,
|
||||
};
|
||||
});
|
||||
|
|
|
@ -5,8 +5,8 @@ import Error from '@ember/error';
|
|||
|
||||
const modelName = 'dc';
|
||||
export default class DcService extends RepositoryService {
|
||||
@service('settings')
|
||||
settings;
|
||||
@service('settings') settings;
|
||||
@service('env') env;
|
||||
|
||||
getModelName() {
|
||||
return modelName;
|
||||
|
@ -35,8 +35,10 @@ export default class DcService extends RepositoryService {
|
|||
const settings = this.settings;
|
||||
return Promise.all([name || settings.findBySlug('dc'), items || this.findAll()]).then(
|
||||
([name, items]) => {
|
||||
return this.findBySlug(name, items).catch(function() {
|
||||
const item = get(items, 'firstObject');
|
||||
return this.findBySlug(name, items).catch(e => {
|
||||
const item =
|
||||
items.findBy('Name', this.env.var('CONSUL_DATACENTER_LOCAL')) ||
|
||||
get(items, 'firstObject');
|
||||
settings.persist({ dc: get(item, 'Name') });
|
||||
return item;
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ test('findAll returns the correct data for list endpoint', function(assert) {
|
|||
assert.deepEqual(
|
||||
actual,
|
||||
expected(function(payload) {
|
||||
return payload.map(item => ({ Name: item }));
|
||||
return payload.map((item, i) => ({ Name: item, Local: i === 0 ? true : false }));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue