mirror of https://github.com/status-im/consul.git
ui: Configure routes in route config rather than classes (#11900)
This commit is contained in:
parent
99ee07d2d1
commit
64767b53e7
|
@ -3,6 +3,11 @@
|
|||
nspaces: {
|
||||
_options: {
|
||||
path: '/namespaces',
|
||||
abilities: ['read nspaces'],
|
||||
},
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
searchproperty: {
|
||||
|
@ -14,7 +19,7 @@
|
|||
replace: true,
|
||||
},
|
||||
},
|
||||
abilities: ['read nspaces'],
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
_options: { path: '/:name' },
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
partitions: {
|
||||
_options: {
|
||||
path: '/partitions',
|
||||
abilities: ['read partitions'],
|
||||
},
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
searchproperty: {
|
||||
|
@ -14,7 +19,7 @@
|
|||
replace: true,
|
||||
},
|
||||
},
|
||||
abilities: ['read partitions'],
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
_options: { path: '/:name' },
|
||||
|
|
|
@ -19,33 +19,123 @@ export const routes = merge.all(
|
|||
// Our parent datacenter resource sets the namespace
|
||||
// for the entire application
|
||||
dc: {
|
||||
_options: { path: '/:dc' },
|
||||
_options: {
|
||||
path: '/:dc',
|
||||
},
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
redirect: '../services',
|
||||
},
|
||||
},
|
||||
// Services represent a consul service
|
||||
services: {
|
||||
_options: { path: '/services' },
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
source: 'source',
|
||||
kind: 'kind',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Show an individual service
|
||||
show: {
|
||||
_options: { path: '/:name' },
|
||||
instances: {
|
||||
_options: { path: '/instances' },
|
||||
_options: {
|
||||
path: '/instances',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
source: 'source',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Node', 'Tags', 'ID', 'Address', 'Port', 'Service.Meta', 'Node.Meta']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
intentions: {
|
||||
_options: { path: '/intentions' },
|
||||
index: {
|
||||
_options: {
|
||||
path: '',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
access: 'access',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['SourceName', 'DestinationName']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
_options: { path: '/:intention_id' },
|
||||
},
|
||||
create: {
|
||||
_options: { path: '/create' },
|
||||
_options: {
|
||||
template: 'dc/services/show/intentions/edit',
|
||||
path: '/create',
|
||||
},
|
||||
},
|
||||
},
|
||||
topology: {
|
||||
_options: { path: '/topology' },
|
||||
},
|
||||
services: {
|
||||
_options: { path: '/services' },
|
||||
_options: {
|
||||
path: '/services',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
instance: 'instance',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
upstreams: {
|
||||
_options: { path: '/upstreams' },
|
||||
_options: {
|
||||
path: '/upstreams',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
instance: 'instance',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
_options: { path: '/routing' },
|
||||
|
@ -55,12 +145,43 @@ export const routes = merge.all(
|
|||
},
|
||||
},
|
||||
instance: {
|
||||
_options: { path: '/:name/instances/:node/:id' },
|
||||
_options: {
|
||||
path: '/:name/instances/:node/:id',
|
||||
redirect: './healthchecks',
|
||||
},
|
||||
healthchecks: {
|
||||
_options: { path: '/health-checks' },
|
||||
_options: {
|
||||
path: '/health-checks',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
check: 'check',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Node', 'CheckID', 'Notes', 'Output', 'ServiceTags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
upstreams: {
|
||||
_options: { path: '/upstreams' },
|
||||
_options: {
|
||||
path: '/upstreams',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['DestinationName', 'LocalBindAddress', 'LocalBindPort']],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
exposedpaths: {
|
||||
_options: { path: '/exposed-paths' },
|
||||
|
@ -79,14 +200,62 @@ export const routes = merge.all(
|
|||
// Nodes represent a consul node
|
||||
nodes: {
|
||||
_options: { path: '/nodes' },
|
||||
index: {
|
||||
_options: {
|
||||
path: '',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Node', 'Address', 'Meta']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Show an individual node
|
||||
show: {
|
||||
_options: { path: '/:name' },
|
||||
healthchecks: {
|
||||
_options: { path: '/health-checks' },
|
||||
_options: {
|
||||
path: '/health-checks',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
kind: 'kind',
|
||||
check: 'check',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Service', 'CheckID', 'Notes', 'Output', 'ServiceTags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
services: {
|
||||
_options: { path: '/service-instances' },
|
||||
_options: {
|
||||
path: '/service-instances',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
source: 'source',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags', 'ID', 'Address', 'Port', 'Service.Meta']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
rtt: {
|
||||
_options: { path: '/round-trip-time' },
|
||||
|
@ -102,6 +271,23 @@ export const routes = merge.all(
|
|||
// Intentions represent a consul intention
|
||||
intentions: {
|
||||
_options: { path: '/intentions' },
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
access: 'access',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['SourceName', 'DestinationName']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
_options: {
|
||||
path: '/:intention_id',
|
||||
|
@ -110,6 +296,7 @@ export const routes = merge.all(
|
|||
},
|
||||
create: {
|
||||
_options: {
|
||||
template: 'dc/intentions/edit',
|
||||
path: '/create',
|
||||
abilities: ['create intentions'],
|
||||
},
|
||||
|
@ -118,20 +305,38 @@ export const routes = merge.all(
|
|||
// Key/Value
|
||||
kv: {
|
||||
_options: { path: '/kv' },
|
||||
index: {
|
||||
_options: {
|
||||
path: '/',
|
||||
queryParams: {
|
||||
sortBy: 'sort',
|
||||
kind: 'kind',
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
folder: {
|
||||
_options: { path: '/*key' },
|
||||
_options: {
|
||||
template: 'dc/kv/index',
|
||||
path: '/*key',
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
_options: { path: '/*key/edit' },
|
||||
},
|
||||
create: {
|
||||
_options: {
|
||||
template: 'dc/kv/edit',
|
||||
path: '/*key/create',
|
||||
abilities: ['create kvs'],
|
||||
},
|
||||
},
|
||||
'root-create': {
|
||||
_options: {
|
||||
template: 'dc/kv/edit',
|
||||
path: '/create',
|
||||
abilities: ['create kvs'],
|
||||
},
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
import to from 'consul-ui/utils/routing/redirect-to';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
redirect = to('services');
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class CreateRoute extends Route {
|
||||
templateName = 'dc/intentions/edit';
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
access: 'access',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['SourceName', 'DestinationName']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class CreateRoute extends Route {
|
||||
templateName = 'dc/kv/edit';
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
import Route from './index';
|
||||
|
||||
export default class FolderRoute extends Route {
|
||||
templateName = 'dc/kv/index';
|
||||
|
||||
beforeModel(transition) {
|
||||
super.beforeModel(...arguments);
|
||||
const params = this.paramsFor('dc.kv.folder');
|
||||
|
|
|
@ -3,15 +3,6 @@ import { action } from '@ember/object';
|
|||
import isFolder from 'consul-ui/utils/isFolder';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
kind: 'kind',
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
|
||||
beforeModel() {
|
||||
// we are index or folder, so if the key doesn't have a trailing slash
|
||||
// add one to force a fake findBySlug
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import Route from './create';
|
||||
|
||||
export default class RootCreateRoute extends Route {}
|
|
@ -1,16 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Node', 'Address', 'Meta']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class HealthchecksRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
kind: 'kind',
|
||||
check: 'check',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Service', 'CheckID', 'Notes', 'Output', 'ServiceTags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class ServicesRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
source: 'source',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags', 'ID', 'Address', 'Port', 'Service.Meta']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
source: 'source',
|
||||
kind: 'kind',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class HealthchecksRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
status: 'status',
|
||||
check: 'check',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Node', 'CheckID', 'Notes', 'Output', 'ServiceTags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
import to from 'consul-ui/utils/routing/redirect-to';
|
||||
|
||||
export default class InstanceIndexRoute extends Route {
|
||||
redirect = to('healthchecks');
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class UpstreamsRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['DestinationName', 'LocalBindAddress', 'LocalBindPort']],
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class CreateRoute extends Route {
|
||||
templateName = 'dc/services/show/intentions/edit';
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class IndexRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
access: 'access',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['SourceName', 'DestinationName']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class ServicesRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
instance: 'instance',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
import Route from 'consul-ui/routing/route';
|
||||
|
||||
export default class UpstreamsRoute extends Route {
|
||||
queryParams = {
|
||||
sortBy: 'sort',
|
||||
instance: 'instance',
|
||||
searchproperty: {
|
||||
as: 'searchproperty',
|
||||
empty: [['Name', 'Tags']],
|
||||
},
|
||||
search: {
|
||||
as: 'filter',
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -13,36 +13,40 @@ export default class BaseRoute extends Route {
|
|||
|
||||
_setRouteName() {
|
||||
super._setRouteName(...arguments);
|
||||
const routeName = this.routeName
|
||||
.split('.')
|
||||
.filter(item => item !== 'index')
|
||||
.join('.');
|
||||
const template = get(routes, `${routeName}._options.template`);
|
||||
if (template) {
|
||||
|
||||
const template = get(routes, `${this.routeName}._options.template`);
|
||||
if (typeof template !== 'undefined') {
|
||||
this.templateName = template;
|
||||
}
|
||||
const queryParams = get(routes, `${routeName}._options.queryParams`);
|
||||
if (
|
||||
queryParams &&
|
||||
['dc.partitions.index', 'dc.nspaces.index', 'oauth-provider-debug'].includes(this.routeName)
|
||||
) {
|
||||
|
||||
const queryParams = get(routes, `${this.routeName}._options.queryParams`);
|
||||
if (typeof queryParams !== 'undefined') {
|
||||
this.queryParams = queryParams;
|
||||
}
|
||||
}
|
||||
|
||||
redirect(model, transition) {
|
||||
// remove any references to index as it is the same as the root routeName
|
||||
const routeName = this.routeName
|
||||
.split('.')
|
||||
.filter(item => item !== 'index')
|
||||
.join('.');
|
||||
const to = get(routes, `${routeName}._options.redirect`);
|
||||
let to = get(routes, `${this.routeName}._options.redirect`);
|
||||
if (typeof to !== 'undefined') {
|
||||
// simple path resolve
|
||||
to = to
|
||||
.split('/')
|
||||
.reduce((prev, item, i, items) => {
|
||||
if (item !== '.') {
|
||||
if (item === '..') {
|
||||
prev.pop();
|
||||
} else if (item !== '' || i === items.length - 1) {
|
||||
prev.push(item);
|
||||
}
|
||||
}
|
||||
return prev;
|
||||
}, this.routeName.split('.'))
|
||||
.join('.');
|
||||
// TODO: Does this need to return?
|
||||
// Almost remember things getting strange if you returned from here
|
||||
// which is why I didn't do it originally so be sure to look properly if
|
||||
// you feel like adding a return
|
||||
this.replaceWith(`${routeName}${to}`, model);
|
||||
this.replaceWith(`${to}`, model);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:dc/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/intentions/create', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:dc/intentions/create');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/intentions/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:dc/intentions/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import { module, skip } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/kv/create', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
skip('it exists', function(assert) {
|
||||
let route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/kv/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:dc/kv/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | dc/kv/root create', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:dc/kv/root-create');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue