Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alerting] only show trial upgrade when running with basic license #64865

Merged
merged 3 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 gold or 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 ', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests ❤️

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