[8.8] Enterprise Search: added ignoredOptions to IndicesSelectComboBox (#157065) (#157193)

# Backport

This will backport the following commits from `main` to `8.8`:
- [Enterprise Search: added ignoredOptions to IndicesSelectComboBox
(#157065)](https://github.com/elastic/kibana/pull/157065)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Rodney
Norris","email":"rodney.norris@elastic.co"},"sourceCommit":{"committedDate":"2023-05-09T16:08:53Z","message":"Enterprise
Search: added ignoredOptions to IndicesSelectComboBox (#157065)\n\n##
Summary\r\n\r\nUpdated the IndicesSelectComboBox to take an optional
ignoredOptions\r\nprop. This prop will take a list of indice names to
ignore from the\r\nsearch results and not display as options. This is
specifically to not\r\nallow selecting indices in the Add indices flyout
that are already a\r\npart of the search application.\r\n\r\n###
Screenshots\r\n\r\n\r\nhttps://user-images.githubusercontent.com/1972968/236926701-fcae8aa9-a396-487c-b345-1a50a66d2dce.mov\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2ffc42cbf0047e2d86fd9d53cbba66f939412011","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:skip","Team:EnterpriseSearch","v8.8.0","v8.9.0"],"number":157065,"url":"https://github.com/elastic/kibana/pull/157065","mergeCommit":{"message":"Enterprise
Search: added ignoredOptions to IndicesSelectComboBox (#157065)\n\n##
Summary\r\n\r\nUpdated the IndicesSelectComboBox to take an optional
ignoredOptions\r\nprop. This prop will take a list of indice names to
ignore from the\r\nsearch results and not display as options. This is
specifically to not\r\nallow selecting indices in the Add indices flyout
that are already a\r\npart of the search application.\r\n\r\n###
Screenshots\r\n\r\n\r\nhttps://user-images.githubusercontent.com/1972968/236926701-fcae8aa9-a396-487c-b345-1a50a66d2dce.mov\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2ffc42cbf0047e2d86fd9d53cbba66f939412011"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157065","number":157065,"mergeCommit":{"message":"Enterprise
Search: added ignoredOptions to IndicesSelectComboBox (#157065)\n\n##
Summary\r\n\r\nUpdated the IndicesSelectComboBox to take an optional
ignoredOptions\r\nprop. This prop will take a list of indice names to
ignore from the\r\nsearch results and not display as options. This is
specifically to not\r\nallow selecting indices in the Add indices flyout
that are already a\r\npart of the search application.\r\n\r\n###
Screenshots\r\n\r\n\r\nhttps://user-images.githubusercontent.com/1972968/236926701-fcae8aa9-a396-487c-b345-1a50a66d2dce.mov\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2ffc42cbf0047e2d86fd9d53cbba66f939412011"}}]}]
BACKPORT-->

Co-authored-by: Rodney Norris <rodney.norris@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-09 13:56:37 -04:00 committed by GitHub
parent 280ddc44ed
commit bf92473415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -36,15 +36,19 @@ import {
} from '../engines/components/indices_select_combobox';
import { AddIndicesLogic } from './add_indices_logic';
import { EngineViewLogic } from './engine_view_logic';
export interface AddIndicesFlyoutProps {
onClose: () => void;
}
export const AddIndicesFlyout: React.FC<AddIndicesFlyoutProps> = ({ onClose }) => {
const { engineData } = useValues(EngineViewLogic);
const { selectedIndices, updateEngineStatus, updateEngineError } = useValues(AddIndicesLogic);
const { setSelectedIndices, submitSelectedIndices } = useActions(AddIndicesLogic);
const existingIndices = engineData?.indices?.map((index) => index.name);
const selectedOptions = useMemo(
() => selectedIndices.map((index) => indexToOption(index)),
[selectedIndices]
@ -96,6 +100,7 @@ export const AddIndicesFlyout: React.FC<AddIndicesFlyoutProps> = ({ onClose }) =
fullWidth
onChange={onIndicesChange}
selectedOptions={selectedOptions}
ignoredOptions={existingIndices}
/>
</EuiFormRow>
</EuiFlyoutBody>

View file

@ -35,9 +35,10 @@ export type IndicesSelectComboBoxProps = Omit<
'onCreateOption' | 'onSearchChange' | 'noSuggestions' | 'async'
> & {
'data-telemetry-id'?: string;
ignoredOptions?: string[];
};
export const IndicesSelectComboBox = (props: IndicesSelectComboBoxProps) => {
export const IndicesSelectComboBox = ({ ignoredOptions, ...props }: IndicesSelectComboBoxProps) => {
const [searchQuery, setSearchQuery] = useState<string | undefined>(undefined);
const { makeRequest } = useActions(FetchIndicesForEnginesAPILogic);
const { status, data } = useValues(FetchIndicesForEnginesAPILogic);
@ -47,7 +48,11 @@ export const IndicesSelectComboBox = (props: IndicesSelectComboBoxProps) => {
}, [searchQuery]);
const options: Array<EuiComboBoxOptionOption<ElasticsearchIndexWithIngestion>> =
data?.indices?.map((index) => indexToOption(index.name, index)) ?? [];
(ignoredOptions && ignoredOptions.length > 0
? data?.indices
?.filter((index) => !ignoredOptions.includes(index.name))
?.map((index) => indexToOption(index.name, index))
: data?.indices?.map((index) => indexToOption(index.name, index))) ?? [];
const renderOption = (option: EuiComboBoxOptionOption<ElasticsearchIndexWithIngestion>) => (
<EuiFlexGroup>