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

[Workplace Search] Fix bug where error was behind modal stuck in loading state #104360

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 @@ -325,10 +325,11 @@ describe('SchemaLogic', () => {
});

it('handles duplicate', () => {
const onSchemaSetFormErrorsSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetFormErrors');
SchemaLogic.actions.onInitializeSchema(serverResponse);
SchemaLogic.actions.addNewField('foo', SchemaType.Number);

expect(setErrorMessage).toHaveBeenCalledWith('New field already exists: foo.');
expect(onSchemaSetFormErrorsSpy).toHaveBeenCalledWith(['New field already exists: foo.']);
});
});

Expand Down Expand Up @@ -393,8 +394,10 @@ describe('SchemaLogic', () => {

it('handles error with message', async () => {
const onSchemaSetFormErrorsSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetFormErrors');
// We expect body.message to be a string[] when it is present
http.post.mockReturnValue(Promise.reject({ body: { message: ['this is an error'] } }));
// We expect body.attributes.errors to be a string[] when it is present
http.post.mockReturnValue(
Promise.reject({ body: { attributes: { errors: ['this is an error'] } } })
);
SchemaLogic.actions.setServerField(schema, ADD);
await nextTick();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
addNewField: ({ fieldName, newFieldType }) => {
if (fieldName in values.activeSchema) {
window.scrollTo(0, 0);
setErrorMessage(
actions.onSchemaSetFormErrors([
i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.newFieldExists.message',
{
defaultMessage: 'New field already exists: {fieldName}.',
values: { fieldName },
}
)
);
),
]);
} else {
const schema = cloneDeep(values.activeSchema);
schema[fieldName] = newFieldType;
Expand Down Expand Up @@ -350,8 +350,8 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
} catch (e) {
window.scrollTo(0, 0);
if (isAdding) {
// We expect body.message to be a string[] for actions.onSchemaSetFormErrors
const message: string[] = e?.body?.message || [defaultErrorMessage];
// We expect body.attributes.errors to be a string[] for actions.onSchemaSetFormErrors
const message: string[] = e?.body?.attributes?.errors || [defaultErrorMessage];
actions.onSchemaSetFormErrors(message);
} else {
flashAPIErrors(e);
Expand Down