-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Transforms: Fix error toasts. (#48509)
Previously, error messages were just output within the toast as raw text which could result in overflows and overall unreadable results. This update fixes it by providing a "View details" button which opens a modal with the properly formatted error message. Plain text error message up to 140 character will still be shown in the toast itself.
- Loading branch information
Showing
8 changed files
with
166 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
x-pack/legacy/plugins/transform/public/app/components/toast_notification_text.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { cleanup, render } from 'react-testing-library'; | ||
import { ToastNotificationText } from './toast_notification_text'; | ||
|
||
describe('ToastNotificationText', () => { | ||
afterEach(cleanup); | ||
|
||
test('should render the text as plain text', () => { | ||
const props = { | ||
text: 'a short text message', | ||
}; | ||
const { container } = render(<ToastNotificationText {...props} />); | ||
expect(container.textContent).toBe('a short text message'); | ||
}); | ||
|
||
test('should render the text within a modal', () => { | ||
const props = { | ||
text: | ||
'a text message that is longer than 140 characters. a text message that is longer than 140 characters. a text message that is longer than 140 characters. ', | ||
}; | ||
const { container } = render(<ToastNotificationText {...props} />); | ||
expect(container.textContent).toBe('View details'); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
x-pack/legacy/plugins/transform/public/app/components/toast_notification_text.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { FC } from 'react'; | ||
|
||
import { | ||
EuiButtonEmpty, | ||
EuiCodeBlock, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
} from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { npStart } from 'ui/new_platform'; | ||
|
||
const MAX_SIMPLE_MESSAGE_LENGTH = 140; | ||
|
||
export const ToastNotificationText: FC<{ text: any }> = ({ text }) => { | ||
if (typeof text === 'string' && text.length <= MAX_SIMPLE_MESSAGE_LENGTH) { | ||
return text; | ||
} | ||
|
||
if ( | ||
typeof text === 'object' && | ||
typeof text.message === 'string' && | ||
text.message.length <= MAX_SIMPLE_MESSAGE_LENGTH | ||
) { | ||
return text.message; | ||
} | ||
|
||
const formattedText = text.message ? text.message : JSON.stringify(text, null, 2); | ||
|
||
const openModal = () => { | ||
const modal = npStart.core.overlays.openModal( | ||
<EuiModal onClose={() => modal.close()}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle> | ||
{i18n.translate('xpack.transform.toastText.modalTitle', { | ||
defaultMessage: 'Error details', | ||
})} | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
<EuiModalBody> | ||
<EuiCodeBlock language="json" fontSize="m" paddingSize="s" isCopyable> | ||
{formattedText} | ||
</EuiCodeBlock> | ||
</EuiModalBody> | ||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={() => modal.close()}> | ||
{i18n.translate('xpack.transform.toastText.closeModalButtonText', { | ||
defaultMessage: 'Close', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<EuiButtonEmpty onClick={openModal}> | ||
{i18n.translate('xpack.transform.toastText.openModalButtonText', { | ||
defaultMessage: 'View details', | ||
})} | ||
</EuiButtonEmpty> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters