-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Change pipeline selector dropdown to selection list #172330
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
05c11c9
Added pipeline select
Mikep86 8c1b2e7
Pipeline select option formatting
Mikep86 146f747
Added onChange logic
Mikep86 917f5f6
Use selection list to select existing pipeline
Mikep86 c40cca2
Make selection list searchable
Mikep86 4f396c9
Make selection list scrollable
Mikep86 09bf53b
Handle disabled pipelines
Mikep86 e73163e
Re-select the same existing pipeline when returning to the configure …
Mikep86 24471a2
Use correct initial tab when returning to the configure step
Mikep86 0bd4890
Remove selection list scrolling
Mikep86 d961636
Show selection icons
Mikep86 f264f2e
Fix PipelineSelectOption rendering on mobile
Mikep86 733b33a
Fixed PipelineSelectOption tests
Mikep86 01a27f1
Model ID & type badge flex group adjustments
Mikep86 00fd082
Remove TODOs and commented out code
Mikep86 3a71a5e
String length check update
Mikep86 7199e64
Removed unused translations
Mikep86 b49359c
Merge branch 'main' into pipeline-selection-list
Mikep86 1c1fbc8
Remove redundant existingPipeline checks
Mikep86 f122406
Pipeline name formatting
Mikep86 54700a3
Merge branch 'main' into pipeline-selection-list
Mikep86 4faf915
Merge branch 'main' into pipeline-selection-list
Mikep86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
79 changes: 79 additions & 0 deletions
79
...erprise_search_content/components/search_index/pipelines/ml_inference/pipeline_select.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,79 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { useActions, useValues } from 'kea'; | ||
|
||
import { EuiSelectable, useIsWithinMaxBreakpoint } from '@elastic/eui'; | ||
|
||
import { MLInferenceLogic, MLInferencePipelineOption } from './ml_inference_logic'; | ||
import { PipelineSelectOption, PipelineSelectOptionProps } from './pipeline_select_option'; | ||
|
||
export const PipelineSelect: React.FC = () => { | ||
const { | ||
addInferencePipelineModal: { configuration }, | ||
existingInferencePipelines, | ||
} = useValues(MLInferenceLogic); | ||
const { selectExistingPipeline } = useActions(MLInferenceLogic); | ||
|
||
const { pipelineName } = configuration; | ||
|
||
const getPipelineOptions = ( | ||
pipelineOptions: MLInferencePipelineOption[] | ||
): PipelineSelectOptionProps[] => { | ||
return pipelineOptions.map((pipelineOption) => ({ | ||
checked: pipelineOption.pipelineName === pipelineName ? 'on' : undefined, | ||
disabled: pipelineOption.disabled, | ||
label: pipelineOption.pipelineName, | ||
pipeline: pipelineOption, | ||
})); | ||
}; | ||
|
||
const renderPipelineOption = (option: PipelineSelectOptionProps) => { | ||
return <PipelineSelectOption {...option} />; | ||
}; | ||
|
||
const onChange = (options: PipelineSelectOptionProps[]) => { | ||
const selectedOption = options.find((option) => option.checked === 'on'); | ||
if (selectedOption) { | ||
selectExistingPipeline(selectedOption.pipeline.pipelineName); | ||
} | ||
}; | ||
|
||
const getActiveOptionIndex = (): number | undefined => { | ||
const index = existingInferencePipelines.findIndex( | ||
(pipelineOption) => pipelineOption.pipelineName === pipelineName | ||
); | ||
|
||
return index >= 0 ? index : undefined; | ||
}; | ||
|
||
return ( | ||
<EuiSelectable | ||
options={getPipelineOptions(existingInferencePipelines)} | ||
listProps={{ | ||
activeOptionIndex: getActiveOptionIndex(), | ||
bordered: true, | ||
rowHeight: useIsWithinMaxBreakpoint('s') ? 120 : 90, | ||
showIcons: true, | ||
onFocusBadge: false, | ||
}} | ||
searchable | ||
singleSelection="always" | ||
onChange={onChange} | ||
renderOption={renderPipelineOption} | ||
> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,107 +7,70 @@ | |
|
||
import React from 'react'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTextColor, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText, EuiTextColor, EuiTitle } from '@elastic/eui'; | ||
|
||
import { MLModelTypeBadge } from '../ml_model_type_badge'; | ||
|
||
import { MLInferencePipelineOption } from './ml_inference_logic'; | ||
import { EXISTING_PIPELINE_DISABLED_MISSING_SOURCE_FIELDS, MODEL_REDACTED_VALUE } from './utils'; | ||
|
||
export interface PipelineSelectOptionProps { | ||
checked?: 'on'; | ||
disabled?: boolean; | ||
label: string; | ||
pipeline: MLInferencePipelineOption; | ||
} | ||
|
||
// TODO: Make disabledReason required and remove EXISTING_PIPELINE_DISABLED_MISSING_SOURCE_FIELDS call without args | ||
export const PipelineSelectOptionDisabled: React.FC<{ disabledReason?: string }> = ({ | ||
disabledReason, | ||
}) => { | ||
return ( | ||
<> | ||
<EuiSpacer size="xs" /> | ||
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type="warning" color="warning" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiFlexGroup alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type="warning" color="warning" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiTextColor color="warning"> | ||
{disabledReason ?? EXISTING_PIPELINE_DISABLED_MISSING_SOURCE_FIELDS} | ||
</EuiTextColor> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiTextColor color="warning"> | ||
{disabledReason ?? EXISTING_PIPELINE_DISABLED_MISSING_SOURCE_FIELDS} | ||
</EuiTextColor> | ||
</EuiFlexItem> | ||
<EuiSpacer size="xs" /> | ||
</> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
export const PipelineSelectOption: React.FC<PipelineSelectOptionProps> = ({ pipeline }) => { | ||
const modelIdDisplay = pipeline.modelId.length > 0 ? pipeline.modelId : MODEL_REDACTED_VALUE; | ||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="none"> | ||
// TODO: Add model state & pipeline info link. Make sure to check mobile rendering when doing this! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Model state & pipeline info link was originally in scope, but was removed in the interest of meeting 8.12 FF. It will be added in a follow-up PR. |
||
<EuiFlexGroup direction="column" gutterSize="xs"> | ||
<EuiFlexItem> | ||
<EuiTitle size="xxs"> | ||
<h5>{pipeline.pipelineName}</h5> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiFlexGroup gutterSize="s" alignItems="center" justifyContent="flexEnd"> | ||
<EuiFlexItem> | ||
<EuiTitle size="xs"> | ||
<h4>{pipeline.pipelineName}</h4> | ||
</EuiTitle> | ||
<EuiFlexGroup gutterSize="s" justifyContent="flexStart"> | ||
<EuiFlexItem grow={pipeline.modelType.length === 0}> | ||
<EuiText size="s">{modelIdDisplay}</EuiText> | ||
</EuiFlexItem> | ||
{pipeline.modelType.length > 0 && ( | ||
<EuiFlexItem grow={false}> | ||
<MLModelTypeBadge type={pipeline.modelType} /> | ||
<EuiFlexItem> | ||
{/* Wrap in a div to prevent the badge from growing to a whole row on mobile*/} | ||
<div> | ||
<MLModelTypeBadge type={pipeline.modelType} /> | ||
</div> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiSpacer size="m" /> | ||
<EuiFlexItem> | ||
<EuiFlexGroup gutterSize="s" alignItems="center" justifyContent="flexEnd"> | ||
<EuiFlexItem> | ||
<EuiText size="s" color="subdued"> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.pipelines.addInferencePipelineModal.steps.configure.existingPipeline.model', | ||
{ defaultMessage: 'Model' } | ||
)} | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s" color={pipeline.disabled ? 'subdued' : 'normal'}> | ||
{modelIdDisplay} | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiSpacer size="xs" /> | ||
<EuiFlexItem> | ||
<EuiFlexGroup> | ||
<EuiFlexItem style={{ minWidth: 100 }}> | ||
<EuiText size="s" color="subdued"> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.pipelines.addInferencePipelineModal.steps.configure.existingPipeline.sourceFields', | ||
{ defaultMessage: 'Source fields' } | ||
)} | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s" color={pipeline.disabled ? 'subdued' : 'normal'} textAlign="right"> | ||
{pipeline.sourceFields.join(', ')} | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{pipeline.disabled ? ( | ||
<PipelineSelectOptionDisabled disabledReason={pipeline.disabledReason} /> | ||
) : ( | ||
<EuiText size="s">{pipeline.sourceFields.join(', ')}</EuiText> | ||
)} | ||
</EuiFlexItem> | ||
<EuiSpacer size="s" /> | ||
{pipeline.disabled && ( | ||
<PipelineSelectOptionDisabled disabledReason={pipeline.disabledReason} /> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here to serve as a reminder to address this in a separate tech debt PR