Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Mar 3, 2022
1 parent 83fa87b commit 676ec89
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
19 changes: 2 additions & 17 deletions x-pack/plugins/fleet/common/services/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,10 @@ export class LicenseService {
}

public isGoldPlus() {
return (
this.licenseInformation?.isAvailable &&
this.licenseInformation?.isActive &&
this.licenseInformation?.hasAtLeast('gold')
);
return this.hasAtLeast('gold');
}
public isEnterprise() {
return (
this.licenseInformation?.isAvailable &&
this.licenseInformation?.isActive &&
this.licenseInformation?.hasAtLeast('enterprise')
);
}
public isPlatinium() {
return (
this.licenseInformation?.isAvailable &&
this.licenseInformation?.isActive &&
this.licenseInformation?.hasAtLeast('platinum')
);
return this.hasAtLeast('enterprise');
}
public hasAtLeast(licenseType: LicenseType) {
return (
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface NewAgentPolicy {
monitoring_enabled?: MonitoringType;
unenroll_timeout?: number;
is_preconfigured?: boolean;
// Nullable to allow user to reset to default outputs
data_output_id?: string | null;
monitoring_output_id?: string | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('useOutputOptions', () => {
it('should generate enabled options if the licence is platinium', async () => {
const testRenderer = createFleetTestRendererMock();
mockedUseLicence.mockReturnValue({
isPlatinium: () => true,
hasAtLeast: () => true,
} as unknown as LicenseService);
mockApiCallsWithOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() => useOutputOptions());
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('useOutputOptions', () => {
it('should only enable the default options if the licence is not platinium', async () => {
const testRenderer = createFleetTestRendererMock();
mockedUseLicence.mockReturnValue({
isPlatinium: () => false,
hasAtLeast: () => false,
} as unknown as LicenseService);
mockApiCallsWithOutputs(testRenderer.startServices.http);
const { result, waitForNextUpdate } = testRenderer.renderHook(() => useOutputOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
import type { EuiSuperSelectOption } from '@elastic/eui';

import { useGetOutputs, useLicense } from '../../../../hooks';
import { LICENCE_FOR_PER_POLICY_OUTPUT } from '../../../../../../../common';

// The super select component do not support null or '' as a value
export const DEFAULT_OUTPUT_VALUE = '@@##DEFAULT_OUTPUT_VALUE##@@';
Expand All @@ -28,7 +29,7 @@ export function useOutputOptions() {
const outputsRequest = useGetOutputs();
const licenseService = useLicense();

const isPlatinium = useMemo(() => licenseService.isPlatinium(), [licenseService]);
const isLicenceAllowingPolicyPerOutput = licenseService.hasAtLeast(LICENCE_FOR_PER_POLICY_OUTPUT);

const outputOptions: Array<EuiSuperSelectOption<string>> = useMemo(() => {
if (outputsRequest.isLoading || !outputsRequest.data) {
Expand All @@ -38,9 +39,9 @@ export function useOutputOptions() {
return outputsRequest.data.items.map((item) => ({
value: item.id,
inputDisplay: item.name,
disabled: !isPlatinium,
disabled: !isLicenceAllowingPolicyPerOutput,
}));
}, [outputsRequest, isPlatinium]);
}, [outputsRequest, isLicenceAllowingPolicyPerOutput]);

const dataOutputOptions = useMemo(() => {
if (outputsRequest.isLoading || !outputsRequest.data) {
Expand Down

0 comments on commit 676ec89

Please sign in to comment.