claire bontempo 49b46ead82
UI: Fix enabling replication capabilities bug (#28371)
* add capabilities service to replication engine

* fix capabilities paths in route file

* pass updated capabilities using getters

* add changelog

* fix logic so default is based on undefined capabilities (not no mode)
2024-09-12 08:51:11 -05:00

41 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
/**
* @module PageModeIndex
*
* @example
* <Page::ModeIndex
* @cluster={{this.model}}
* @onEnableSuccess={{this.onEnableSuccess}}
* @replicationDisabled={{this.replicationForMode.replicationDisabled}
* @replicationMode={{this.replicationMode}}
* />
*
* @param {model} cluster - cluster route model
* @param {function} onEnableSuccess - callback after enabling is successful, handles transition if enabled from the top-level index route
* @param {boolean} replicationDisabled - whether or not replication is enabled
* @param {string} replicationMode - should be "dr" or "performance"
*/
export default class PageModeIndex extends Component {
canEnable = (type) => {
const { cluster, replicationMode } = this.args;
let perm;
if (replicationMode === 'dr') {
// returns canEnablePrimaryDr or canEnableSecondaryDr
perm = `canEnable${type}Dr`;
}
if (replicationMode === 'performance') {
// returns canEnablePrimaryPerformance or canEnableSecondaryPerformance
perm = `canEnable${type}Performance`;
}
// if there's a problem checking capabilities, default to true
// since the backend can gate as a fallback
return cluster[perm] ?? true;
};
}