Skip to content

Commit 874882e

Browse files
[Workplace Search] Fix bug where error was behind modal stuck in loading state (#104360)
* Fix an issue from previous PR In #104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array. * Use inline error for duplicate name
1 parent 5baff65 commit 874882e

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,11 @@ describe('SchemaLogic', () => {
325325
});
326326

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

331-
expect(setErrorMessage).toHaveBeenCalledWith('New field already exists: foo.');
332+
expect(onSchemaSetFormErrorsSpy).toHaveBeenCalledWith(['New field already exists: foo.']);
332333
});
333334
});
334335

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

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

x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
301301
addNewField: ({ fieldName, newFieldType }) => {
302302
if (fieldName in values.activeSchema) {
303303
window.scrollTo(0, 0);
304-
setErrorMessage(
304+
actions.onSchemaSetFormErrors([
305305
i18n.translate(
306306
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.newFieldExists.message',
307307
{
308308
defaultMessage: 'New field already exists: {fieldName}.',
309309
values: { fieldName },
310310
}
311-
)
312-
);
311+
),
312+
]);
313313
} else {
314314
const schema = cloneDeep(values.activeSchema);
315315
schema[fieldName] = newFieldType;
@@ -350,8 +350,8 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
350350
} catch (e) {
351351
window.scrollTo(0, 0);
352352
if (isAdding) {
353-
// We expect body.message to be a string[] for actions.onSchemaSetFormErrors
354-
const message: string[] = e?.body?.message || [defaultErrorMessage];
353+
// We expect body.attributes.errors to be a string[] for actions.onSchemaSetFormErrors
354+
const message: string[] = e?.body?.attributes?.errors || [defaultErrorMessage];
355355
actions.onSchemaSetFormErrors(message);
356356
} else {
357357
flashAPIErrors(e);

0 commit comments

Comments
 (0)