-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] [Synonyms UI] Fix infinite loading when permissions missing (#2…
…11530) ## Summary Fixes infinite loading when user had missing permissions. <img width="948" alt="Screenshot 2025-02-18 at 12 24 22" src="https://github.com/user-attachments/assets/975c46ef-a729-4bec-9442-fdb38b59fe19" /> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit c0da61a)
- Loading branch information
Showing
5 changed files
with
169 additions
and
46 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
.../solutions/search/plugins/search_synonyms/public/components/error_prompt/error_prompt.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,51 @@ | ||
/* | ||
* 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'; | ||
|
||
const ERROR_MESSAGES = { | ||
generic: { | ||
title: ( | ||
<FormattedMessage id="xpack.search.synonyms.errorTitle" defaultMessage="An error occurred" /> | ||
), | ||
body: ( | ||
<FormattedMessage | ||
id="xpack.search.synonyms.errorDescription" | ||
defaultMessage="An error occured while fetching synonyms. Check Kibana logs for more information." | ||
/> | ||
), | ||
}, | ||
missingPermissions: { | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.search.synonyms.missingPermissionsTitle" | ||
defaultMessage="Missing permissions" | ||
/> | ||
), | ||
body: ( | ||
<FormattedMessage | ||
id="xpack.search.synonyms.missingPermissionsDescription" | ||
defaultMessage="You do not have the necessary permissions to manage synonyms. Contact your system administrator." | ||
/> | ||
), | ||
}, | ||
}; | ||
|
||
export const ErrorPrompt: React.FC<{ errorType: 'missingPermissions' | 'generic' }> = ({ | ||
errorType, | ||
}) => { | ||
return ( | ||
<EuiEmptyPrompt | ||
iconType="logoEnterpriseSearch" | ||
title={<h2>{ERROR_MESSAGES[errorType].title}</h2>} | ||
body={<p>{ERROR_MESSAGES[errorType].body}</p>} | ||
/> | ||
); | ||
}; |
57 changes: 57 additions & 0 deletions
57
x-pack/solutions/search/plugins/search_synonyms/public/components/overview/overview.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,57 @@ | ||
/* | ||
* 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 { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { SearchSynonymsOverview } from './overview'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
import { useFetchSynonymsSets } from '../../hooks/use_fetch_synonyms_sets'; | ||
|
||
jest.mock('../../hooks/use_fetch_synonyms_sets', () => ({ | ||
useFetchSynonymsSets: jest.fn(() => ({ | ||
data: undefined, | ||
isLoading: false, | ||
isError: true, | ||
error: { body: { statusCode: 500 } }, | ||
})), | ||
})); | ||
|
||
describe('Search Synonyms Overview', () => { | ||
const queryClient = new QueryClient(); | ||
const Wrapper = ({ children }: { children?: React.ReactNode }) => ( | ||
<I18nProvider> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
</I18nProvider> | ||
); | ||
it('should show error prompt when we get a generic error', () => { | ||
render( | ||
<Wrapper> | ||
<SearchSynonymsOverview /> | ||
</Wrapper> | ||
); | ||
|
||
expect(screen.getByText('An error occurred')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show error prompt when we get a missing permissions error', () => { | ||
(useFetchSynonymsSets as jest.Mock).mockReturnValue({ | ||
data: undefined, | ||
isLoading: false, | ||
isError: true, | ||
error: { body: { statusCode: 403 } }, | ||
}); | ||
|
||
render( | ||
<Wrapper> | ||
<SearchSynonymsOverview /> | ||
</Wrapper> | ||
); | ||
|
||
expect(screen.getByText('Missing permissions')).toBeInTheDocument(); | ||
}); | ||
}); |
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