Skip to content

Commit

Permalink
Merge branch 'use-fetch-data-view-hook' of github.com:dhurley14/kiban…
Browse files Browse the repository at this point in the history
…a into use-fetch-data-view-hook
  • Loading branch information
dhurley14 committed Jun 23, 2023
2 parents 8c63fbc + bdcb250 commit 736753e
Show file tree
Hide file tree
Showing 154 changed files with 3,353 additions and 3,030 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ async function fetchDocuments(esClient: ElasticsearchClient, index: string) {

const assertMigratedDocuments = (arr: any[], target: any[]) => target.every((v) => arr.includes(v));

describe('migration v2', () => {
// FAILING ES PROMOTION: https://github.com/elastic/kibana/issues/160295
describe.skip('migration v2', () => {
let esServer: TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<TestElasticsearchUtils>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EuiButtonEmpty, EuiPageHeader, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import type { CoreStart, HttpStart } from '@kbn/core/public';
import React from 'react';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import type { SearchSessionsMgmtAPI } from '../lib/api';
import type { AsyncSearchIntroDocumentation } from '../lib/documentation';
import { SearchSessionsMgmtTable } from './table';
Expand All @@ -29,7 +30,7 @@ interface Props {

export function SearchSessionsMgmtMain({ documentation, ...tableProps }: Props) {
return (
<>
<KibanaThemeProvider theme$={tableProps.core.theme.theme$}>
<EuiPageHeader
pageTitle={
<FormattedMessage
Expand Down Expand Up @@ -60,6 +61,6 @@ export function SearchSessionsMgmtMain({ documentation, ...tableProps }: Props)

<EuiSpacer size="l" />
<SearchSessionsMgmtTable data-test-subj="search-sessions-mgmt-table" {...tableProps} />
</>
</KibanaThemeProvider>
);
}
5 changes: 2 additions & 3 deletions test/functional/apps/home/_newsfeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const globalNav = getService('globalNav');
const PageObjects = getPageObjects(['newsfeed']);
const PageObjects = getPageObjects(['newsfeed', 'common']);

// FLAKY: https://github.com/elastic/kibana/issues/135251
describe.skip('Newsfeed', () => {
describe('Newsfeed', () => {
before(async () => {
await PageObjects.newsfeed.resetPage();
});
Expand Down
8 changes: 6 additions & 2 deletions test/functional/page_objects/newsfeed_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { setTimeout as setTimeoutAsync } from 'timers/promises';
import { FtrService } from '../ftr_provider_context';

export class NewsfeedPageObject extends FtrService {
Expand All @@ -16,8 +16,12 @@ export class NewsfeedPageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly common = this.ctx.getPageObject('common');

async sleep(sleepMilliseconds: number) {
await setTimeoutAsync(sleepMilliseconds);
}

async resetPage() {
await this.common.navigateToApp('home', { disableWelcomePrompt: true });
await this.common.navigateToUrl('home', undefined); // navigateToApp sets `disableWelcomePrompt` to true under the hood. `navigateToUrl` explicitly disables the welcome screen.
}

async closeNewsfeedPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const ResultsLinks: FC<Props> = ({
getAdditionalLinks.map(async (asyncCardGetter) => {
const results = await asyncCardGetter({
dataViewId,
globalState,
});
if (Array.isArray(results)) {
return await Promise.all(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import { mockHttpValues } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { createEngine } from './create_engine_api_logic';
import { createSearchApplication } from './create_search_application_api_logic';

describe('CreateEngineApiLogic', () => {
describe('CreateSearchApplicationApiLogic', () => {
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
});
describe('createEngine', () => {
describe('createSearchApplication', () => {
it('calls correct api', async () => {
const engine = { engineName: 'my-engine', indices: ['an-index'] };
const searchApplication = { indices: ['an-index'], name: 'my-search-application' };
const response = { result: 'created' };
const promise = Promise.resolve(response);
http.put.mockReturnValue(promise);
const result = createEngine(engine);
const result = createSearchApplication(searchApplication);
await nextTick();
expect(http.put).toHaveBeenCalledWith(
'/internal/enterprise_search/search_applications/my-engine',
'/internal/enterprise_search/search_applications/my-search-application',
{
body: '{"indices":["an-index"],"name":"my-engine"}',
body: '{"indices":["an-index"],"name":"my-search-application"}',
query: { create: true },
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,34 @@ import { EnterpriseSearchApplicationUpsertResponse } from '../../../../../common
import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

export interface CreateEngineApiParams {
engineName: string;
export interface CreateSearchApplicationApiParams {
indices: string[];
name: string;
}

export type CreateEngineApiResponse = EnterpriseSearchApplicationUpsertResponse;
export type CreateSearchApplicationApiResponse = EnterpriseSearchApplicationUpsertResponse;

export type CreateEngineApiLogicActions = Actions<CreateEngineApiParams, CreateEngineApiResponse>;
export type CreateSearchApplicationApiLogicActions = Actions<
CreateSearchApplicationApiParams,
CreateSearchApplicationApiResponse
>;

export const createEngine = async ({
engineName,
export const createSearchApplication = async ({
name,
indices,
}: CreateEngineApiParams): Promise<CreateEngineApiResponse> => {
const route = `/internal/enterprise_search/search_applications/${engineName}`;
}: CreateSearchApplicationApiParams): Promise<CreateSearchApplicationApiResponse> => {
const route = `/internal/enterprise_search/search_applications/${name}`;

return await HttpLogic.values.http.put<EnterpriseSearchApplicationUpsertResponse>(route, {
body: JSON.stringify({ indices, name: engineName }),
body: JSON.stringify({ indices, name }),
query: { create: true },
});
};

export const CreateEngineApiLogic = createApiLogic(['create_engine_api_logic'], createEngine, {
showErrorFlash: false,
});
export const CreateSearchApplicationApiLogic = createApiLogic(
['search_applications', 'create_search_application_api_logic'],
createSearchApplication,
{
showErrorFlash: false,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import { mockHttpValues } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { deleteEngine } from './delete_engines_api_logic';
import { deleteSearchApplication } from './delete_search_application_api_logic';

describe('deleteEngineApiLogic', () => {
describe('DeleteSearchApplicationAPILogic', () => {
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
});
describe('deleteEngine', () => {
describe('deleteSearchApplication', () => {
it('calls correct api', async () => {
const promise = Promise.resolve();
http.post.mockReturnValue(promise);
const result = deleteEngine({ engineName: 'deleteEngineName' });
const result = deleteSearchApplication({ searchApplicationName: 'search-application' });
await nextTick();
expect(http.delete).toHaveBeenCalledWith(
'/internal/enterprise_search/search_applications/deleteEngineName'
'/internal/enterprise_search/search_applications/search-application'
);
await expect(result).resolves;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';

import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

export interface DeleteSearchApplicationApiLogicArguments {
searchApplicationName: string;
}
export interface DeleteSearchApplicationApiLogicResponse {
searchApplicationName: string;
}

export const deleteSearchApplication = async ({
searchApplicationName,
}: DeleteSearchApplicationApiLogicArguments): Promise<DeleteSearchApplicationApiLogicResponse> => {
const route = `/internal/enterprise_search/search_applications/${searchApplicationName}`;
await HttpLogic.values.http.delete<DeleteSearchApplicationApiLogicResponse>(route);
return { searchApplicationName };
};
export const DeleteSearchApplicationAPILogic = createApiLogic(
['search_applications', 'delete_search_application_api_logic'],
deleteSearchApplication,
{
showSuccessFlashFn: ({ searchApplicationName }) =>
i18n.translate(
'xpack.enterpriseSearch.searchApplications.list.deleteSearchApplication.successToast.title',
{
defaultMessage: '{searchApplicationName} has been deleted',
values: {
searchApplicationName,
},
}
),
}
);

export type DeleteSearchApplicationApiLogicActions = Actions<
DeleteSearchApplicationApiLogicArguments,
DeleteSearchApplicationApiLogicResponse
>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_lo
import { INPUT_THROTTLE_DELAY_MS } from '../../../shared/constants/timers';
import { HttpLogic } from '../../../shared/http';

export interface EnginesFetchIndicesApiParams {
export interface SearchApplicationsFetchIndicesApiParams {
searchQuery?: string;
}

export interface EnginesFetchIndicesApiResponse {
export interface SearchApplicationsFetchIndicesApiResponse {
indices: ElasticsearchIndexWithIngestion[];
meta: Meta;
searchQuery?: string;
Expand All @@ -26,7 +26,7 @@ const INDEX_SEARCH_PAGE_SIZE = 40;

export const fetchIndices = async ({
searchQuery,
}: EnginesFetchIndicesApiParams): Promise<EnginesFetchIndicesApiResponse> => {
}: SearchApplicationsFetchIndicesApiParams): Promise<SearchApplicationsFetchIndicesApiResponse> => {
const { http } = HttpLogic.values;
const route = '/internal/enterprise_search/indices';
const query = {
Expand All @@ -45,15 +45,15 @@ export const fetchIndices = async ({
return { ...response, searchQuery };
};

export const FetchIndicesForEnginesAPILogic = createApiLogic(
['content', 'engines_fetch_indices_api_logic'],
export const FetchIndicesForSearchApplicationsAPILogic = createApiLogic(
['search_applications', 'fetch_indices_api_logic'],
fetchIndices,
{
requestBreakpointMS: INPUT_THROTTLE_DELAY_MS,
}
);

export type FetchIndicesForEnginesAPILogicActions = Actions<
EnginesFetchIndicesApiParams,
EnginesFetchIndicesApiResponse
export type FetchIndicesForSearchApplicationsAPILogicActions = Actions<
SearchApplicationsFetchIndicesApiParams,
SearchApplicationsFetchIndicesApiResponse
>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import { mockHttpValues } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { fetchEngine } from './fetch_engine_api_logic';
import { fetchSearchApplication } from './fetch_search_application_api_logic';

describe('FetchEngineApiLogic', () => {
describe('FetchSearchApplicationApiLogic', () => {
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
});
describe('fetchEngine', () => {
describe('fetchSearchApplication', () => {
it('calls correct api', async () => {
const promise = Promise.resolve('result');
http.get.mockReturnValue(promise);
const result = fetchEngine({ engineName: 'my-engine' });
const result = fetchSearchApplication({ name: 'search-application' });
await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/internal/enterprise_search/search_applications/my-engine'
'/internal/enterprise_search/search_applications/search-application'
);
await expect(result).resolves.toEqual('result');
});
Expand Down
Loading

0 comments on commit 736753e

Please sign in to comment.