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

[8.17] Remove inference_id field if no inference endpoint is selected (#205660) #209351

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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ describe('Mappings editor: core', () => {
let getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler);
let testBed: MappingsEditorTestBed;
const appDependencies = {
core: { application: {} },
docLinks: {
links: {
inferenceManagement: {
inferenceAPIDocumentation: 'https://abc.com/inference-api-create',
},
},
},
plugins: {
ml: { mlApi: {} },
},
Expand Down Expand Up @@ -474,6 +482,40 @@ describe('Mappings editor: core', () => {
expect(data).toEqual(updatedMappings);
});

test('updates mapping without inference id for semantic_text field', async () => {
let updatedMappings = { ...defaultMappings };

const {
find,
actions: { addField },
component,
} = testBed;

/**
* Mapped fields
*/
await act(async () => {
find('addFieldButton').simulate('click');
jest.advanceTimersByTime(0); // advance timers to allow the form to validate
});
component.update();

const newField = { name: 'someNewField', type: 'semantic_text' };
await addField(newField.name, newField.type);

updatedMappings = {
...updatedMappings,
properties: {
...updatedMappings.properties,
[newField.name]: { reference_field: 'address.city', type: 'semantic_text' },
},
};

({ data } = await getMappingsEditorData(component));

expect(data).toEqual(updatedMappings);
});

describe('props.indexMode sets the correct default value of _source field', () => {
it("defaults to 'stored' with 'standard' index mode prop", async () => {
await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const CreateField = React.memo(function CreateFieldComponent({
}
};

const { createInferenceEndpoint, handleSemanticText } = useSemanticText({
const { createInferenceEndpoint } = useSemanticText({
form,
setErrorsInTrainedModelDeployment,
ml,
Expand All @@ -130,8 +130,9 @@ export const CreateField = React.memo(function CreateFieldComponent({
const { isValid, data } = await form.submit();

if (isValid && !clickOutside) {
if (isSemanticTextField(data)) {
handleSemanticText(data);
if (isSemanticTextField(data) && !data.inference_id) {
const { inference_id: inferenceId, ...rest } = data;
dispatch({ type: 'field.add', value: rest });
} else {
dispatch({ type: 'field.add', value: data });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ function FieldListItemComponent(
</EuiBadge>
</EuiFlexItem>

{isSemanticText && (
{isSemanticText && source.inference_id ? (
<EuiFlexItem grow={false}>
<EuiBadge color="hollow">{source.inference_id as string}</EuiBadge>
</EuiFlexItem>
)}
) : null}

{isShadowed && (
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ export const getAllFieldTypesFromState = (allFields: Fields): DataType[] => {
};

export function isSemanticTextField(field: Partial<Field>): field is SemanticTextField {
return Boolean(field.inference_id && field.type === 'semantic_text');
return field.type === 'semantic_text';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const DetailsPageMappingsContent: FunctionComponent<{
.map((field) => field.inference_id)
.filter(
(inferenceId: string) =>
inferenceId &&
inferenceToModelIdMap?.[inferenceId].trainedModelId && // third-party inference models don't have trainedModelId
!inferenceToModelIdMap?.[inferenceId].isDeployed &&
!isInferencePreconfigured(inferenceId)
Expand Down