claire bontempo 7774261c15
UI: Ember upgrade: Handle deprecation router service from host (#28603)
* use alias for router injection

* update @router declarations in engine files

* fix remaining pki router imports

* dynamically set router based on owner

* address replication routers

* update markdown docs

* use non-deprecated import for getOwner

* revert out of scope changes

* add transition-to test
2024-10-08 09:01:46 -07:00

40 lines
1.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { service } from '@ember/service';
import { hash } from 'rsvp';
import { setProperties } from '@ember/object';
import Route from '@ember/routing/route';
const SUPPORTED_REPLICATION_MODES = ['dr', 'performance'];
export default Route.extend({
replicationMode: service(),
router: service('app-router'),
store: service(),
beforeModel() {
const replicationMode = this.paramsFor(this.routeName).replication_mode;
if (!SUPPORTED_REPLICATION_MODES.includes(replicationMode)) {
this.router.transitionTo('vault.cluster.replication.index');
}
},
model() {
const replicationMode = this.paramsFor(this.routeName).replication_mode;
this.replicationMode.setMode(replicationMode);
return this.modelFor('application');
},
afterModel(model) {
return hash({
// set new property on model to compare if the drMode changes when you are demoting the cluster
drModeInit: model.drMode,
}).then(({ drModeInit }) => {
setProperties(model, {
drModeInit,
});
return model;
});
},
});