ui: Move peers to a subapplication (#13725)

This commit is contained in:
John Cowen 2022-07-14 11:22:45 +01:00 committed by GitHub
parent 610038ce67
commit f6edc37d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 153 additions and 70 deletions

View File

@ -34,7 +34,7 @@ references:
ember: &EMBER_IMAGE docker.mirror.hashicorp.services/circleci/node:14-browsers
ubuntu: &UBUNTU_CI_IMAGE ubuntu-2004:202201-02
cache:
yarn: &YARN_CACHE_KEY consul-ui-v8-{{ checksum "ui/yarn.lock" }}
yarn: &YARN_CACHE_KEY consul-ui-v9-{{ checksum "ui/yarn.lock" }}
steps:
install-gotestsum: &install-gotestsum

View File

@ -11,7 +11,7 @@
"scripts": {
"doc:toc": "doctoc README.md",
"compliance": "npm-run-all compliance:*",
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-hcp@0.1.0'"
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-hcp@0.1.0;consul-peerings@0.1.0'"
},
"devDependencies": {

View File

@ -9,11 +9,15 @@ Searchbar tailored for searching Peers. Follows our more generic
@onsearch={{fn (mut this.search) value="target.value"}}
@sort={{hash
value='Name:asc'
value='State:asc'
change=(noop)
}}
@filter={{hash
state=(hash
value=(array "PENDING")
change=(noop)
)
searchproperty=(hash
value=(array)
change=(noop)

View File

@ -81,7 +81,7 @@ as |key value|}}
{{#each
(get
(require '/models/peer'
path='schema'
export='schema'
from='/components/consul/peer/search-bar'
)
'State.allowedValues'

View File

@ -0,0 +1,36 @@
# Consul::Peer::Selector
A conditional, autoloading, menu component specifically for navigating to peers.
Please note:
- Currently at least, you must add this inside of a `<ul>` element.
- For the moment, make sure you have enabled peers using developer debug
cookies.
```hbs preview-template
<ul>
<Consul::Peer::Selector
@dc={{hash
Name='dc-1'
}}
@nspace='default'
@partition='default'
/>
</ul>
```
## Arguments
| Argument/Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `dc` | `object` | | The current datacenter |
| `nspace` | `string` | | The name of the current namespace |
| `partition` | `string` | | The name of the current partition |
## See
- [Template Source Code](./index.hbs)
---

View File

@ -0,0 +1,20 @@
<li
class="peers-separator"
role="separator"
...attributes
>
Organization
</li>
<li
data-test-main-nav-peers
class={{if (is-href 'dc.peers' @dc.Name) 'is-active'}}
>
<a
href={{href-to 'dc.peers' @dc.Name
params=(hash peer=undefined)
}}
>
Peers
</a>
</li>

View File

@ -0,0 +1,5 @@
{
"name": "consul-peerings",
"version": "0.1.0",
"private": true
}

View File

@ -0,0 +1,40 @@
(routes => routes({
dc: {
peers: {
_options: {
path: '/peers'
},
index: {
_options: {
path: '/',
queryParams: {
sortBy: 'sort',
state: 'state',
searchproperty: {
as: 'searchproperty',
empty: [['Name']],
},
search: {
as: 'filter',
replace: true,
},
},
},
},
edit: {
_options: {
path: '/:name'
},
addresses: {
_options: {
path: '/addresses',
},
},
},
},
},
}))(
(json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => {
data[`routes`] = JSON.stringify(json);
}
);

View File

@ -0,0 +1,9 @@
(services => services({
"component:consul/peer/selector": {
"class": "consul-ui/components/consul/peer/selector"
}
}))(
(json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => {
data[`services`] = JSON.stringify(json);
}
);

View File

@ -112,6 +112,12 @@ module.exports = {
urlSchema: 'auto',
urlPrefix: 'docs/consul-lock-sessions',
},
{
root: `${path.dirname(require.resolve('consul-peerings/package.json'))}/app/components`,
pattern: '**/README.mdx',
urlSchema: 'auto',
urlPrefix: 'docs/consul-peerings',
},
{
root: `${path.dirname(require.resolve('consul-partitions/package.json'))}/app/components`,
pattern: '**/README.mdx',

View File

@ -18,6 +18,6 @@ export default class PeerAbility extends BaseAbility {
}
get canUse() {
return this.env.var('CONSUL_PEERING_ENABLED');
return this.env.var('CONSUL_PEERINGS_ENABLED');
}
}

View File

@ -146,14 +146,11 @@
@partition={{@partition}}
@nspace={{@nspace}}
/>
{{#if (can "use peers")}}
<li role="separator">
Organization
</li>
<li data-test-main-nav-peers class={{if (is-href 'dc.peers' @dc.Name) 'is-active' }}>
<a href={{href-to 'dc.peers' @dc.Name params=(hash peer=undefined)}}>Peers</a>
</li>
{{/if}}
<Consul::Peer::Selector
@dc={{@dc}}
@partition={{@partition}}
@nspace={{@nspace}}
/>
</ul>
</:main-nav>

View File

@ -1,12 +0,0 @@
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
export default class PeersRoute extends Route {
@service abilities;
beforeModel() {
if (!this.abilities.can('use peers')) {
this.transitionTo('dc.services.index');
}
}
}

View File

@ -1,16 +0,0 @@
import Route from 'consul-ui/routing/route';
export default class PeersRoute extends Route {
queryParams = {
sortBy: 'sort',
state: 'state',
searchproperty: {
as: 'searchproperty',
empty: [['Name']],
},
search: {
as: 'filter',
replace: true,
},
};
}

View File

@ -124,7 +124,7 @@ export default function(config = {}, win = window, doc = document) {
return typeof operatorConfig.PartitionsEnabled === 'undefined'
? false
: operatorConfig.PartitionsEnabled;
case 'CONSUL_PEERING_ENABLED':
case 'CONSUL_PEERINGS_ENABLED':
return typeof operatorConfig.PeeringEnabled === 'undefined'
? false
: operatorConfig.PeeringEnabled;
@ -213,8 +213,8 @@ export default function(config = {}, win = window, doc = document) {
case 'CONSUL_METRICS_PROXY_ENABLE':
prev['CONSUL_METRICS_PROXY_ENABLED'] = !!JSON.parse(String(value).toLowerCase());
break;
case 'CONSUL_PEERING_ENABLE':
prev['CONSUL_PEERING_ENABLED'] = !!JSON.parse(String(value).toLowerCase());
case 'CONSUL_PEERINGS_ENABLE':
prev['CONSUL_PEERINGS_ENABLED'] = !!JSON.parse(String(value).toLowerCase());
break;
case 'CONSUL_UI_CONFIG':
prev['CONSUL_UI_CONFIG'] = JSON.parse(value);
@ -248,7 +248,7 @@ export default function(config = {}, win = window, doc = document) {
case 'CONSUL_DATACENTER_PRIMARY':
case 'CONSUL_ACLS_ENABLED':
case 'CONSUL_NSPACES_ENABLED':
case 'CONSUL_PEERING_ENABLED':
case 'CONSUL_PEERINGS_ENABLED':
case 'CONSUL_SSO_ENABLED':
case 'CONSUL_PARTITIONS_ENABLED':
case 'CONSUL_METRICS_PROVIDER':

View File

@ -82,7 +82,7 @@ module.exports = function(environment, $ = process.env) {
ACLsEnabled: false,
NamespacesEnabled: false,
SSOEnabled: false,
PeeringEnabled: env('CONSUL_PEERING_ENABLED', false),
PeeringEnabled: false,
PartitionsEnabled: false,
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
@ -107,7 +107,7 @@ module.exports = function(environment, $ = process.env) {
NamespacesEnabled: env('CONSUL_NSPACES_ENABLED', false),
SSOEnabled: env('CONSUL_SSO_ENABLED', false),
// in testing peering feature is on by default
PeeringEnabled: env('CONSUL_PEERING_ENABLED', true),
PeeringEnabled: env('CONSUL_PEERINGS_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', false),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
@ -158,6 +158,7 @@ module.exports = function(environment, $ = process.env) {
ACLsEnabled: env('CONSUL_ACLS_ENABLED', true),
NamespacesEnabled: env('CONSUL_NSPACES_ENABLED', true),
SSOEnabled: env('CONSUL_SSO_ENABLED', true),
PeeringEnabled: env('CONSUL_PEERINGS_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', true),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),

View File

@ -12,7 +12,7 @@ Below is a list of the most commonly used functions as bookmarklets followed by
| [Enable ACLs](javascript:Scenario('CONSUL_ACLS_ENABLE=1')) | Enable ACLs |
| [Enable TProxy](javascript:Scenario('CONSUL_TPROXY_ENABLE=1')) | Enable TProxy |
| [Enable Nspaces](javascript:Scenario('CONSUL_NSPACES_ENABLE=1')) | Enable Namespace Support |
| [Enable Peers](javascript:Scenario('CONSUL_PEERING_ENABLE=1')) | Enable Peers Support |
| [Enable Peers](javascript:Scenario('CONSUL_PEERINGS_ENABLE=1')) | Enable Peering Support |
| [Enable Partitions](javascript:Scenario('CONSUL_PARTITIONS_ENABLE=1')) | Enable Admin Partition Support |
| [Enable SSO](javascript:Scenario('CONSUL_SSO_ENABLE=1')) | Enable SSO Support |
| [Enable Metrics](javascript:Scenario('CONSUL_METRICS_PROXY_ENABLE=1;CONSUL_METRICS_PROVIDER=prometheus')) | Enable all configuration required for viewing the full Metrics Visualization |

View File

@ -30,6 +30,7 @@ module.exports = function(defaults, $ = process.env) {
'consul-ui',
'consul-acls',
'consul-lock-sessions',
'consul-peerings',
'consul-partitions',
'consul-nspaces',
'consul-hcp'

View File

@ -59,6 +59,10 @@ ${
{{if .ACLsEnabled}}
<script src="${rootURL}assets/consul-acls/routes.js"></script>
{{end}}
{{if .PeeringEnabled}}
<script src="${rootURL}assets/consul-peerings/services.js"></script>
<script src="${rootURL}assets/consul-peerings/routes.js"></script>
{{end}}
{{if .PartitionsEnabled}}
<script src="${rootURL}assets/consul-partitions/services.js"></script>
<script src="${rootURL}assets/consul-partitions/routes.js"></script>
@ -87,6 +91,7 @@ ${
key => document.cookie.split('; ').find(item => item.startsWith(\`\${key}=\`)),
{
'CONSUL_ACLS_ENABLE': 'consul-acls',
'CONSUL_PEERINGS_ENABLE': 'consul-peerings',
'CONSUL_PARTITIONS_ENABLE': 'consul-partitions',
'CONSUL_NSPACES_ENABLE': 'consul-nspaces',
'CONSUL_HCP_ENABLE': 'consul-hcp'

View File

@ -20,8 +20,8 @@ test(
ACLsEnabled: true,
NamespacesEnabled: false,
SSOEnabled: false,
PeeringEnabled: true,
PartitionsEnabled: false,
PeeringEnabled: true,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
@ -36,8 +36,8 @@ test(
ACLsEnabled: true,
NamespacesEnabled: true,
SSOEnabled: false,
PeeringEnabled: true,
PartitionsEnabled: false,
PeeringEnabled: true,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
@ -52,8 +52,8 @@ test(
ACLsEnabled: true,
NamespacesEnabled: false,
SSOEnabled: true,
PeeringEnabled: true,
PartitionsEnabled: false,
PeeringEnabled: true,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
@ -66,6 +66,7 @@ test(
NamespacesEnabled: true,
SSOEnabled: true,
PartitionsEnabled: true,
PeeringEnabled: true,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}

View File

@ -82,6 +82,7 @@
"consul-hcp": "*",
"consul-lock-sessions": "*",
"consul-nspaces": "*",
"consul-peerings": "*",
"consul-partitions": "*",
"css.escape": "^1.5.1",
"d3-array": "^2.8.0",

View File

@ -34,24 +34,6 @@
},
},
},
peers: {
_options: { path: '/peers' },
index: {
_options: {
path: '/',
},
},
edit: {
_options: {
path: '/:name'
},
addresses: {
_options: {
path: '/addresses',
},
},
},
},
services: {
_options: { path: '/services' },
index: {

View File

@ -15,6 +15,9 @@
'component:consul/partition/selector': {
class: '@glimmer/component',
},
'component:consul/peer/selector': {
class: '@glimmer/component',
},
}))(
(
json,