Files
threshold-ui/ui/admin/app/routes/scopes/scope/targets/target.js
T
2024-05-31 11:29:24 -07:00

40 lines
917 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ScopesScopeTargetsTargetRoute extends Route {
// =services
@service store;
@service can;
@service router;
// =methods
/**
* Load a target.
* @param {object} params
* @param {string} params.target_id
* @return {Promise{TargetModel}}
*/
async model({ target_id }) {
return this.store.findRecord('target', target_id, { reload: true });
}
/**
* Redirects to route with correct scope id if incorrect.
* @param {TargetModel} target
* @param {object} transition
*/
redirect(target, transition) {
const scope = this.modelFor('scopes.scope');
if (target.scopeID !== scope.id) {
this.router.replaceWith(transition.to.name, target.scopeID, target.id);
}
}
}