forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Deangularization context error message refactoring (elasti…
…c#70090) Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
0ce23d5
commit 1be87e8
Showing
6 changed files
with
171 additions
and
38 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
54 changes: 54 additions & 0 deletions
54
...scover/public/application/components/context_error_message/context_error_message.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,54 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { ReactWrapper } from 'enzyme'; | ||
import { ContextErrorMessage } from './context_error_message'; | ||
// @ts-ignore | ||
import { FAILURE_REASONS, LOADING_STATUS } from '../../angular/context/query'; | ||
// @ts-ignore | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
|
||
describe('loading spinner', function () { | ||
let component: ReactWrapper; | ||
|
||
it('ContextErrorMessage does not render on loading', () => { | ||
component = mountWithIntl(<ContextErrorMessage status={LOADING_STATUS.LOADING} />); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(0); | ||
}); | ||
|
||
it('ContextErrorMessage does not render on success loading', () => { | ||
component = mountWithIntl(<ContextErrorMessage status={LOADING_STATUS.LOADED} />); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(0); | ||
}); | ||
|
||
it('ContextErrorMessage renders just the title if the reason is not specifically handled', () => { | ||
component = mountWithIntl(<ContextErrorMessage status={LOADING_STATUS.FAILED} />); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').text()).toBe(''); | ||
}); | ||
|
||
it('ContextErrorMessage renders the reason for unknown errors', () => { | ||
component = mountWithIntl( | ||
<ContextErrorMessage status={LOADING_STATUS.FAILED} reason={FAILURE_REASONS.UNKNOWN} /> | ||
); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').length).toBe(1); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
...ns/discover/public/application/components/context_error_message/context_error_message.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,64 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { EuiCallOut, EuiText } from '@elastic/eui'; | ||
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react'; | ||
// @ts-ignore | ||
import { FAILURE_REASONS, LOADING_STATUS } from '../../angular/context/query'; | ||
|
||
export interface ContextErrorMessageProps { | ||
/** | ||
* the status of the loading action | ||
*/ | ||
status: string; | ||
/** | ||
* the reason of the error | ||
*/ | ||
reason?: string; | ||
} | ||
|
||
export function ContextErrorMessage({ status, reason }: ContextErrorMessageProps) { | ||
if (status !== LOADING_STATUS.FAILED) { | ||
return null; | ||
} | ||
return ( | ||
<I18nProvider> | ||
<EuiCallOut | ||
title={ | ||
<FormattedMessage | ||
id="discover.context.failedToLoadAnchorDocumentDescription" | ||
defaultMessage="Failed to load the anchor document" | ||
/> | ||
} | ||
color="danger" | ||
iconType="alert" | ||
data-test-subj="contextErrorMessageTitle" | ||
> | ||
<EuiText data-test-subj="contextErrorMessageBody"> | ||
{reason === FAILURE_REASONS.UNKNOWN && ( | ||
<FormattedMessage | ||
id="discover.context.reloadPageDescription.reloadOrVisitTextMessage" | ||
defaultMessage="Please reload or go back to the document list to select a valid anchor document." | ||
/> | ||
)} | ||
</EuiText> | ||
</EuiCallOut> | ||
</I18nProvider> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
...er/public/application/components/context_error_message/context_error_message_directive.ts
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,26 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { ContextErrorMessage } from './context_error_message'; | ||
|
||
export function createContextErrorMessageDirective(reactDirective: any) { | ||
return reactDirective(ContextErrorMessage, [ | ||
['status', { watchDepth: 'reference' }], | ||
['reason', { watchDepth: 'reference' }], | ||
]); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/plugins/discover/public/application/components/context_error_message/index.ts
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,21 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { ContextErrorMessage } from './context_error_message'; | ||
export { createContextErrorMessageDirective } from './context_error_message_directive'; |
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