-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Discover] Deangularization context error message refactoring #70090
Changes from 5 commits
b9f41cd
8258199
f8fc8f1
41fb803
27635ce
4913423
4668008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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} | ||
queryParameters={{ indexPatternId: 'index-pattern-id' }} | ||
/> | ||
); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(0); | ||
}); | ||
|
||
it('ContextErrorMessage does not render on success loading', () => { | ||
component = mountWithIntl( | ||
<ContextErrorMessage | ||
status={LOADING_STATUS.LOADED} | ||
queryParameters={{ indexPatternId: 'index-pattern-id' }} | ||
/> | ||
); | ||
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} | ||
queryParameters={{ indexPatternId: 'index-pattern-id' }} | ||
/> | ||
); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').text()).toBe(''); | ||
}); | ||
|
||
it('ContextErrorMessage renders the reason for tiebreaker errors', () => { | ||
component = mountWithIntl( | ||
<ContextErrorMessage | ||
status={LOADING_STATUS.FAILED} | ||
reason={FAILURE_REASONS.INVALID_TIEBREAKER} | ||
queryParameters={{ indexPatternId: 'index-pattern-id' }} | ||
/> | ||
); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').text()).toMatch( | ||
'index-pattern-id' | ||
); | ||
}); | ||
|
||
it('ContextErrorMessage renders the reason for unknown errors', () => { | ||
component = mountWithIntl( | ||
<ContextErrorMessage | ||
status={LOADING_STATUS.FAILED} | ||
reason={FAILURE_REASONS.UNKNOWN} | ||
queryParameters={{ indexPatternId: 'index-pattern-id' }} | ||
/> | ||
); | ||
expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').length).toBe(1); | ||
expect(findTestSubject(component, 'contextErrorMessageBody').text()).not.toMatch( | ||
'index-pattern-id' | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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; | ||
/** | ||
* parameters used for invalid tieBreakerFields realted errors | ||
*/ | ||
queryParameters: { indexPatternId: string }; | ||
} | ||
|
||
export function ContextErrorMessage({ status, reason, queryParameters }: 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.INVALID_TIEBREAKER && ( | ||
<FormattedMessage | ||
id="discover.context.noSearchableTiebreakerFieldDescription" | ||
defaultMessage="No searchable tiebreaker field could be found in the index pattern {indexPatternId}. Please change the advanced setting {tieBreakerFields} to include a valid field for this index pattern." | ||
values={{ | ||
indexPatternId: queryParameters.indexPatternId, | ||
tieBreakerFields: <code>context:tieBreakerFields</code>, | ||
}} | ||
/> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this error message is redundant, legacy, might have been useful in recent time. I tried to set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried some ideas but didn't work. I'll remove it. |
||
{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> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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' }], | ||
['queryParameters', { watchDepth: 'reference' }], | ||
]); | ||
} |
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "realted" sounds bit like Spanish ⚽, I think it's "related"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the removal of the error above I guess I can remove also this prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pls clean up dead code, thx