Skip to content

Commit

Permalink
[Alerting] only show trial upgrade when running with basic license
Browse files Browse the repository at this point in the history
resolves #64245

Prior to this PR, the "Upgrade your license" banner in the connectors list
was displayed for gold licenses because the Service Now action requires
platinum, and the check only looked for any actions disabled by license.

Rather than display a different message for gold users, this PR changes the
banner display logic to check for any actions disabled by license that
also have a minimum required license of gold.  That means gold+ users
won't see the message, even for actions with a minimum required license of
platinum+.  Another perk of the gold license!

This will continue to display the banner for basic users, but will no longer
display it for gold users.  It also continues to not display it for trial,
platinum and enterprise users.
  • Loading branch information
pmuellr committed Apr 30, 2020
1 parent d6f0c78 commit 9fa5520
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { checkActionTypeEnabled } from '../../lib/check_action_type_enabled';
interface Props {
onActionTypeChange: (actionType: ActionType) => void;
actionTypes?: ActionType[];
setHasActionsDisabledByLicense?: (value: boolean) => void;
setHasActionsUpgradeableByTrial?: (value: boolean) => void;
}

export const ActionTypeMenu = ({
onActionTypeChange,
actionTypes,
setHasActionsDisabledByLicense,
setHasActionsUpgradeableByTrial,
}: Props) => {
const { http, toastNotifications, actionTypeRegistry } = useActionsConnectorsContext();
const [actionTypesIndex, setActionTypesIndex] = useState<ActionTypeIndex | undefined>(undefined);
Expand All @@ -36,11 +36,15 @@ export const ActionTypeMenu = ({
index[actionTypeItem.id] = actionTypeItem;
}
setActionTypesIndex(index);
if (setHasActionsDisabledByLicense) {
const hasActionsDisabledByLicense = availableActionTypes.some(
action => !index[action.id].enabledInLicense
// determine if there are actions disabled by license that that
// would be enabled by upgrading to trial
if (setHasActionsUpgradeableByTrial) {
const hasActionsUpgradeableByTrial = availableActionTypes.some(
action =>
!index[action.id].enabledInLicense &&
index[action.id].minimumLicenseRequired === 'gold'
);
setHasActionsDisabledByLicense(hasActionsDisabledByLicense);
setHasActionsUpgradeableByTrial(hasActionsUpgradeableByTrial);
}
} catch (e) {
if (toastNotifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('connector_add_flyout', () => {
expect(wrapper.find(`[data-test-subj="${actionType.id}-card"]`).exists()).toBeTruthy();
});

it('renders banner with subscription links when features are disbaled due to licensing ', () => {
it('renders banner with subscription links when gold features are disabled due to licensing ', () => {
const actionType = createActionType();
const disabledActionType = createActionType();

Expand Down Expand Up @@ -136,6 +136,100 @@ describe('connector_add_flyout', () => {
`"https://www.elastic.co/subscriptions"`
);
});

it('does not render banner with subscription links when only platinum features are disabled due to licensing ', () => {
const actionType = createActionType();
const disabledActionType = createActionType();

actionTypeRegistry.get.mockReturnValueOnce(actionType);
actionTypeRegistry.has.mockReturnValue(true);

const wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
toastNotifications: deps!.toastNotifications,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
actionTypes={[
{
id: actionType.id,
enabled: true,
name: 'Test',
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
},
{
id: disabledActionType.id,
enabled: true,
name: 'Test',
enabledInConfig: true,
enabledInLicense: false,
minimumLicenseRequired: 'platinum',
},
]}
/>
</ActionsConnectorsContextProvider>
);
const callout = wrapper.find('UpgradeYourLicenseCallOut');
expect(callout).toHaveLength(0);
});

it('does not render banner with subscription links when only enterprise features are disabled due to licensing ', () => {
const actionType = createActionType();
const disabledActionType = createActionType();

actionTypeRegistry.get.mockReturnValueOnce(actionType);
actionTypeRegistry.has.mockReturnValue(true);

const wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
toastNotifications: deps!.toastNotifications,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
actionTypes={[
{
id: actionType.id,
enabled: true,
name: 'Test',
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
},
{
id: disabledActionType.id,
enabled: true,
name: 'Test',
enabledInConfig: true,
enabledInLicense: false,
minimumLicenseRequired: 'enterprise',
},
]}
/>
</ActionsConnectorsContextProvider>
);
const callout = wrapper.find('UpgradeYourLicenseCallOut');
expect(callout).toHaveLength(0);
});
});

let count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ConnectorAddFlyout = ({
reloadConnectors,
} = useActionsConnectorsContext();
const [actionType, setActionType] = useState<ActionType | undefined>(undefined);
const [hasActionsDisabledByLicense, setHasActionsDisabledByLicense] = useState<boolean>(false);
const [hasActionsUpgradeableByTrial, setHasActionsUpgradeableByTrial] = useState<boolean>(false);

// hooks
const initialConnector = {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const ConnectorAddFlyout = ({
<ActionTypeMenu
onActionTypeChange={onActionTypeChange}
actionTypes={actionTypes}
setHasActionsDisabledByLicense={setHasActionsDisabledByLicense}
setHasActionsUpgradeableByTrial={setHasActionsUpgradeableByTrial}
/>
);
} else {
Expand Down Expand Up @@ -219,7 +219,7 @@ export const ConnectorAddFlyout = ({
</EuiFlyoutHeader>
<EuiFlyoutBody
banner={
!actionType && hasActionsDisabledByLicense ? (
!actionType && hasActionsUpgradeableByTrial ? (
<UpgradeYourLicenseCallOut http={http} />
) : (
<Fragment />
Expand Down

0 comments on commit 9fa5520

Please sign in to comment.