ui: Configure routes in route config rather than classes (#11900)

This commit is contained in:
John Cowen 2022-01-05 09:34:28 +00:00 committed by GitHub
parent 7abfe6bff9
commit 98aac0855c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 268 additions and 321 deletions

View File

@ -3,18 +3,23 @@
nspaces: { nspaces: {
_options: { _options: {
path: '/namespaces', path: '/namespaces',
queryParams: { abilities: ['read nspaces'],
sortBy: 'sort', },
searchproperty: { index: {
as: 'searchproperty', _options: {
empty: [['Name', 'Description', 'Role', 'Policy']], path: '/',
}, queryParams: {
search: { sortBy: 'sort',
as: 'filter', searchproperty: {
replace: true, as: 'searchproperty',
empty: [['Name', 'Description', 'Role', 'Policy']],
},
search: {
as: 'filter',
replace: true,
},
}, },
}, },
abilities: ['read nspaces'],
}, },
edit: { edit: {
_options: { path: '/:name' }, _options: { path: '/:name' },

View File

@ -3,18 +3,23 @@
partitions: { partitions: {
_options: { _options: {
path: '/partitions', path: '/partitions',
queryParams: { abilities: ['read partitions'],
sortBy: 'sort', },
searchproperty: { index: {
as: 'searchproperty', _options: {
empty: [['Name', 'Description']], path: '/',
}, queryParams: {
search: { sortBy: 'sort',
as: 'filter', searchproperty: {
replace: true, as: 'searchproperty',
empty: [['Name', 'Description']],
},
search: {
as: 'filter',
replace: true,
},
}, },
}, },
abilities: ['read partitions'],
}, },
edit: { edit: {
_options: { path: '/:name' }, _options: { path: '/:name' },

View File

@ -19,33 +19,123 @@ export const routes = merge.all(
// Our parent datacenter resource sets the namespace // Our parent datacenter resource sets the namespace
// for the entire application // for the entire application
dc: { dc: {
_options: { path: '/:dc' }, _options: {
path: '/:dc',
},
index: {
_options: {
path: '/',
redirect: '../services',
},
},
// Services represent a consul service // Services represent a consul service
services: { services: {
_options: { path: '/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 an individual service
show: { show: {
_options: { path: '/:name' }, _options: { path: '/:name' },
instances: { 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: { intentions: {
_options: { path: '/intentions' }, _options: { path: '/intentions' },
index: {
_options: {
path: '',
queryParams: {
sortBy: 'sort',
access: 'access',
searchproperty: {
as: 'searchproperty',
empty: [['SourceName', 'DestinationName']],
},
search: {
as: 'filter',
replace: true,
},
},
},
},
edit: { edit: {
_options: { path: '/:intention_id' }, _options: { path: '/:intention_id' },
}, },
create: { create: {
_options: { path: '/create' }, _options: {
template: 'dc/services/show/intentions/edit',
path: '/create',
},
}, },
}, },
topology: { topology: {
_options: { path: '/topology' }, _options: { path: '/topology' },
}, },
services: { services: {
_options: { path: '/services' }, _options: {
path: '/services',
queryParams: {
sortBy: 'sort',
instance: 'instance',
searchproperty: {
as: 'searchproperty',
empty: [['Name', 'Tags']],
},
search: {
as: 'filter',
replace: true,
},
},
},
}, },
upstreams: { upstreams: {
_options: { path: '/upstreams' }, _options: {
path: '/upstreams',
queryParams: {
sortBy: 'sort',
instance: 'instance',
searchproperty: {
as: 'searchproperty',
empty: [['Name', 'Tags']],
},
search: {
as: 'filter',
replace: true,
},
},
},
}, },
routing: { routing: {
_options: { path: '/routing' }, _options: { path: '/routing' },
@ -55,12 +145,43 @@ export const routes = merge.all(
}, },
}, },
instance: { instance: {
_options: { path: '/:name/instances/:node/:id' }, _options: {
path: '/:name/instances/:node/:id',
redirect: './healthchecks',
},
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: { upstreams: {
_options: { path: '/upstreams' }, _options: {
path: '/upstreams',
queryParams: {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
searchproperty: {
as: 'searchproperty',
empty: [['DestinationName', 'LocalBindAddress', 'LocalBindPort']],
},
},
},
}, },
exposedpaths: { exposedpaths: {
_options: { path: '/exposed-paths' }, _options: { path: '/exposed-paths' },
@ -79,14 +200,62 @@ export const routes = merge.all(
// Nodes represent a consul node // Nodes represent a consul node
nodes: { nodes: {
_options: { path: '/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 an individual node
show: { show: {
_options: { path: '/:name' }, _options: { path: '/:name' },
healthchecks: { 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: { 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: { rtt: {
_options: { path: '/round-trip-time' }, _options: { path: '/round-trip-time' },
@ -102,6 +271,23 @@ export const routes = merge.all(
// Intentions represent a consul intention // Intentions represent a consul intention
intentions: { intentions: {
_options: { path: '/intentions' }, _options: { path: '/intentions' },
index: {
_options: {
path: '/',
queryParams: {
sortBy: 'sort',
access: 'access',
searchproperty: {
as: 'searchproperty',
empty: [['SourceName', 'DestinationName']],
},
search: {
as: 'filter',
replace: true,
},
},
},
},
edit: { edit: {
_options: { _options: {
path: '/:intention_id', path: '/:intention_id',
@ -110,6 +296,7 @@ export const routes = merge.all(
}, },
create: { create: {
_options: { _options: {
template: 'dc/intentions/edit',
path: '/create', path: '/create',
abilities: ['create intentions'], abilities: ['create intentions'],
}, },
@ -118,20 +305,38 @@ export const routes = merge.all(
// Key/Value // Key/Value
kv: { kv: {
_options: { path: '/kv' }, _options: { path: '/kv' },
index: {
_options: {
path: '/',
queryParams: {
sortBy: 'sort',
kind: 'kind',
search: {
as: 'filter',
replace: true,
},
},
},
},
folder: { folder: {
_options: { path: '/*key' }, _options: {
template: 'dc/kv/index',
path: '/*key',
},
}, },
edit: { edit: {
_options: { path: '/*key/edit' }, _options: { path: '/*key/edit' },
}, },
create: { create: {
_options: { _options: {
template: 'dc/kv/edit',
path: '/*key/create', path: '/*key/create',
abilities: ['create kvs'], abilities: ['create kvs'],
}, },
}, },
'root-create': { 'root-create': {
_options: { _options: {
template: 'dc/kv/edit',
path: '/create', path: '/create',
abilities: ['create kvs'], abilities: ['create kvs'],
}, },

View File

@ -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');
}

View File

@ -1,5 +0,0 @@
import Route from 'consul-ui/routing/route';
export default class CreateRoute extends Route {
templateName = 'dc/intentions/edit';
}

View File

@ -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,
},
};
}

View File

@ -1,5 +0,0 @@
import Route from 'consul-ui/routing/route';
export default class CreateRoute extends Route {
templateName = 'dc/kv/edit';
}

View File

@ -1,8 +1,6 @@
import Route from './index'; import Route from './index';
export default class FolderRoute extends Route { export default class FolderRoute extends Route {
templateName = 'dc/kv/index';
beforeModel(transition) { beforeModel(transition) {
super.beforeModel(...arguments); super.beforeModel(...arguments);
const params = this.paramsFor('dc.kv.folder'); const params = this.paramsFor('dc.kv.folder');

View File

@ -3,15 +3,6 @@ import { action } from '@ember/object';
import isFolder from 'consul-ui/utils/isFolder'; import isFolder from 'consul-ui/utils/isFolder';
export default class IndexRoute extends Route { export default class IndexRoute extends Route {
queryParams = {
sortBy: 'sort',
kind: 'kind',
search: {
as: 'filter',
replace: true,
},
};
beforeModel() { beforeModel() {
// we are index or folder, so if the key doesn't have a trailing slash // we are index or folder, so if the key doesn't have a trailing slash
// add one to force a fake findBySlug // add one to force a fake findBySlug

View File

@ -1,3 +0,0 @@
import Route from './create';
export default class RootCreateRoute extends Route {}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -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');
}

View File

@ -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']],
},
};
}

View File

@ -1,5 +0,0 @@
import Route from 'consul-ui/routing/route';
export default class CreateRoute extends Route {
templateName = 'dc/services/show/intentions/edit';
}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -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,
},
};
}

View File

@ -13,36 +13,40 @@ export default class BaseRoute extends Route {
_setRouteName() { _setRouteName() {
super._setRouteName(...arguments); super._setRouteName(...arguments);
const routeName = this.routeName
.split('.') const template = get(routes, `${this.routeName}._options.template`);
.filter(item => item !== 'index') if (typeof template !== 'undefined') {
.join('.');
const template = get(routes, `${routeName}._options.template`);
if (template) {
this.templateName = template; this.templateName = template;
} }
const queryParams = get(routes, `${routeName}._options.queryParams`);
if ( const queryParams = get(routes, `${this.routeName}._options.queryParams`);
queryParams && if (typeof queryParams !== 'undefined') {
['dc.partitions.index', 'dc.nspaces.index', 'oauth-provider-debug'].includes(this.routeName)
) {
this.queryParams = queryParams; this.queryParams = queryParams;
} }
} }
redirect(model, transition) { redirect(model, transition) {
// remove any references to index as it is the same as the root routeName let to = get(routes, `${this.routeName}._options.redirect`);
const routeName = this.routeName
.split('.')
.filter(item => item !== 'index')
.join('.');
const to = get(routes, `${routeName}._options.redirect`);
if (typeof to !== 'undefined') { 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? // TODO: Does this need to return?
// Almost remember things getting strange if you returned from here // 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 // which is why I didn't do it originally so be sure to look properly if
// you feel like adding a return // you feel like adding a return
this.replaceWith(`${routeName}${to}`, model); this.replaceWith(`${to}`, model);
} }
} }

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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);
});
});