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

Align inference pipeline card/option styling #172952

Merged
merged 15 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -11,11 +11,11 @@ import React from 'react';

import { shallow } from 'enzyme';

import { EuiButtonIcon, EuiPanel, EuiTextColor, EuiTitle } from '@elastic/eui';
import { EuiButtonEmpty, EuiPanel, EuiText, EuiTitle } from '@elastic/eui';

import { InferencePipeline, TrainedModelState } from '../../../../../../common/types/pipelines';

import { InferencePipelineCard } from './inference_pipeline_card';
import { InferencePipelineCard, TrainedModelHealthPopover } from './inference_pipeline_card';
import { MLModelTypeBadge } from './ml_model_type_badge';

export const DEFAULT_VALUES: InferencePipeline = {
Expand All @@ -40,7 +40,7 @@ describe('InferencePipelineCard', () => {
it('renders pipeline as title', () => {
const wrapper = shallow(<InferencePipelineCard {...mockValues} />);
expect(wrapper.find(EuiTitle)).toHaveLength(1);
const title = wrapper.find(EuiTitle).dive();
const title = wrapper.find(EuiTitle).at(0).children();
expect(title.text()).toBe(DEFAULT_VALUES.pipelineName);
});
it('renders pipeline as title with unknown model type', () => {
Expand All @@ -51,14 +51,14 @@ describe('InferencePipelineCard', () => {
const wrapper = shallow(<InferencePipelineCard {...values} />);
expect(wrapper.find(EuiTitle)).toHaveLength(1);
// does not render subtitle
expect(wrapper.find(EuiTextColor)).toHaveLength(0);
const title = wrapper.find(EuiTitle).dive();
expect(wrapper.find(EuiText)).toHaveLength(0);
const title = wrapper.find(EuiTitle).at(0).children();
expect(title.text()).toBe(DEFAULT_VALUES.pipelineName);
});
it('renders model ID as subtitle', () => {
const wrapper = shallow(<InferencePipelineCard {...mockValues} />);
expect(wrapper.find(EuiTextColor)).toHaveLength(1);
const subtitle = wrapper.find(EuiTextColor).dive();
expect(wrapper.find(EuiText)).toHaveLength(1);
const subtitle = wrapper.find(EuiText).at(0).children();
expect(subtitle.text()).toBe(DEFAULT_VALUES.modelId);
});
it('renders model type as badge', () => {
Expand All @@ -67,20 +67,21 @@ describe('InferencePipelineCard', () => {
const badge = wrapper.find(MLModelTypeBadge).render();
expect(badge.text()).toBe('ner');
});
it('renders fix button when model not deployed', () => {
it('popover renders fix button when model not deployed', () => {
Mikep86 marked this conversation as resolved.
Show resolved Hide resolved
const values = {
...DEFAULT_VALUES,
modelState: TrainedModelState.NotDeployed,
};
const wrapper = shallow(<InferencePipelineCard {...values} />);
expect(wrapper.find(EuiButtonIcon)).toHaveLength(1);
const wrapper = shallow(<TrainedModelHealthPopover {...values} />);
expect(wrapper.find(EuiButtonEmpty)).toHaveLength(3);

const fixButton = wrapper.find(EuiButtonIcon);
const fixButton = wrapper.find(EuiButtonEmpty).at(0);
expect(fixButton.prop('iconType')).toBe('wrench');
expect(fixButton.prop('href')).toBe('/app/ml/trained_models');
expect(fixButton.children().text()).toBe('Fix issue in Trained Models');
});
it('does not render fix button when model deployed', () => {
const wrapper = shallow(<InferencePipelineCard {...mockValues} />);
expect(wrapper.find(EuiButtonIcon)).toHaveLength(0);
it('popover does not render fix button when model deployed', () => {
const wrapper = shallow(<TrainedModelHealthPopover {...mockValues} />);
expect(wrapper.find(EuiButtonEmpty)).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import { useActions, useValues } from 'kea';

import {
EuiButtonEmpty,
EuiButtonIcon,
EuiConfirmModal,
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiPopover,
EuiText,
EuiTextColor,
EuiTitle,
EuiToolTip,
useIsWithinMaxBreakpoint,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
Expand All @@ -39,20 +37,18 @@ import { TrainedModelHealth } from './ml_model_health';
import { MLModelTypeBadge } from './ml_model_type_badge';
import { PipelinesLogic } from './pipelines_logic';

export const InferencePipelineCard: React.FC<InferencePipeline> = (pipeline) => {
export const TrainedModelHealthPopover: React.FC<InferencePipeline> = (pipeline) => {
const { http } = useValues(HttpLogic);
const { indexName } = useValues(IndexNameLogic);
const { ingestionMethod } = useValues(IndexViewLogic);

const { deleteMlPipeline, detachMlPipeline } = useActions(PipelinesLogic);

const [isPopOverOpen, setIsPopOverOpen] = useState(false);
const [showConfirmDelete, setShowConfirmDelete] = useState(false);
const { deleteMlPipeline, detachMlPipeline } = useActions(PipelinesLogic);
const showConfirmDeleteModal = () => {
setShowConfirmDelete(true);
setIsPopOverOpen(false);
};
const { modelId, pipelineName, types: modelTypes } = pipeline;
const modelType = getMLType(modelTypes);
const modelTitle = getModelDisplayTitle(modelType);

const { pipelineName } = pipeline;

const actionButton = (
<EuiButtonEmpty
Comment on lines 52 to 53
Copy link
Contributor

Choose a reason for hiding this comment

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

I see some discrepancies with the model-related subcomponents here vs in the model selection component within the pipeline configuration flyout. Let's make sure we address these in the unified ML design:

  • The status badge is part of the "..." button here. In the model selection list it's not.
  • We display a wrench button to navigate to the Trained Models page if the model is not deployed vs in the model selection list we don't.
  • The model status badge here works with the reduced set of states (implemented in TrainedModelHealth), for example the downloading/downloaded states all map to "Not started". If we want to display more fine-grained states, we'll need to use model details from MlModel in the pipeline card.
  • The model type is rendered as a badge here (text_embedding) vs a user-friendly title in the model selector ("Dense Vector Text Embedding"). (We may not have the space the display the full title here.)

I'll link to this comment in the unified UX Jira.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callouts! I could address the first point in this PR by shrinking the button to not include the status badge, but IMO it's nice to have a larger button area, especially since there's no other click action to associate with the status badge. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

To me it doesn't come intuitively that a badge is clickable. I'd either restrict clickability to the "..." button only, or turn the status badge into a (non-empty) button. But this is a good question to the UX folks, maybe they have some suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, since this an open question for the UX folks, I will keep this as-is for now and we can adjust in a follow-up PR.

iconSide="right"
Expand All @@ -67,119 +63,88 @@ export const InferencePipelineCard: React.FC<InferencePipeline> = (pipeline) =>
</EuiButtonEmpty>
);

const showConfirmDeleteModal = () => {
setShowConfirmDelete(true);
setIsPopOverOpen(false);
};

return (
<EuiPanel color="subdued">
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="xs">
<>
<EuiPopover
button={actionButton}
isOpen={isPopOverOpen}
closePopover={() => setIsPopOverOpen(false)}
>
<EuiFlexGroup direction="column" gutterSize="none">
{pipeline.modelState === TrainedModelState.NotDeployed && (
<EuiFlexItem>
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
<EuiTitle size="xs">
<h4>{pipelineName ?? modelTitle}</h4>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false} />
</EuiFlexGroup>
</EuiFlexItem>
{modelTitle && (
<EuiFlexItem>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
<EuiTextColor color="subdued">{modelId}</EuiTextColor>
</EuiFlexItem>
<EuiFlexItem>
<span>
<MLModelTypeBadge type={modelType} />
</span>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiPopover
button={actionButton}
isOpen={isPopOverOpen}
closePopover={() => setIsPopOverOpen(false)}
>
{pipeline.modelState === TrainedModelState.NotDeployed && (
<EuiFlexItem grow={false} style={{ paddingRight: '1rem' }}>
<EuiToolTip
position="top"
content={i18n.translate(
<div>
Mikep86 marked this conversation as resolved.
Show resolved Hide resolved
<EuiButtonEmpty
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-fixIssueInTrainedModels`}
size="s"
flush="both"
iconType="wrench"
color="text"
href={http.basePath.prepend(ML_MANAGE_TRAINED_MODELS_PATH)}
Mikep86 marked this conversation as resolved.
Show resolved Hide resolved
>
{i18n.translate(
'xpack.enterpriseSearch.inferencePipelineCard.modelState.notDeployed.fixLink',
{ defaultMessage: 'Fix issue in Trained Models' }
{
defaultMessage: 'Fix issue in Trained Models',
}
)}
>
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.enterpriseSearch.inferencePipelineCard.modelState.notDeployed.fixLink',
{
defaultMessage: 'Fix issue in Trained Models',
}
)}
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-fixIssueInTrainedModels`}
href={http.basePath.prepend(ML_MANAGE_TRAINED_MODELS_PATH)}
display="base"
size="xs"
iconType="wrench"
/>
</EuiToolTip>
</EuiFlexItem>
)}
<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem>
<div>
<EuiButtonEmpty
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-stackManagement`}
size="s"
flush="both"
iconType="eye"
color="text"
href={http.basePath.prepend(
`/app/management/ingest/ingest_pipelines/?pipeline=${pipelineName}`
)}
>
{i18n.translate('xpack.enterpriseSearch.inferencePipelineCard.action.view', {
defaultMessage: 'View in Stack Management',
})}
</EuiButtonEmpty>
</div>
</EuiFlexItem>
<EuiFlexItem>
<div>
<EuiButtonEmpty
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-detachPipeline`}
size="s"
flush="both"
iconType="unlink"
color="text"
onClick={() => {
detachMlPipeline({ indexName, pipelineName });
setIsPopOverOpen(false);
}}
>
{i18n.translate('xpack.enterpriseSearch.inferencePipelineCard.action.detach', {
defaultMessage: 'Detach pipeline',
})}
</EuiButtonEmpty>
</div>
</EuiFlexItem>
<EuiFlexItem>
<div>
<DeleteInferencePipelineButton
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-deletePipeline`}
onClick={showConfirmDeleteModal}
pipeline={pipeline}
/>
</div>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
</EuiButtonEmpty>
</div>
</EuiFlexItem>
)}
<EuiFlexItem>
<div>
<EuiButtonEmpty
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-stackManagement`}
size="s"
flush="both"
iconType="eye"
color="text"
href={http.basePath.prepend(
`/app/management/ingest/ingest_pipelines/?pipeline=${pipelineName}`
)}
>
{i18n.translate('xpack.enterpriseSearch.inferencePipelineCard.action.view', {
defaultMessage: 'View in Stack Management',
})}
</EuiButtonEmpty>
</div>
</EuiFlexItem>
<EuiFlexItem>
<div>
<EuiButtonEmpty
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-detachPipeline`}
size="s"
flush="both"
iconType="unlink"
color="text"
onClick={() => {
detachMlPipeline({ indexName, pipelineName });
setIsPopOverOpen(false);
}}
>
{i18n.translate('xpack.enterpriseSearch.inferencePipelineCard.action.detach', {
defaultMessage: 'Detach pipeline',
})}
</EuiButtonEmpty>
</div>
</EuiFlexItem>
<EuiFlexItem>
<div>
<DeleteInferencePipelineButton
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-inferencePipeline-deletePipeline`}
onClick={showConfirmDeleteModal}
pipeline={pipeline}
/>
</div>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPopover>

{showConfirmDelete && (
<EuiConfirmModal
Expand Down Expand Up @@ -217,6 +182,49 @@ export const InferencePipelineCard: React.FC<InferencePipeline> = (pipeline) =>
</EuiText>
</EuiConfirmModal>
)}
</>
);
};

export const InferencePipelineCard: React.FC<InferencePipeline> = (pipeline) => {
const { modelId, pipelineName, types: modelTypes } = pipeline;
const modelType = getMLType(modelTypes);
const modelTitle = getModelDisplayTitle(modelType);
const isSmallScreen = useIsWithinMaxBreakpoint('s');

// TODO: Handle redacted model ID
Mikep86 marked this conversation as resolved.
Show resolved Hide resolved
return (
<EuiPanel color="subdued">
<EuiFlexGroup alignItems="center" gutterSize={isSmallScreen ? 'xs' : undefined}>
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="xs">
<EuiFlexItem>
<EuiTitle size="xs">
<h4>{pipelineName ?? modelTitle}</h4>
</EuiTitle>
</EuiFlexItem>
{modelTitle && (
<EuiFlexItem>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
<EuiText size="s" color="subdued">
{modelId}
</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<span>
<MLModelTypeBadge type={modelType} />
</span>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<TrainedModelHealthPopover {...pipeline} />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ export const PipelineSelectOption: React.FC<PipelineSelectOptionProps> = ({ pipe
// TODO: Add model state & pipeline info link. Make sure to check mobile rendering when doing this!
<EuiFlexGroup direction="column" gutterSize="xs">
<EuiFlexItem>
<EuiTitle size="xxs">
<h5>{pipeline.pipelineName}</h5>
<EuiTitle size="xs">
<h4>{pipeline.pipelineName}</h4>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" justifyContent="flexStart">
<EuiFlexGroup gutterSize="s" justifyContent="flexStart" alignItems="center">
<EuiFlexItem grow={pipeline.modelType.length === 0}>
<EuiText size="s">{modelIdDisplay}</EuiText>
</EuiFlexItem>
{pipeline.modelType.length > 0 && (
<EuiFlexItem>
{/* Wrap in a div to prevent the badge from growing to a whole row on mobile*/}
<div>
{/* Wrap in a span to prevent the badge from growing to a whole row on mobile*/}
<span>
<MLModelTypeBadge type={pipeline.modelType} />
</div>
</span>
</EuiFlexItem>
)}
</EuiFlexGroup>
Expand Down