-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index subset selection to setup process
- Loading branch information
1 parent
b8647ae
commit f3aa009
Showing
11 changed files
with
309 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
x-pack/legacy/plugins/infra/public/pages/logs/analysis/setup/analysis_setup_indices_form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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, { useMemo, useCallback } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { EuiCode, EuiDescribedFormGroup, EuiFormRow, EuiCheckboxGroup } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
const indicesSelectionLabel = i18n.translate('xpack.infra.analysisSetup.indicesSelectionLabel', { | ||
defaultMessage: 'Indices', | ||
}); | ||
|
||
type IndicesSelection = Record<string, boolean>; | ||
|
||
export const AnalysisSetupIndicesForm: React.FunctionComponent<{ | ||
indices: IndicesSelection; | ||
onChangeSelectedIndices: (selectedIndices: IndicesSelection) => void; | ||
validationErrors?: Array<'TOO_FEW_SELECTED_INDICES'>; | ||
}> = ({ indices, onChangeSelectedIndices, validationErrors = [] }) => { | ||
const choices = useMemo( | ||
() => | ||
Object.keys(indices).map(indexName => ({ | ||
id: indexName, | ||
label: <EuiCode>{indexName}</EuiCode>, | ||
})), | ||
[indices] | ||
); | ||
|
||
const handleCheckboxGroupChange = useCallback( | ||
indexName => { | ||
onChangeSelectedIndices({ | ||
...indices, | ||
[indexName]: !indices[indexName], | ||
}); | ||
}, | ||
[indices, onChangeSelectedIndices] | ||
); | ||
|
||
return ( | ||
<EuiDescribedFormGroup | ||
idAria="indices" | ||
title={ | ||
<FormattedMessage | ||
id="xpack.infra.analysisSetup.indicesSelectionTitle" | ||
defaultMessage="Choose indices" | ||
/> | ||
} | ||
description={ | ||
<FormattedMessage | ||
id="xpack.infra.analysisSetup.indicesSelectionDescription" | ||
defaultMessage="By default, Machine Learning analyzes log messages in all log indices configured for the source. You can choose to only analyse a subset of the index names. Every selected index name must match at least one index with log entries." | ||
/> | ||
} | ||
> | ||
<EuiFormRow | ||
describedByIds={['indices']} | ||
error={validationErrors.map(formatValidationError)} | ||
fullWidth | ||
isInvalid={validationErrors.length > 0} | ||
label={indicesSelectionLabel} | ||
labelType="legend" | ||
> | ||
<EuiCheckboxGroup | ||
options={choices} | ||
idToSelectedMap={indices} | ||
onChange={handleCheckboxGroupChange} | ||
/> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
); | ||
}; | ||
|
||
const formatValidationError = (validationError: 'TOO_FEW_SELECTED_INDICES') => { | ||
switch (validationError) { | ||
case 'TOO_FEW_SELECTED_INDICES': | ||
return i18n.translate( | ||
'xpack.infra.analysisSetup.indicesSelectionTooFewSelectedIndicesDescription', | ||
{ | ||
defaultMessage: 'Select at least one index name.', | ||
} | ||
); | ||
} | ||
}; |
Oops, something went wrong.