-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fix] [Synonyms UI] Fix infinite loading when permissions missing #211530
Changes from 1 commit
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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiEmptyPrompt } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
export const ErrorPrompt = () => { | ||
return ( | ||
<EuiEmptyPrompt | ||
iconType="logoEnterpriseSearch" | ||
title={ | ||
<h2> | ||
<FormattedMessage | ||
id="xpack.search.synonyms.errorTitle" | ||
defaultMessage="An error occurred" | ||
/> | ||
</h2> | ||
} | ||
body={ | ||
<p> | ||
<FormattedMessage | ||
id="xpack.search.synonyms.errorDescription" | ||
defaultMessage="An error occured while fetching synonyms. Check Kibana logs for more information." | ||
/> | ||
</p> | ||
} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiEmptyPrompt } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
export const MissingPermissionsPrompt = () => { | ||
return ( | ||
<EuiEmptyPrompt | ||
iconType="logoEnterpriseSearch" | ||
title={ | ||
<h2> | ||
<FormattedMessage | ||
id="xpack.search.synonyms.missingPermissionsTitle" | ||
defaultMessage="Missing permissions" | ||
/> | ||
</h2> | ||
} | ||
body={ | ||
<p> | ||
<FormattedMessage | ||
id="xpack.search.synonyms.missingPermissionsDescription" | ||
defaultMessage="You do not have the necessary permissions to manage synonyms. Contact your system administrator." | ||
/> | ||
</p> | ||
} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,14 @@ import { SynonymSets } from '../synonym_sets/synonym_sets'; | |
import { useFetchSynonymsSets } from '../../hooks/use_fetch_synonyms_sets'; | ||
import { EmptyPrompt } from '../empty_prompt/empty_prompt'; | ||
import { CreateSynonymsSetModal } from '../synonym_sets/create_new_set_modal'; | ||
import { MissingPermissionsPrompt } from '../missing_permissions/missing_permissions'; | ||
import { ErrorPrompt } from '../error_prompt/error_prompt'; | ||
|
||
export const SearchSynonymsOverview = () => { | ||
const { | ||
services: { console: consolePlugin, history, searchNavigation }, | ||
} = useKibana(); | ||
const { data: synonymsData, isInitialLoading } = useFetchSynonymsSets(); | ||
const { data: synonymsData, isInitialLoading, isError, error } = useFetchSynonymsSets(); | ||
const [isCreateModalVisible, setIsCreateModalVisible] = useState(false); | ||
|
||
const embeddableConsole = useMemo( | ||
|
@@ -44,50 +46,52 @@ export const SearchSynonymsOverview = () => { | |
solutionNav={searchNavigation?.useClassicNavigation(history)} | ||
color="primary" | ||
> | ||
<KibanaPageTemplate.Header | ||
pageTitle="Synonyms" | ||
restrictWidth | ||
color="primary" | ||
rightSideItems={[ | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLink | ||
data-test-subj="searchSynonymsSearchSynonymsOverviewApiDocumentationLink" | ||
external | ||
target="_blank" | ||
href={docLinks.synonymsApi} | ||
> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.documentationLink" | ||
defaultMessage="API Documentation" | ||
/> | ||
</EuiLink> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
data-test-subj="searchSynonymsSearchSynonymsOverviewCreateButton" | ||
fill | ||
iconType="plusInCircle" | ||
onClick={() => { | ||
setIsCreateModalVisible(true); | ||
}} | ||
> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.createButton" | ||
defaultMessage="Create" | ||
/> | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup>, | ||
]} | ||
> | ||
<EuiText> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.description" | ||
defaultMessage="Create and manage synonym sets and synonym rules." | ||
/> | ||
</EuiText> | ||
</KibanaPageTemplate.Header> | ||
{synonymsData && !isInitialLoading && !isError && ( | ||
<KibanaPageTemplate.Header | ||
pageTitle="Synonyms" | ||
restrictWidth | ||
color="primary" | ||
rightSideItems={[ | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLink | ||
data-test-subj="searchSynonymsSearchSynonymsOverviewApiDocumentationLink" | ||
external | ||
target="_blank" | ||
href={docLinks.synonymsApi} | ||
> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.documentationLink" | ||
defaultMessage="API Documentation" | ||
/> | ||
</EuiLink> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
data-test-subj="searchSynonymsSearchSynonymsOverviewCreateButton" | ||
fill | ||
iconType="plusInCircle" | ||
onClick={() => { | ||
setIsCreateModalVisible(true); | ||
}} | ||
> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.createButton" | ||
defaultMessage="Create" | ||
/> | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup>, | ||
]} | ||
> | ||
<EuiText> | ||
<FormattedMessage | ||
id="xpack.searchSynonyms.synonymsSetDetail.description" | ||
defaultMessage="Create and manage synonym sets and synonym rules." | ||
/> | ||
</EuiText> | ||
</KibanaPageTemplate.Header> | ||
)} | ||
<KibanaPageTemplate.Section restrictWidth> | ||
{isCreateModalVisible && ( | ||
<CreateSynonymsSetModal | ||
|
@@ -97,6 +101,8 @@ export const SearchSynonymsOverview = () => { | |
/> | ||
)} | ||
{isInitialLoading && <EuiLoadingSpinner />} | ||
{isError && error.body.statusCode === 403 && <MissingPermissionsPrompt />} | ||
{isError && error.body.statusCode !== 403 && <ErrorPrompt />} | ||
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. nitpick: Rather than having two same component with different name 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. Also, Is it possible to add some add tests for these scenarios? |
||
|
||
{!isInitialLoading && synonymsData && synonymsData._meta.totalItemCount > 0 && ( | ||
<SynonymSets /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
*/ | ||
|
||
import { EuiComboBoxOptionOption } from '@elastic/eui'; | ||
import { KibanaServerError } from '@kbn/kibana-utils-plugin/common'; | ||
|
||
export const isExplicitSynonym = (synonym: string) => { | ||
return synonym.trim().includes('=>'); | ||
|
@@ -41,3 +42,7 @@ export const synonymsOptionToString = ({ | |
`${fromTerms.map((s) => s.label).join(',')}${ | ||
isExplicit ? ' => ' + toTerms.map((s) => s.label).join(',') : '' | ||
}`; | ||
|
||
export const isPermissionError = (error: { body: KibanaServerError }) => { | ||
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. is this function being used anywhere? 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. It's used in |
||
return error.body.statusCode === 403; | ||
}; |
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.
I think we're migrating away from this logo, so we may want to use
logoElasticsearch
instead.