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] Add navigation to license if URL is configured #172404

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion x-pack/plugins/enterprise_search/common/types/ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface MlModel {
type: string;
title: string;
description?: string;
license?: string;
licenseType?: string;
licensePageUrl?: string;
modelDetailsPageUrl?: string;
deploymentState: MlModelDeploymentState;
deploymentStateReason?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import React from 'react';

import { shallow } from 'enzyme';

import { EuiBadge, EuiText } from '@elastic/eui';
import { EuiLink, EuiText } from '@elastic/eui';

import { MlModelDeploymentState } from '../../../../../../../common/types/ml';
import { TrainedModelHealth } from '../ml_model_health';

import {
DeployModelButton,
getContextMenuPanel,
LicenseBadge,
ModelSelectOption,
ModelSelectOptionProps,
StartModelButton,
Expand All @@ -30,7 +31,8 @@ const DEFAULT_PROPS: ModelSelectOptionProps = {
label: 'Model 1',
title: 'Model 1',
description: 'Model 1 description',
license: 'elastic',
licenseType: 'elastic',
licensePageUrl: 'https://licen.se',
deploymentState: MlModelDeploymentState.NotDeployed,
startTime: 0,
targetAllocationCount: 0,
Expand All @@ -47,16 +49,16 @@ describe('ModelSelectOption', () => {
});
it('renders with license badge if present', () => {
const wrapper = shallow(<ModelSelectOption {...DEFAULT_PROPS} />);
expect(wrapper.find(EuiBadge)).toHaveLength(1);
expect(wrapper.find(LicenseBadge)).toHaveLength(1);
});
it('renders without license badge if not present', () => {
const props = {
...DEFAULT_PROPS,
license: undefined,
licenseType: undefined,
};

const wrapper = shallow(<ModelSelectOption {...props} />);
expect(wrapper.find(EuiBadge)).toHaveLength(0);
expect(wrapper.find(LicenseBadge)).toHaveLength(0);
});
it('renders with description if present', () => {
const wrapper = shallow(<ModelSelectOption {...DEFAULT_PROPS} />);
Expand Down Expand Up @@ -93,11 +95,27 @@ describe('ModelSelectOption', () => {
const wrapper = shallow(<ModelSelectOption {...DEFAULT_PROPS} />);
expect(wrapper.find(TrainedModelHealth)).toHaveLength(1);
});
});

describe('LicenseBadge', () => {
it('renders with link if URL is present', () => {
const wrapper = shallow(
<LicenseBadge
licenseType={DEFAULT_PROPS.licenseType!}
licensePageUrl={DEFAULT_PROPS.licensePageUrl}
/>
);
expect(wrapper.find(EuiLink)).toHaveLength(1);
});
it('renders without link if URL is not present', () => {
const wrapper = shallow(<LicenseBadge licenseType={DEFAULT_PROPS.licenseType!} />);
expect(wrapper.find(EuiLink)).toHaveLength(0);
});
});

describe('getContextMenuPanel', () => {
it('gets model details link if URL is present', () => {
const panels = getContextMenuPanel('https://model.ai');
expect(panels[0].items).toHaveLength(2);
});
describe('getContextMenuPanel', () => {
it('gets model details link if URL is present', () => {
const panels = getContextMenuPanel('https://model.ai');
expect(panels[0].items).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiContextMenuPanelDescriptor,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
EuiPopover,
EuiRadio,
EuiText,
Expand Down Expand Up @@ -142,11 +143,41 @@ export const ModelMenuPopover: React.FC<{
);
};

export interface LicenseBadgeProps {
licenseType: string;
licensePageUrl?: string;
}

export const LicenseBadge: React.FC<LicenseBadgeProps> = ({ licenseType, licensePageUrl }) => {
const licenseLabel = i18n.translate(
'xpack.enterpriseSearch.content.indices.pipelines.modelSelectOption.licenseBadge.label',
{
defaultMessage: 'License: {licenseType}',
values: {
licenseType,
},
}
);

return (
<EuiBadge color="hollow">
{licensePageUrl ? (
<EuiLink target="_blank" href={licensePageUrl}>
{licenseLabel}
</EuiLink>
) : (
<p>{licenseLabel}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you add this <p>? I'm not sure I've see this before, I have had to wrap <EuiBadge> with a <span> to ensure they dont grow in certain scenarios and wondering if this <p> solves that instead.

Copy link
Contributor Author

@demjened demjened Dec 1, 2023

Choose a reason for hiding this comment

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

@TattdCodeMonkey {licenseLabel} by itself got recognized and reformatted as an object ({ licenseLabel }), and I used <p> a workaround. Is there an easier way, e.g. <>?

)}
</EuiBadge>
);
};

export const ModelSelectOption: React.FC<ModelSelectOptionProps> = ({
modelId,
title,
description,
license,
licenseType,
licensePageUrl,
deploymentState,
deploymentStateReason,
modelDetailsPageUrl,
Expand Down Expand Up @@ -184,24 +215,14 @@ export const ModelSelectOption: React.FC<ModelSelectOptionProps> = ({
<EuiFlexItem>
<EuiTextColor color="subdued">{modelId}</EuiTextColor>
</EuiFlexItem>
{(license || description) && (
{(licenseType || description) && (
<EuiFlexItem>
<EuiFlexGroup gutterSize="xs" alignItems="center">
{license && (
{licenseType && (
<EuiFlexItem grow={false}>
{/* Wrap in a div to prevent the badge from growing to a whole row on mobile */}
<div>
<EuiBadge color="hollow">
{i18n.translate(
'xpack.enterpriseSearch.content.indices.pipelines.modelSelectOption.licenseBadge.label',
{
defaultMessage: 'License: {license}',
values: {
license,
},
}
)}
</EuiBadge>
<LicenseBadge licenseType={licenseType} licensePageUrl={licensePageUrl} />
</div>
</EuiFlexItem>
)}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/enterprise_search/server/lib/ml/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export const E5_MODEL_PLACEHOLDER: MlModel = {
defaultMessage:
'E5 is an NLP model that enables you to perform multi-lingual semantic search by using dense vector representations. This model performs best for non-English language documents and queries.',
}),
license: 'MIT',
licenseType: 'mit',
licensePageUrl: 'https://huggingface.co/elastic/multilingual-e5-small-optimized',
modelDetailsPageUrl: 'https://huggingface.co/intfloat/multilingual-e5-small',
isPlaceholder: true,
};
Loading