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

[App Search] Relevance Tuning stub page and server routes #89308

Merged
merged 14 commits into from
Feb 3, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export const EngineNav: React.FC = () => {
)}
{canManageEngineRelevanceTuning && (
<SideNavLink
isExternal
to={getAppSearchUrl(generateEnginePath(ENGINE_RELEVANCE_TUNING_PATH))}
to={generateEnginePath(ENGINE_RELEVANCE_TUNING_PATH)}
data-test-subj="EngineRelevanceTuningLink"
>
<EuiFlexGroup justifyContent="spaceBetween" gutterSize="none">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Switch, Redirect, useParams } from 'react-router-dom';
import { Loading } from '../../../shared/loading';
import { EngineOverview } from '../engine_overview';
import { AnalyticsRouter } from '../analytics';
import { RelevanceTuning } from '../relevance_tuning';

import { EngineRouter } from './engine_router';

Expand Down Expand Up @@ -93,4 +94,11 @@ describe('EngineRouter', () => {

expect(wrapper.find(AnalyticsRouter)).toHaveLength(1);
});

it('renders an relevance tuning view', () => {
setMockValues({ ...values, myRole: { canManageEngineRelevanceTuning: true } });
const wrapper = shallow(<EngineRouter />);

expect(wrapper.find(RelevanceTuning)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
// ENGINE_SCHEMA_PATH,
// ENGINE_CRAWLER_PATH,
// META_ENGINE_SOURCE_ENGINES_PATH,
// ENGINE_RELEVANCE_TUNING_PATH,
ENGINE_RELEVANCE_TUNING_PATH,
// ENGINE_SYNONYMS_PATH,
// ENGINE_CURATIONS_PATH,
// ENGINE_RESULT_SETTINGS_PATH,
Expand All @@ -37,20 +37,21 @@ import { Loading } from '../../../shared/loading';
import { EngineOverview } from '../engine_overview';
import { AnalyticsRouter } from '../analytics';
import { DocumentDetail, Documents } from '../documents';
import { RelevanceTuning } from '../relevance_tuning';

import { EngineLogic } from './';

export const EngineRouter: React.FC = () => {
const {
myRole: {
canViewEngineAnalytics,
canManageEngineRelevanceTuning,
// canViewEngineDocuments,
// canViewEngineSchema,
// canViewEngineCrawler,
// canViewMetaEngineSourceEngines,
// canManageEngineSynonyms,
// canManageEngineCurations,
// canManageEngineRelevanceTuning,
// canManageEngineResultSettings,
// canManageEngineSearchUi,
// canViewEngineApiLogs,
Expand Down Expand Up @@ -95,6 +96,11 @@ export const EngineRouter: React.FC = () => {
<Route path={ENGINE_DOCUMENTS_PATH}>
<Documents engineBreadcrumb={engineBreadcrumb} />
</Route>
{canManageEngineRelevanceTuning && (
<Route path={ENGINE_RELEVANCE_TUNING_PATH}>
<RelevanceTuning engineBreadcrumb={engineBreadcrumb} />
</Route>
)}
<Route>
<SetPageChrome trail={[...engineBreadcrumb, OVERVIEW_TITLE]} />
<EngineOverview />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export { RELEVANCE_TUNING_TITLE } from './constants';
export { RelevanceTuning } from './relevance_tuning';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';

import { shallow } from 'enzyme';

import { RelevanceTuning } from './relevance_tuning';

describe('RelevanceTuning', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders', () => {
const wrapper = shallow(<RelevanceTuning engineBreadcrumb={['test']} />);
expect(wrapper.isEmptyRender()).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import {
EuiPageHeader,
EuiPageHeaderSection,
EuiTitle,
EuiPageContentBody,
EuiPageContent,
} from '@elastic/eui';

import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';
import { FlashMessages } from '../../../shared/flash_messages';

import { RELEVANCE_TUNING_TITLE } from './constants';

interface Props {
engineBreadcrumb: string[];
}

export const RelevanceTuning: React.FC<Props> = ({ engineBreadcrumb }) => {
return (
<>
<SetPageChrome trail={[...engineBreadcrumb, RELEVANCE_TUNING_TITLE]} />
<EuiPageHeader>
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>{RELEVANCE_TUNING_TITLE}</h1>
</EuiTitle>
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentBody>
<FlashMessages />
</EuiPageContentBody>
</EuiPageContent>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ENGINE_CRAWLER_PATH = `${ENGINE_PATH}/crawler`;

export const META_ENGINE_SOURCE_ENGINES_PATH = `${ENGINE_PATH}/engines`;

export const ENGINE_RELEVANCE_TUNING_PATH = `${ENGINE_PATH}/search-settings`;
export const ENGINE_RELEVANCE_TUNING_PATH = `${ENGINE_PATH}/relevance_tuning`;
export const ENGINE_SYNONYMS_PATH = `${ENGINE_PATH}/synonyms`;
export const ENGINE_CURATIONS_PATH = `${ENGINE_PATH}/curations`;
// TODO: Curations sub-pages
Expand Down
20 changes: 13 additions & 7 deletions x-pack/plugins/enterprise_search/server/__mocks__/router.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ export class MockRouter {
};

public callRoute = async (request: MockRouterRequest) => {
const routerCalls = this.router[this.method].mock.calls as any[];
if (!routerCalls.length) throw new Error('No routes registered.');

const route = routerCalls.find(([router]: any) => router.path === this.path);
if (!route) throw new Error('No matching registered routes found - check method/path keys');

const route = this.findRouteRegistration();
const [, handler] = route;
const context = {} as jest.Mocked<RequestHandlerContext>;
await handler(context, httpServerMock.createKibanaRequest(request as any), this.response);
Expand All @@ -68,7 +63,8 @@ export class MockRouter {
public validateRoute = (request: MockRouterRequest) => {
if (!this.payload) throw new Error('Cannot validate wihout a payload type specified.');

const [config] = this.router[this.method].mock.calls[0];
const route = this.findRouteRegistration();
const [config] = route;
const validate = config.validate as RouteValidatorConfig<{}, {}, {}>;

const payloadValidation = validate[this.payload] as { validate(request: KibanaRequest): void };
Expand All @@ -84,6 +80,16 @@ export class MockRouter {
public shouldThrow = (request: MockRouterRequest) => {
expect(() => this.validateRoute(request)).toThrow();
};

private findRouteRegistration = () => {
const routerCalls = this.router[this.method].mock.calls as any[];
if (!routerCalls.length) throw new Error('No routes registered.');

const route = routerCalls.find(([router]: any) => router.path === this.path);
if (!route) throw new Error('No matching registered routes found - check method/path keys');

return route;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { registerCredentialsRoutes } from './credentials';
import { registerSettingsRoutes } from './settings';
import { registerAnalyticsRoutes } from './analytics';
import { registerDocumentsRoutes, registerDocumentRoutes } from './documents';
import { registerSearchSettingsRoutes } from './search_settings';

export const registerAppSearchRoutes = (dependencies: RouteDependencies) => {
registerEnginesRoutes(dependencies);
Expand All @@ -19,4 +20,5 @@ export const registerAppSearchRoutes = (dependencies: RouteDependencies) => {
registerAnalyticsRoutes(dependencies);
registerDocumentsRoutes(dependencies);
registerDocumentRoutes(dependencies);
registerSearchSettingsRoutes(dependencies);
};
Loading