Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/23004.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Removed ember-route-action-helper and migrated all {{route-action}} usages to explicit route/controller logic.
```
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</BlockSlot>
</ModalDialog>
{{else}}
<DeleteConfirmation @message={{message}} @execute={{queue execute (fn @delete @item)}} @cancel={{cancel}} />
<DeleteConfirmation @message={{message}} @execute={{queue execute (fn @onDelete @item)}} @cancel={{cancel}} />
{{/if}}
</BlockSlot>
</ConfirmationDialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</BlockSlot>
</ModalDialog>
{{else}}
<DeleteConfirmation @message={{message}} @execute={{queue execute (fn @delete @item)}} @cancel={{cancel}} />
<DeleteConfirmation @message={{message}} @execute={{queue execute (fn @onDelete @item)}} @cancel={{cancel}} />
{{/if}}
</BlockSlot>
</ConfirmationDialog>
Expand Down
14 changes: 14 additions & 0 deletions ui/packages/consul-ui/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export default class ApplicationController extends Controller {
// as the nspace and dc variables aren't available directly on the Route
// look to see if we can move this up there so we can empty the Controller
// out again

@action
gotoDefaultDcServices(dcName) {
// Preserve prior semantics (was route.replaceWith with a hash)
// If your router expects a positional segment instead, change to: this.router.replaceWith('dc.services.index', dcName);
this.router.replaceWith('dc.services.index', { dc: dcName });
}

@action
onClientChanged(e) {
const route = getOwner(this).lookup('route:application');
route.onClientChanged(e);
}

@action
reauthorize(e) {
// TODO: For the moment e isn't a real event
Expand Down
21 changes: 20 additions & 1 deletion ui/packages/consul-ui/app/controllers/dc/acls/policies/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@ export default class EditController extends Controller {
);
}

// Forwarders replacing route-action usage
@action
delete(item) {
onCreate(item, event) {
event?.preventDefault();
this.target.send('create', item, event);
}

@action
onUpdate(item, event) {
event?.preventDefault();
this.target.send('update', item, event);
}

@action
onCancel(item, event) {
event?.preventDefault();
this.target.send('cancel', item, event);
}

@action
onDelete(item) {
this.target.send('delete', item);
}
}
14 changes: 14 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/acls/policies/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class DcAclsPoliciesIndexController extends Controller {
@action
delete(item) {
// delegate to the route (WithBlockingActions mixin) which has the delete action
this.target.send('delete', item);
}
}
21 changes: 20 additions & 1 deletion ui/packages/consul-ui/app/controllers/dc/acls/roles/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@ export default class EditController extends Controller {
);
}

// Forwarders replacing route-action helper usage
@action
delete(item) {
onCreate(item, event) {
event?.preventDefault();
this.target.send('create', item, event);
}

@action
onUpdate(item, event) {
event?.preventDefault();
this.target.send('update', item, event);
}

@action
onCancel(item, event) {
event?.preventDefault();
this.target.send('cancel', item, event);
}

@action
onDelete(item) {
this.target.send('delete', item);
}
}
13 changes: 13 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/acls/roles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class DcAclsRolesIndexController extends Controller {
@action
delete(item) {
this.target.send('delete', item);
}
}
20 changes: 19 additions & 1 deletion ui/packages/consul-ui/app/controllers/dc/acls/tokens/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,25 @@ export default class EditController extends Controller {
}

@action
delete(item) {
onCreate(item, event) {
event?.preventDefault();
this.target.send('create', item, event);
}

@action
onUpdate(item, event) {
event?.preventDefault();
this.target.send('update', item, event);
}

@action
onCancel(item, event) {
event?.preventDefault();
this.target.send('cancel', item, event);
}

@action
onDelete(item) {
this.target.send('delete', item);
}
}
25 changes: 25 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/acls/tokens/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class DcAclsTokensIndexController extends Controller {
@action
onUse(item) {
this.target.send('use', item);
}
@action
onDelete(item) {
this.target.send('delete', item);
}
@action
onLogout(item) {
this.target.send('logout', item);
}
@action
onClone(item) {
this.target.send('clone', item);
}
}
16 changes: 16 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/intentions/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class DcIntentionsCreateController extends Controller {
@service router;

@action
goToIndex(dc) {
this.router.transitionTo('dc.intentions.index', dc);
}
}
16 changes: 16 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/intentions/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class DcIntentionsEditController extends Controller {
@service router;

@action
goToIndex(dc) {
this.router.transitionTo('dc.intentions.index', dc);
}
}
21 changes: 21 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/nodes/show/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class DcNodesShowIndexController extends Controller {
@service router;

@action
goServices() {
this.router.replaceWith('dc.nodes.show.services');
}

@action
goHealthChecks() {
this.router.replaceWith('dc.nodes.show.healthchecks');
}
}
19 changes: 19 additions & 0 deletions ui/packages/consul-ui/app/controllers/dc/services/show/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class DcServicesShowIndexController extends Controller {
@service router;

@action
forward(tabs = {}) {
if (tabs.topology) return this.router.replaceWith('dc.services.show.topology');
if (tabs.upstreams) return this.router.replaceWith('dc.services.show.upstreams');
if (tabs.services) return this.router.replaceWith('dc.services.show.services');
return this.router.replaceWith('dc.services.show.instances');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { getOwner } from '@ember/application';

export default class TopologyController extends Controller {
@action
createIntention(source, destination) {
const route = getOwner(this).lookup('route:dc.services.show.topology');
return route.createIntention(source, destination);
}
}
14 changes: 14 additions & 0 deletions ui/packages/consul-ui/app/routes/dc/acls/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';

export default class DcAclsIndexRoute extends Route {
@service router;

beforeModel() {
this.router.replaceWith('dc.acls.tokens');
}
}
14 changes: 14 additions & 0 deletions ui/packages/consul-ui/app/routes/dc/nodes/show/rtt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from 'consul-ui/routing/route';

export default class DcNodesShowRttRoute extends Route {
redirect(model) {
const distances = model?.tomography?.distances;
if (Array.isArray(distances) && distances.length == 0) {
this.replaceWith('dc.nodes.show');
}
}
}
16 changes: 16 additions & 0 deletions ui/packages/consul-ui/app/routes/dc/show/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';

export default class DcShowIndexRoute extends Route {
// Use the abilities service (ember-can) backing the {{can}} helper
@service abilities;

afterModel() {
const canAccess = this.abilities.can('access overview');
this.replaceWith(canAccess ? 'dc.show.serverstatus' : 'dc.services.index');
}
}
3 changes: 3 additions & 0 deletions ui/packages/consul-ui/app/services/repository/coordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class CoordinateService extends RepositoryService {
let results = {};
if (coordinates.length > 1) {
results = tomography(params.id, coordinates);
} else {
// Ensure consistent shape
results = { distances: [], min: 0, median: 0, max: 0 };
}
results.meta = coordinates.meta;
return results;
Expand Down
32 changes: 15 additions & 17 deletions ui/packages/consul-ui/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
{{document-attrs class='has-partitions'}}
{{/if}}

{{! Listen out for blocking query/client setting changes }}
<DataSource
@src={{uri 'settings://consul:client'}}
@onchange={{route-action 'onClientChanged'}}
/>
{{! Listen out for blocking query/client setting changes }}
<DataSource
@src={{uri 'settings://consul:client'}}
@onchange={{this.onClientChanged}}
/>

{{! Tell CSS about our theme }}
<DataSource @src={{uri 'settings://consul:theme'}} as |source|>
Expand Down Expand Up @@ -60,18 +60,16 @@
{{! as we don't know the dc, any inital permission based }}
{{! redirects are in the dc.show route}}

{{! 2022-04-15: Temporarily reverting the services page to the default }}
{{did-insert
(route-action 'replaceWith' 'dc.services.index' (hash dc=(env 'CONSUL_DATACENTER_LOCAL')))
}}
{{else}}
{{! If we are notfound, guess the params we need }}
{{#if (eq route.currentName 'notfound')}}
<DataSource
@src={{uri '/*/*/*/notfound/${path}' (hash path=route.params.notfound)}}
@onchange={{action (mut this.notfound) value='data'}}
/>
{{/if}}
{{! 2022-04-15: Temporarily reverting the services page to the default }}
{{did-insert (fn this.gotoDefaultDcServices (env 'CONSUL_DATACENTER_LOCAL'))}}
{{else}}
{{! If we are notfound, guess the params we need }}
{{#if (eq route.currentName 'notfound')}}
<DataSource
@src={{uri '/*/*/*/notfound/${path}' (hash path=route.params.notfound)}}
@onchange={{action (mut this.notfound) value='data'}}
/>
{{/if}}

{{! Make sure we guess and default to the right params when not found }}
{{#let
Expand Down
1 change: 0 additions & 1 deletion ui/packages/consul-ui/app/templates/dc/acls/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
<Route
@name={{this.routeName}}
as |route|>
{{did-insert (route-action 'replaceWith' 'dc.acls.tokens')}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to keep did-insert modifer? or are you handling it somewhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, It is now handled directly in the route file here

</Route>
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ as |dc partition nspace id item create|}}
@dc={{dc}}
@id={{id}}
@items={{this.items}}
@onCreate={{route-action 'create' item}}
@onUpdate={{route-action 'update' item}}
@onCancel={{route-action 'cancel' item}}
@onDelete={{route-action 'delete'}}
@onCreate={{fn this.onCreate item}}
@onUpdate={{fn this.onUpdate item}}
@onCancel={{fn this.onCancel item}}
@onDelete={{fn this.onDelete item}}
@onItemsChange={{action (mut this.items) value="data"}}
/>
{{/if}}
Expand Down
Loading
Loading