mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Suggestions enabled check (#116136)
This commit is contained in:
parent
33fd1bdff0
commit
b1dab1f029
12 changed files with 99 additions and 93 deletions
|
@ -26,6 +26,10 @@ const MOCK_VALUES = {
|
|||
},
|
||||
queries: ['some query'],
|
||||
},
|
||||
// EngineLogic
|
||||
engine: {
|
||||
search_relevance_suggestions_active: true,
|
||||
},
|
||||
};
|
||||
|
||||
describe('SuggestedDocumentsCallout', () => {
|
||||
|
@ -40,7 +44,7 @@ describe('SuggestedDocumentsCallout', () => {
|
|||
expect(wrapper.is(SuggestionsCallout));
|
||||
});
|
||||
|
||||
it('is empty when the suggested is undefined', () => {
|
||||
it('is empty when the suggestion is undefined', () => {
|
||||
setMockValues({ ...MOCK_VALUES, curation: {} });
|
||||
|
||||
const wrapper = shallow(<SuggestedDocumentsCallout />);
|
||||
|
@ -48,6 +52,15 @@ describe('SuggestedDocumentsCallout', () => {
|
|||
expect(wrapper.isEmptyRender()).toBe(true);
|
||||
});
|
||||
|
||||
it('is empty when suggestions are not active', () => {
|
||||
const values = set('engine.search_relevance_suggestions_active', false, MOCK_VALUES);
|
||||
setMockValues(values);
|
||||
|
||||
const wrapper = shallow(<SuggestedDocumentsCallout />);
|
||||
|
||||
expect(wrapper.isEmptyRender()).toBe(true);
|
||||
});
|
||||
|
||||
it('is empty when curation status is not pending', () => {
|
||||
const values = set('curation.suggestion.status', 'applied', MOCK_VALUES);
|
||||
setMockValues(values);
|
||||
|
|
|
@ -11,7 +11,7 @@ import { useValues } from 'kea';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { ENGINE_CURATION_SUGGESTION_PATH } from '../../../routes';
|
||||
import { generateEnginePath } from '../../engine';
|
||||
import { EngineLogic, generateEnginePath } from '../../engine';
|
||||
|
||||
import { SuggestionsCallout } from '../components/suggestions_callout';
|
||||
|
||||
|
@ -21,8 +21,15 @@ export const SuggestedDocumentsCallout: React.FC = () => {
|
|||
const {
|
||||
curation: { suggestion, queries },
|
||||
} = useValues(CurationLogic);
|
||||
const {
|
||||
engine: { search_relevance_suggestions_active: searchRelevanceSuggestionsActive },
|
||||
} = useValues(EngineLogic);
|
||||
|
||||
if (typeof suggestion === 'undefined' || suggestion.status !== 'pending') {
|
||||
if (
|
||||
typeof suggestion === 'undefined' ||
|
||||
suggestion.status !== 'pending' ||
|
||||
searchRelevanceSuggestionsActive === false
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import React from 'react';
|
|||
|
||||
import { shallow } from 'enzyme';
|
||||
|
||||
import { set } from 'lodash/fp';
|
||||
|
||||
import { EuiTab } from '@elastic/eui';
|
||||
|
||||
import { getPageHeaderTabs, getPageTitle } from '../../../../test_helpers';
|
||||
|
@ -51,8 +53,10 @@ describe('Curations', () => {
|
|||
curationsSettings: {
|
||||
enabled: true,
|
||||
},
|
||||
// LicensingLogic
|
||||
hasPlatinumLicense: true,
|
||||
// EngineLogic
|
||||
engine: {
|
||||
search_relevance_suggestions_active: true,
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
@ -84,8 +88,8 @@ describe('Curations', () => {
|
|||
expect(actions.onSelectPageTab).toHaveBeenNthCalledWith(3, 'settings');
|
||||
});
|
||||
|
||||
it('renders less tabs when less than platinum license', () => {
|
||||
setMockValues({ ...values, hasPlatinumLicense: false });
|
||||
it('renders less tabs when suggestions are not active', () => {
|
||||
setMockValues(set('engine.search_relevance_suggestions_active', false, values));
|
||||
const wrapper = shallow(<Curations />);
|
||||
|
||||
expect(getPageTitle(wrapper)).toEqual('Curated results');
|
||||
|
@ -94,8 +98,8 @@ describe('Curations', () => {
|
|||
expect(tabs.length).toBe(2);
|
||||
});
|
||||
|
||||
it('renders a New! badge when less than platinum license', () => {
|
||||
setMockValues({ ...values, hasPlatinumLicense: false });
|
||||
it('renders a New! badge when suggestions are not active', () => {
|
||||
setMockValues(set('engine.search_relevance_suggestions_active', false, values));
|
||||
const wrapper = shallow(<Curations />);
|
||||
|
||||
expect(getPageTitle(wrapper)).toEqual('Curated results');
|
||||
|
@ -104,29 +108,8 @@ describe('Curations', () => {
|
|||
expect(tabs.at(1).prop('append')).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('renders a New! badge when suggestions are disabled', () => {
|
||||
setMockValues({
|
||||
...values,
|
||||
curationsSettings: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
const wrapper = shallow(<Curations />);
|
||||
|
||||
expect(getPageTitle(wrapper)).toEqual('Curated results');
|
||||
|
||||
const tabs = getPageHeaderTabs(wrapper).find(EuiTab);
|
||||
expect(tabs.at(2).prop('append')).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('hides the badge when suggestions are enabled and the user has a platinum license', () => {
|
||||
setMockValues({
|
||||
...values,
|
||||
hasPlatinumLicense: true,
|
||||
curationsSettings: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
it('hides the badge when suggestions are active', () => {
|
||||
setMockValues(set('engine.search_relevance_suggestions_active', true, values));
|
||||
const wrapper = shallow(<Curations />);
|
||||
|
||||
expect(getPageTitle(wrapper)).toEqual('Curated results');
|
||||
|
|
|
@ -12,11 +12,10 @@ import { useValues, useActions } from 'kea';
|
|||
import { EuiBadge } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { LicensingLogic } from '../../../../shared/licensing';
|
||||
import { EuiButtonTo } from '../../../../shared/react_router_helpers';
|
||||
|
||||
import { ENGINE_CURATIONS_NEW_PATH } from '../../../routes';
|
||||
import { generateEnginePath } from '../../engine';
|
||||
import { EngineLogic, generateEnginePath } from '../../engine';
|
||||
import { AppSearchPageTemplate } from '../../layout';
|
||||
|
||||
import { CURATIONS_OVERVIEW_TITLE, CREATE_NEW_CURATION_TITLE } from '../constants';
|
||||
|
@ -30,13 +29,13 @@ import { CurationsSettings, CurationsSettingsLogic } from './curations_settings'
|
|||
export const Curations: React.FC = () => {
|
||||
const { dataLoading: curationsDataLoading, meta, selectedPageTab } = useValues(CurationsLogic);
|
||||
const { loadCurations, onSelectPageTab } = useActions(CurationsLogic);
|
||||
const { hasPlatinumLicense } = useValues(LicensingLogic);
|
||||
const {
|
||||
dataLoading: curationsSettingsDataLoading,
|
||||
curationsSettings: { enabled: curationsSettingsEnabled },
|
||||
} = useValues(CurationsSettingsLogic);
|
||||
engine: { search_relevance_suggestions_active: searchRelevanceSuggestionsActive },
|
||||
} = useValues(EngineLogic);
|
||||
|
||||
const suggestionsEnabled = hasPlatinumLicense && curationsSettingsEnabled;
|
||||
const { dataLoading: curationsSettingsDataLoading } = useValues(CurationsSettingsLogic);
|
||||
|
||||
const suggestionsEnabled = searchRelevanceSuggestionsActive;
|
||||
|
||||
const OVERVIEW_TAB = {
|
||||
label: i18n.translate(
|
||||
|
@ -75,7 +74,7 @@ export const Curations: React.FC = () => {
|
|||
),
|
||||
};
|
||||
|
||||
const pageTabs = hasPlatinumLicense
|
||||
const pageTabs = searchRelevanceSuggestionsActive
|
||||
? [OVERVIEW_TAB, HISTORY_TAB, SETTINGS_TAB]
|
||||
: [OVERVIEW_TAB, SETTINGS_TAB];
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import '../../../__mocks__/engine_logic.mock';
|
|||
import React from 'react';
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import { set } from 'lodash/fp';
|
||||
|
||||
import { CurationsTable, EmptyState } from '../components';
|
||||
|
||||
|
@ -33,8 +34,10 @@ const MOCK_VALUES = {
|
|||
id: 'cur-id-2',
|
||||
},
|
||||
],
|
||||
// LicensingLogics
|
||||
hasPlatinumLicense: true,
|
||||
// EngineLogic
|
||||
engine: {
|
||||
search_relevance_suggestions_active: true,
|
||||
},
|
||||
};
|
||||
|
||||
describe('CurationsOverview', () => {
|
||||
|
@ -67,36 +70,15 @@ describe('CurationsOverview', () => {
|
|||
expect(wrapper.find(CurationsTable)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders a suggestions table when the user has a platinum license and curations suggestions enabled', () => {
|
||||
setMockValues({
|
||||
...MOCK_VALUES,
|
||||
hasPlatinumLicense: true,
|
||||
curationsSettings: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
it('renders a suggestions table when suggestions are active', () => {
|
||||
setMockValues(set('engine.search_relevance_suggestions_active', true, MOCK_VALUES));
|
||||
const wrapper = shallow(<CurationsOverview />);
|
||||
|
||||
expect(wrapper.find(SuggestionsTable).exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('doesn\t render a suggestions table when the user has no platinum license', () => {
|
||||
setMockValues({
|
||||
...MOCK_VALUES,
|
||||
hasPlatinumLicense: false,
|
||||
});
|
||||
const wrapper = shallow(<CurationsOverview />);
|
||||
|
||||
expect(wrapper.find(SuggestionsTable).exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('doesn\t render a suggestions table when the user has disabled suggestions', () => {
|
||||
setMockValues({
|
||||
...MOCK_VALUES,
|
||||
curationsSettings: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
it('doesn\t render a suggestions table when suggestions are not active', () => {
|
||||
setMockValues(set('engine.search_relevance_suggestions_active', false, MOCK_VALUES));
|
||||
const wrapper = shallow(<CurationsOverview />);
|
||||
|
||||
expect(wrapper.find(SuggestionsTable).exists()).toBe(false);
|
||||
|
|
|
@ -11,22 +11,18 @@ import { useValues } from 'kea';
|
|||
|
||||
import { EuiSpacer } from '@elastic/eui';
|
||||
|
||||
import { LicensingLogic } from '../../../../shared/licensing';
|
||||
import { EngineLogic } from '../../engine';
|
||||
import { CurationsTable, EmptyState } from '../components';
|
||||
import { SuggestionsTable } from '../components/suggestions_table';
|
||||
import { CurationsLogic } from '../curations_logic';
|
||||
|
||||
import { CurationsSettingsLogic } from './curations_settings';
|
||||
|
||||
export const CurationsOverview: React.FC = () => {
|
||||
const { curations } = useValues(CurationsLogic);
|
||||
const { hasPlatinumLicense } = useValues(LicensingLogic);
|
||||
|
||||
const {
|
||||
curationsSettings: { enabled },
|
||||
} = useValues(CurationsSettingsLogic);
|
||||
engine: { search_relevance_suggestions_active: searchRelevanceSuggestionsActive },
|
||||
} = useValues(EngineLogic);
|
||||
|
||||
const shouldShowSuggestions = enabled && hasPlatinumLicense;
|
||||
const shouldShowSuggestions = searchRelevanceSuggestionsActive;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -12,8 +12,20 @@ import {
|
|||
} from '../../../../../__mocks__/kea_logic';
|
||||
import '../../../../__mocks__/engine_logic.mock';
|
||||
|
||||
jest.mock('../../curations_logic', () => ({
|
||||
CurationsLogic: {
|
||||
values: {},
|
||||
actions: {
|
||||
loadCurations: jest.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { CurationsLogic } from '../..';
|
||||
import { EngineLogic } from '../../../engine';
|
||||
|
||||
import { CurationsSettingsLogic } from './curations_settings_logic';
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
|
@ -205,6 +217,10 @@ describe('CurationsSettingsLogic', () => {
|
|||
enabled: true,
|
||||
mode: 'automatic',
|
||||
});
|
||||
|
||||
// data should have been reloaded
|
||||
expect(EngineLogic.actions.initializeEngine).toHaveBeenCalled();
|
||||
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('presents any API errors to the user', async () => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import { kea, MakeLogicType } from 'kea';
|
|||
import { flashAPIErrors } from '../../../../../shared/flash_messages';
|
||||
import { HttpLogic } from '../../../../../shared/http';
|
||||
import { EngineLogic } from '../../../engine';
|
||||
import { CurationsLogic } from '../../curations_logic';
|
||||
|
||||
export interface CurationsSettings {
|
||||
enabled: boolean;
|
||||
|
@ -101,6 +102,10 @@ export const CurationsSettingsLogic = kea<
|
|||
}
|
||||
);
|
||||
actions.onCurationsSettingsLoad(response.curation);
|
||||
|
||||
// Re-fetch data so that UI updates to new settings
|
||||
CurationsLogic.actions.loadCurations();
|
||||
EngineLogic.actions.initializeEngine();
|
||||
} catch (e) {
|
||||
flashAPIErrors(e);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ describe('EngineLogic', () => {
|
|||
schema: { test: SchemaType.Text },
|
||||
apiTokens: [],
|
||||
apiKey: 'some-key',
|
||||
search_relevance_suggestions_active: true,
|
||||
};
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
|
|
|
@ -54,6 +54,7 @@ export interface EngineDetails extends Engine {
|
|||
engine_count?: number;
|
||||
includedEngines?: EngineDetails[];
|
||||
search_relevance_suggestions?: SearchRelevanceSuggestionDetails;
|
||||
search_relevance_suggestions_active: boolean;
|
||||
}
|
||||
|
||||
interface ResultField {
|
||||
|
|
|
@ -18,16 +18,14 @@ import { SuggestionsCallout } from '../../curations/components/suggestions_callo
|
|||
import { SuggestedCurationsCallout } from './suggested_curations_callout';
|
||||
|
||||
const MOCK_VALUES = {
|
||||
// EngineLogic
|
||||
engine: {
|
||||
search_relevance_suggestions: {
|
||||
curation: {
|
||||
pending: 1,
|
||||
},
|
||||
},
|
||||
search_relevance_suggestions_active: true,
|
||||
},
|
||||
// LicensingLogic
|
||||
hasPlatinumLicense: true,
|
||||
};
|
||||
|
||||
describe('SuggestedCurationsCallout', () => {
|
||||
|
@ -43,7 +41,21 @@ describe('SuggestedCurationsCallout', () => {
|
|||
});
|
||||
|
||||
it('is empty when the suggestions are undefined', () => {
|
||||
setMockValues({ ...MOCK_VALUES, engine: {} });
|
||||
setMockValues({
|
||||
...MOCK_VALUES,
|
||||
engine: {
|
||||
search_relevance_suggestions_active: true,
|
||||
},
|
||||
});
|
||||
|
||||
const wrapper = shallow(<SuggestedCurationsCallout />);
|
||||
|
||||
expect(wrapper.isEmptyRender()).toBe(true);
|
||||
});
|
||||
|
||||
it('is empty when suggestions are not active', () => {
|
||||
const values = set('engine.search_relevance_suggestions_active', false, MOCK_VALUES);
|
||||
setMockValues(values);
|
||||
|
||||
const wrapper = shallow(<SuggestedCurationsCallout />);
|
||||
|
||||
|
@ -58,14 +70,4 @@ describe('SuggestedCurationsCallout', () => {
|
|||
|
||||
expect(wrapper.isEmptyRender()).toBe(true);
|
||||
});
|
||||
|
||||
it('is empty when the user has no platinum license', () => {
|
||||
// This would happen if the user *had* suggestions and then downgraded from platinum to gold or something
|
||||
const values = set('hasPlatinumLicense', false, MOCK_VALUES);
|
||||
setMockValues(values);
|
||||
|
||||
const wrapper = shallow(<SuggestedCurationsCallout />);
|
||||
|
||||
expect(wrapper.isEmptyRender()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,23 +10,24 @@ import { useValues } from 'kea';
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { LicensingLogic } from '../../../../shared/licensing';
|
||||
import { ENGINE_CURATIONS_PATH } from '../../../routes';
|
||||
import { SuggestionsCallout } from '../../curations/components/suggestions_callout';
|
||||
import { EngineLogic, generateEnginePath } from '../../engine';
|
||||
|
||||
export const SuggestedCurationsCallout: React.FC = () => {
|
||||
const {
|
||||
engine: { search_relevance_suggestions: searchRelevanceSuggestions },
|
||||
engine: {
|
||||
search_relevance_suggestions: searchRelevanceSuggestions,
|
||||
search_relevance_suggestions_active: searchRelevanceSuggestionsActive,
|
||||
},
|
||||
} = useValues(EngineLogic);
|
||||
const { hasPlatinumLicense } = useValues(LicensingLogic);
|
||||
|
||||
const pendingCount = searchRelevanceSuggestions?.curation.pending;
|
||||
|
||||
if (
|
||||
typeof searchRelevanceSuggestions === 'undefined' ||
|
||||
pendingCount === 0 ||
|
||||
hasPlatinumLicense === false
|
||||
searchRelevanceSuggestionsActive === false
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue