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|}}
|
{{#each (sort-by 'Name' dcs) as |item|}}
|
||||||
<MenuItem
|
<MenuItem
|
||||||
data-test-datacenter-picker
|
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)}}
|
@href={{href-mut (hash dc=item.Name)}}
|
||||||
>
|
>
|
||||||
<BlockSlot @name="label">
|
<BlockSlot @name="label">
|
||||||
|
|
|
@ -7,6 +7,7 @@ export const SLUG_KEY = 'Name';
|
||||||
export default class Datacenter extends Model {
|
export default class Datacenter extends Model {
|
||||||
@attr('string') uid;
|
@attr('string') uid;
|
||||||
@attr('string') Name;
|
@attr('string') Name;
|
||||||
|
@attr('boolean') Local;
|
||||||
|
|
||||||
@attr('boolean', { defaultValue: () => true }) MeshEnabled;
|
@attr('boolean', { defaultValue: () => true }) MeshEnabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
import Serializer from './application';
|
import Serializer from './application';
|
||||||
|
|
||||||
export default class DcSerializer extends Serializer {
|
export default class DcSerializer extends Serializer {
|
||||||
|
@service('env') env;
|
||||||
|
|
||||||
primaryKey = 'Name';
|
primaryKey = 'Name';
|
||||||
|
|
||||||
respondForQuery(respond, query) {
|
respondForQuery(respond, query) {
|
||||||
|
@ -14,6 +17,7 @@ export default class DcSerializer extends Serializer {
|
||||||
case 'query':
|
case 'query':
|
||||||
return payload.map(item => {
|
return payload.map(item => {
|
||||||
return {
|
return {
|
||||||
|
Local: this.env.var('CONSUL_DATACENTER_LOCAL') === item,
|
||||||
[this.primaryKey]: item,
|
[this.primaryKey]: item,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,8 +5,8 @@ import Error from '@ember/error';
|
||||||
|
|
||||||
const modelName = 'dc';
|
const modelName = 'dc';
|
||||||
export default class DcService extends RepositoryService {
|
export default class DcService extends RepositoryService {
|
||||||
@service('settings')
|
@service('settings') settings;
|
||||||
settings;
|
@service('env') env;
|
||||||
|
|
||||||
getModelName() {
|
getModelName() {
|
||||||
return modelName;
|
return modelName;
|
||||||
|
@ -35,8 +35,10 @@ export default class DcService extends RepositoryService {
|
||||||
const settings = this.settings;
|
const settings = this.settings;
|
||||||
return Promise.all([name || settings.findBySlug('dc'), items || this.findAll()]).then(
|
return Promise.all([name || settings.findBySlug('dc'), items || this.findAll()]).then(
|
||||||
([name, items]) => {
|
([name, items]) => {
|
||||||
return this.findBySlug(name, items).catch(function() {
|
return this.findBySlug(name, items).catch(e => {
|
||||||
const item = get(items, 'firstObject');
|
const item =
|
||||||
|
items.findBy('Name', this.env.var('CONSUL_DATACENTER_LOCAL')) ||
|
||||||
|
get(items, 'firstObject');
|
||||||
settings.persist({ dc: get(item, 'Name') });
|
settings.persist({ dc: get(item, 'Name') });
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,7 @@ test('findAll returns the correct data for list endpoint', function(assert) {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
actual,
|
actual,
|
||||||
expected(function(payload) {
|
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