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

[Enterprise Search][Search Application] Update engines to be search application #155299

Merged
merged 16 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -45,10 +45,13 @@ export const AddIndicesFlyout: React.FC<AddIndicesFlyoutProps> = ({ onClose }) =
const { selectedIndices, updateEngineStatus, updateEngineError } = useValues(AddIndicesLogic);
const { setSelectedIndices, submitSelectedIndices } = useActions(AddIndicesLogic);

const selectedOptions = useMemo(() => selectedIndices.map(indexToOption), [selectedIndices]);
const selectedOptions = useMemo(
() => selectedIndices.map((index) => indexToOption(index)),
[selectedIndices]
);
const onIndicesChange = useCallback(
(options: IndicesSelectComboBoxOption[]) => {
setSelectedIndices(options.map(({ value }) => value).filter(isNotNullish));
setSelectedIndices(options.map(({ label }) => label).filter(isNotNullish));
},
[setSelectedIndices]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { LogicMounter } from '../../../__mocks__/kea_logic';

import { Status } from '../../../../../common/types/api';
import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices';

import { AddIndicesLogic, AddIndicesLogicValues } from './add_indices_logic';

Expand All @@ -18,16 +17,6 @@ const DEFAULT_VALUES: AddIndicesLogicValues = {
updateEngineStatus: Status.IDLE,
};

const makeIndexData = (name: string): ElasticsearchIndexWithIngestion => ({
count: 0,
hidden: false,
name,
total: {
docs: { count: 0, deleted: 0 },
store: { size_in_bytes: 'n/a' },
},
});

describe('AddIndicesLogic', () => {
const { mount: mountAddIndicesLogic } = new LogicMounter(AddIndicesLogic);
const { mount: mountEngineIndicesLogic } = new LogicMounter(AddIndicesLogic);
Expand All @@ -47,31 +36,16 @@ describe('AddIndicesLogic', () => {
describe('actions', () => {
describe('setSelectedIndices', () => {
it('adds the indices to selectedIndices', () => {
AddIndicesLogic.actions.setSelectedIndices([
makeIndexData('index-001'),
makeIndexData('index-002'),
]);
AddIndicesLogic.actions.setSelectedIndices(['index-001', 'index-002']);

expect(AddIndicesLogic.values.selectedIndices).toEqual([
makeIndexData('index-001'),
makeIndexData('index-002'),
]);
expect(AddIndicesLogic.values.selectedIndices).toEqual(['index-001', 'index-002']);
});

it('replaces any existing indices', () => {
AddIndicesLogic.actions.setSelectedIndices([
makeIndexData('index-001'),
makeIndexData('index-002'),
]);
AddIndicesLogic.actions.setSelectedIndices([
makeIndexData('index-003'),
makeIndexData('index-004'),
]);
AddIndicesLogic.actions.setSelectedIndices(['index-001', 'index-002']);
AddIndicesLogic.actions.setSelectedIndices(['index-003', 'index-004']);

expect(AddIndicesLogic.values.selectedIndices).toEqual([
makeIndexData('index-003'),
makeIndexData('index-004'),
]);
expect(AddIndicesLogic.values.selectedIndices).toEqual(['index-003', 'index-004']);
});
});
});
Expand Down Expand Up @@ -103,10 +77,7 @@ describe('AddIndicesLogic', () => {
it('calls addIndicesToEngine when there are selectedIndices', () => {
jest.spyOn(AddIndicesLogic.actions, 'addIndicesToEngine');

AddIndicesLogic.actions.setSelectedIndices([
makeIndexData('index-001'),
makeIndexData('index-002'),
]);
AddIndicesLogic.actions.setSelectedIndices(['index-001', 'index-002']);
AddIndicesLogic.actions.submitSelectedIndices();

expect(AddIndicesLogic.actions.addIndicesToEngine).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { kea, MakeLogicType } from 'kea';

import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices';

import { UpdateEngineApiLogic } from '../../api/engines/update_engine_api_logic';

import { EngineIndicesLogic, EngineIndicesLogicActions } from './engine_indices_logic';
Expand All @@ -17,21 +15,21 @@ export interface AddIndicesLogicActions {
addIndicesToEngine: EngineIndicesLogicActions['addIndicesToEngine'];
closeAddIndicesFlyout: EngineIndicesLogicActions['closeAddIndicesFlyout'];
engineUpdated: EngineIndicesLogicActions['engineUpdated'];
setSelectedIndices: (indices: ElasticsearchIndexWithIngestion[]) => {
indices: ElasticsearchIndexWithIngestion[];
setSelectedIndices: (indices: string[]) => {
indices: string[];
};
submitSelectedIndices: () => void;
}

export interface AddIndicesLogicValues {
selectedIndices: ElasticsearchIndexWithIngestion[];
selectedIndices: string[];
updateEngineError: typeof UpdateEngineApiLogic.values.error | undefined;
updateEngineStatus: typeof UpdateEngineApiLogic.values.status;
}

export const AddIndicesLogic = kea<MakeLogicType<AddIndicesLogicValues, AddIndicesLogicActions>>({
actions: {
setSelectedIndices: (indices: ElasticsearchIndexWithIngestion[]) => ({ indices }),
setSelectedIndices: (indices: string[]) => ({ indices }),
submitSelectedIndices: () => true,
},
connect: {
Expand All @@ -46,7 +44,7 @@ export const AddIndicesLogic = kea<MakeLogicType<AddIndicesLogicValues, AddIndic
const { selectedIndices } = values;
if (selectedIndices.length === 0) return;

actions.addIndicesToEngine(selectedIndices.map(({ name }) => name));
actions.addIndicesToEngine(selectedIndices);
},
}),
path: ['enterprise_search', 'content', 'add_indices_logic'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export const EngineError: React.FC<{ error: HttpError | undefined }> = ({ error
<>
<SendEnterpriseSearchTelemetry action="error" metric="not_found" />
<NotFoundPrompt
backToContent={i18n.translate('xpack.enterpriseSearch.engines.engine.notFound.action1', {
defaultMessage: 'Back to Engines',
})}
backToContent={i18n.translate(
'xpack.enterpriseSearch.searchApplications.engine.notFound.action1',
{
defaultMessage: 'Back to Search Applications',
}
)}
backToLink={ENGINES_PATH}
productSupportUrl={ENTERPRISE_SEARCH_CONTENT_PLUGIN.SUPPORT_URL}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const EngineIndices: React.FC = () => {
description: i18n.translate(
'xpack.enterpriseSearch.content.engine.indices.actions.removeIndex.title',
{
defaultMessage: 'Remove this index from engine',
defaultMessage: 'Remove this index from search application',
}
),
icon: 'minusInCircle',
Expand Down Expand Up @@ -213,7 +213,7 @@ export const EngineIndices: React.FC = () => {
'xpack.enterpriseSearch.content.engine.indices.unknownIndicesCallout.description',
{
defaultMessage:
'Some data might be unreachable from this engine. Check for any pending operations or errors on affected indices, or remove those that should no longer be used by this engine.',
'Some data might be unreachable from this search application. Check for any pending operations or errors on affected indices, or remove those that should no longer be used by this search application.',
}
)}
</p>
Expand Down Expand Up @@ -257,7 +257,7 @@ export const EngineIndices: React.FC = () => {
}}
title={i18n.translate(
'xpack.enterpriseSearch.content.engine.indices.removeIndexConfirm.title',
{ defaultMessage: 'Remove this index from the engine' }
{ defaultMessage: 'Remove this index from the Search Application' }
)}
buttonColor="danger"
cancelButtonText={CANCEL_BUTTON_LABEL}
Expand All @@ -276,7 +276,7 @@ export const EngineIndices: React.FC = () => {
'xpack.enterpriseSearch.content.engine.indices.removeIndexConfirm.description',
{
defaultMessage:
"This won't delete the index. You may add it back to this engine at a later time.",
"This won't delete the index. You may add it back to this search application at a later time.",
}
)}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const IndicesSelectComboBox = (props: IndicesSelectComboBoxProps) => {
}, [searchQuery]);

const options: Array<EuiComboBoxOptionOption<ElasticsearchIndexWithIngestion>> =
data?.indices?.map(indexToOption) ?? [];
data?.indices?.map((index) => indexToOption(index.name, index)) ?? [];

const renderOption = (option: EuiComboBoxOptionOption<ElasticsearchIndexWithIngestion>) => (
<EuiFlexGroup>
Expand Down Expand Up @@ -84,8 +84,9 @@ export const IndicesSelectComboBox = (props: IndicesSelectComboBoxProps) => {
};

export const indexToOption = (
index: ElasticsearchIndexWithIngestion
indexName: string,
index?: ElasticsearchIndexWithIngestion
): IndicesSelectComboBoxOption => ({
label: index.name,
label: indexName,
value: index,
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const EnginesListTable: React.FC<EnginesListTableProps> = ({
description: i18n.translate(
'xpack.enterpriseSearch.content.enginesList.table.column.actions.view.buttonDescription',
{
defaultMessage: 'View this engine',
defaultMessage: 'View this search application',
}
),
type: 'icon',
Expand All @@ -134,7 +134,7 @@ export const EnginesListTable: React.FC<EnginesListTableProps> = ({
description: i18n.translate(
'xpack.enterpriseSearch.content.enginesList.table.column.action.delete.buttonDescription',
{
defaultMessage: 'Delete this engine',
defaultMessage: 'Delete this search application',
}
),
type: 'icon',
Expand All @@ -144,7 +144,7 @@ export const EnginesListTable: React.FC<EnginesListTableProps> = ({
i18n.translate(
'xpack.enterpriseSearch.content.engineList.table.column.actions.deleteEngineLabel',
{
defaultMessage: 'Delete this engine',
defaultMessage: 'Delete this search application',
}
),
onClick: (engine) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import React from 'react';
import React, { useEffect } from 'react';

import { useLocation } from 'react-router-dom';

import { useActions, useValues } from 'kea';

import {
EuiButton,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiFieldText,
Expand All @@ -33,14 +33,18 @@ import { FormattedMessage } from '@kbn/i18n-react';

import { Status } from '../../../../../common/types/api';
import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices';
import { isNotNullish } from '../../../../../common/utils/is_not_nullish';

import { CANCEL_BUTTON_LABEL } from '../../../shared/constants';
import { CANCEL_BUTTON_LABEL, ESINDEX_QUERY_PARAMETER } from '../../../shared/constants';
import { docLinks } from '../../../shared/doc_links';
import { getErrorsFromHttpResponse } from '../../../shared/flash_messages/handle_api_errors';

import { indexToOption, IndicesSelectComboBox } from './components/indices_select_combobox';
import { parseQueryParams } from '../../../shared/query_params';

import { EuiButtonEmptyTo, EuiButtonTo } from '../../../shared/react_router_helpers';

import { ENGINES_PATH } from '../../routes';

import { indexToOption, IndicesSelectComboBox } from './components/indices_select_combobox';
import { CreateEngineLogic } from './create_engine_logic';

export interface CreateEngineFlyoutProps {
Expand All @@ -60,19 +64,26 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
selectedIndices,
} = useValues(CreateEngineLogic);

const { search } = useLocation() as unknown as Location;
const { ...params } = parseQueryParams(search);
const indexName = params[ESINDEX_QUERY_PARAMETER];

const onIndicesChange = (
selectedOptions: Array<EuiComboBoxOptionOption<ElasticsearchIndexWithIngestion>>
) => {
setSelectedIndices(selectedOptions.map((option) => option.value).filter(isNotNullish));
setSelectedIndices(selectedOptions.map((option) => option.label));
};
useEffect(() => {
if (indexName && typeof indexName === 'string') setSelectedIndices([indexName]);
}, []);

return (
<EuiFlyout onClose={onClose} size="m">
<EuiFlyoutHeader>
<EuiTitle size="m">
<h3>
{i18n.translate('xpack.enterpriseSearch.content.engines.createEngine.headerTitle', {
defaultMessage: 'Create an engine',
defaultMessage: 'Create an Search Application',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defaultMessage: 'Create an Search Application',
defaultMessage: 'Create a Search Application',

})}
</h3>
</EuiTitle>
Expand All @@ -81,7 +92,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
<p>
<FormattedMessage
id="xpack.enterpriseSearch.content.engines.createEngine.headerSubTitle"
defaultMessage="An engine allows your users to query data in your indices. Explore our {enginesDocsLink} to learn more!"
defaultMessage="An Search Application allows your users to query data in your indices. Explore our {enginesDocsLink} to learn more!"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defaultMessage="An Search Application allows your users to query data in your indices. Explore our {enginesDocsLink} to learn more!"
defaultMessage="A Search Application allows your users to query data in your indices. Explore our {enginesDocsLink} to learn more!"

values={{
enginesDocsLink: (
<EuiLink
Expand All @@ -92,7 +103,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
>
{i18n.translate(
'xpack.enterpriseSearch.content.engines.createEngine.header.docsLink',
{ defaultMessage: 'Engines documentation' }
{ defaultMessage: 'Search Application documentation' }
)}
</EuiLink>
),
Expand All @@ -107,7 +118,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
color="danger"
title={i18n.translate(
'xpack.enterpriseSearch.content.engines.createEngine.header.createError.title',
{ defaultMessage: 'Error creating engine' }
{ defaultMessage: 'Error creating search application' }
)}
>
{getErrorsFromHttpResponse(createEngineError).map((errMessage, i) => (
Expand All @@ -126,7 +137,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
fullWidth
isDisabled={formDisabled}
onChange={onIndicesChange}
selectedOptions={selectedIndices.map(indexToOption)}
selectedOptions={selectedIndices.map((index: string) => indexToOption(index))}
/>
),
status: indicesStatus,
Expand All @@ -142,7 +153,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
disabled={formDisabled}
placeholder={i18n.translate(
'xpack.enterpriseSearch.content.engines.createEngine.nameEngine.placeholder',
{ defaultMessage: 'Engine name' }
{ defaultMessage: 'Search Application name' }
)}
value={engineName}
onChange={(e) => setEngineName(e.target.value)}
Expand All @@ -151,7 +162,7 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
status: engineNameStatus,
title: i18n.translate(
'xpack.enterpriseSearch.content.engines.createEngine.nameEngine.title',
{ defaultMessage: 'Name your engine' }
{ defaultMessage: 'Name your Search Application' }
),
},
]}
Expand All @@ -160,29 +171,31 @@ export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => {
<EuiFlyoutFooter>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
<EuiButtonEmptyTo
disabled={formDisabled}
data-telemetry-id="entSearchContent-engines-createEngine-cancel"
onClick={onClose}
to={ENGINES_PATH}
>
{CANCEL_BUTTON_LABEL}
</EuiButtonEmpty>
</EuiButtonEmptyTo>
</EuiFlexItem>
<EuiFlexItem />
<EuiFlexItem grow={false}>
<EuiButton
disabled={createDisabled || formDisabled}
<EuiButtonTo
isDisabled={createDisabled || formDisabled}
data-telemetry-id="entSearchContent-engines-createEngine-submit"
fill
iconType="plusInCircle"
onClick={() => {
createEngine();
}}
to={ENGINES_PATH}
>
{i18n.translate('xpack.enterpriseSearch.content.engines.createEngine.submit', {
defaultMessage: 'Create this engine',
defaultMessage: 'Create this Search Application',
})}
</EuiButton>
</EuiButtonTo>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlyoutFooter>
Expand Down
Loading