From 0f7311888bb211a38f9d134dc821b4fffe971511 Mon Sep 17 00:00:00 2001 From: SanketD92 Date: Thu, 12 Aug 2021 12:24:25 -0400 Subject: [PATCH 1/7] feat: warn users to terminate non-appstream envs --- .../env-sc-connection-url-plugin.test.js | 6 ++--- .../models/environments-sc/ScEnvironment.js | 1 + .../src/parts/accounts/AccountCard.js | 11 +++----- .../environments-sc/ScEnvironmentCard.js | 25 ++++++++++++++++++- .../environments-sc/ScEnvironmentsList.js | 7 +++--- .../parts/ScEnvironmentButtons.js | 6 ++++- .../src/templates/onboard-account.cfn.yml | 10 +++----- .../environment-sc-connection-service.js | 7 ++++-- .../service-catalog/environment-sc-service.js | 15 ++++++----- .../backend/config/infra/cloudformation.yml | 16 +++++------- 10 files changed, 63 insertions(+), 41 deletions(-) diff --git a/addons/addon-base-raas-appstream/packages/base-raas-appstream-services/lib/plugins/__tests__/env-sc-connection-url-plugin.test.js b/addons/addon-base-raas-appstream/packages/base-raas-appstream-services/lib/plugins/__tests__/env-sc-connection-url-plugin.test.js index 592aaa0009..a1e479b28f 100644 --- a/addons/addon-base-raas-appstream/packages/base-raas-appstream-services/lib/plugins/__tests__/env-sc-connection-url-plugin.test.js +++ b/addons/addon-base-raas-appstream/packages/base-raas-appstream-services/lib/plugins/__tests__/env-sc-connection-url-plugin.test.js @@ -25,12 +25,12 @@ const PluginRegistryService = require('@aws-ee/base-services/lib/plugin-registry jest.mock('@aws-ee/base-services/lib/settings/env-settings-service'); const SettingsServiceMock = require('@aws-ee/base-services/lib/settings/env-settings-service'); -jest.mock('../../appstream/appstream-sc-service'); -const AppStreamScService = require('../../appstream/appstream-sc-service'); - jest.mock('@aws-ee/base-raas-services/lib/environment/service-catalog/environment-sc-connection-service'); const EnvironmentScConnectionServiceMock = require('@aws-ee/base-raas-services/lib/environment/service-catalog/environment-sc-connection-service'); +jest.mock('../../appstream/appstream-sc-service'); +const AppStreamScService = require('../../appstream/appstream-sc-service'); + const plugin = require('../env-sc-connection-url-plugin'); // Tested Functions: create, update, delete diff --git a/addons/addon-base-raas-ui/packages/base-raas-ui/src/models/environments-sc/ScEnvironment.js b/addons/addon-base-raas-ui/packages/base-raas-ui/src/models/environments-sc/ScEnvironment.js index 71b174111a..4c0130dde8 100644 --- a/addons/addon-base-raas-ui/packages/base-raas-ui/src/models/environments-sc/ScEnvironment.js +++ b/addons/addon-base-raas-ui/packages/base-raas-ui/src/models/environments-sc/ScEnvironment.js @@ -167,6 +167,7 @@ const ScEnvironment = types studyIds: types.frozen([]), cidr: types.frozen([]), outputs: types.frozen([]), + isAppStreamConfigured: types.optional(types.boolean, false), }) .actions(self => ({ setScEnvironment(rawEnvironment) { diff --git a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/accounts/AccountCard.js b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/accounts/AccountCard.js index 0ec912bb94..42a08cf23d 100644 --- a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/accounts/AccountCard.js +++ b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/accounts/AccountCard.js @@ -19,10 +19,9 @@ import { observer, inject } from 'mobx-react'; import { withRouter } from 'react-router-dom'; import { Header, Segment, Accordion, Icon, Label, Table, Button } from 'semantic-ui-react'; import c from 'classnames'; - import { createLink } from '@aws-ee/base-ui/dist/helpers/routing'; - import { displayWarning } from '@aws-ee/base-ui/dist/helpers/notification'; +import { isAppStreamEnabled } from '../../helpers/settings'; const { getAccountIdsOfActiveEnvironments } = require('./AccountUtils'); @@ -54,12 +53,8 @@ class AccountCard extends React.Component { return this.props.account; } - get isAppStreamEnabled() { - return process.env.REACT_APP_IS_APP_STREAM_ENABLED === 'true'; - } - get appStreamStatusMismatch() { - return this.isAppStreamEnabled && !this.account.isAppStreamConfigured; + return isAppStreamEnabled && !this.account.isAppStreamConfigured; } get awsAccountsStore() { @@ -181,7 +176,7 @@ class AccountCard extends React.Component { : `Service Workbench is waiting for the CFN stack to complete. Please wait a few minutes for provisioning to complete. If you did not create a CFN stack for this account, click - "Re-Onboard Account" to return to the account onboarding page.`} + "Re-Onboard Account" to return to the account onboarding page.`} )} diff --git a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentCard.js b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentCard.js index c42d23f5bf..2b41dd7023 100644 --- a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentCard.js +++ b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentCard.js @@ -7,6 +7,7 @@ import { Header, Label, Popup, Icon, Divider, Message, Table, Grid, Segment } fr import TimeAgo from 'react-timeago'; import { niceNumber } from '@aws-ee/base-ui/dist/helpers/utils'; +import { isAppStreamEnabled } from '../../helpers/settings'; import By from '../helpers/By'; import ScEnvironmentButtons from './parts/ScEnvironmentButtons'; import ScEnvironmentCost from './parts/ScEnvironmentCost'; @@ -14,11 +15,16 @@ import ScEnvironmentCost from './parts/ScEnvironmentCost'; // expected props // - scEnvironment (via prop) // - envTypesStore (via injection) +// - indexesStore (via injection) class ScEnvironmentCard extends React.Component { get envTypesStore() { return this.props.envTypesStore; } + get indexesStore() { + return this.props.indexesStore; + } + get environment() { return this.props.scEnvironment; } @@ -34,12 +40,15 @@ class ScEnvironmentCard extends React.Component { render() { const env = this.environment; const state = env.state; + const indexesStore = this.indexesStore; + const indexes = indexesStore.getIndexes(); return ( <> {this.renderStatus(state)} {this.renderTitle(env)} {this.renderError(env)} + {this.renderWarning(env, indexes)} {this.renderButtons(env)} @@ -120,6 +129,20 @@ class ScEnvironmentCard extends React.Component { ); } + renderWarning(env) { + if (isAppStreamEnabled && !env.isAppStreamConfigured && env.state.canTerminate) { + return ( + + ); + } + + return null; + } + renderError(env) { if (_.isEmpty(env.error)) return null; @@ -138,4 +161,4 @@ decorate(ScEnvironmentCard, { envType: computed, }); -export default inject('envTypesStore')(withRouter(observer(ScEnvironmentCard))); +export default inject('envTypesStore', 'indexesStore')(withRouter(observer(ScEnvironmentCard))); diff --git a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentsList.js b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentsList.js index 4f445a7ab0..8c737a0189 100644 --- a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentsList.js +++ b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/ScEnvironmentsList.js @@ -112,7 +112,7 @@ class ScEnvironmentsList extends React.Component { } else if (isStoreEmpty(store)) { content = this.renderEmpty(); } else if (isStoreNotEmpty(store)) { - content = this.renderMain(appStreamProjectIds); + content = this.renderMain(); } else { content = null; } @@ -143,11 +143,10 @@ class ScEnvironmentsList extends React.Component { ); } - renderMain(appStreamProjectIds) { + renderMain() { const store = this.envsStore; const selectedFilter = this.selectedFilter; - let list = store.filtered(selectedFilter); - list = this.isAppStreamEnabled ? _.filter(list, env => _.includes(appStreamProjectIds, env.projectId)) : list; + const list = store.filtered(selectedFilter); const isEmpty = _.isEmpty(list); return ( diff --git a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/parts/ScEnvironmentButtons.js b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/parts/ScEnvironmentButtons.js index 5452a3f428..05cc1b0587 100644 --- a/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/parts/ScEnvironmentButtons.js +++ b/addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/parts/ScEnvironmentButtons.js @@ -194,7 +194,11 @@ class ScEnvironmentButtons extends React.Component { )} - {canConnect && ( + {/* Only let users connect to the environment if either of these conditions is true: + 1. AppStream is not enabled and environment can be connected to + 2. AppStream is enabled, environment is linked to an AppStream-configured account, and environment can be connected to + */} + {canConnect && !(isAppStreamEnabled && !env.isAppStreamConfigured) && (