forked from opensearch-project/OpenSearch-Dashboards
-
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.
Showing
10 changed files
with
507 additions
and
5 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
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
"savedObjects" | ||
], | ||
"optionalPlugins": [], | ||
"requiredBundles": [] | ||
"requiredBundles": ["opensearchDashboardsReact"] | ||
} |
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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AppMountParameters, ScopedHistory } from '../../../core/public'; | ||
import { OpenSearchDashboardsContextProvider } from '../../opensearch_dashboards_react/public'; | ||
import { WorkspaceFatalError } from './components/workspace_fatal_error'; | ||
import { Services } from './types'; | ||
|
||
export const renderFatalErrorApp = (params: AppMountParameters, services: Services) => { | ||
const { element } = params; | ||
const history = params.history as ScopedHistory<{ error?: string }>; | ||
ReactDOM.render( | ||
<OpenSearchDashboardsContextProvider services={services}> | ||
<WorkspaceFatalError error={history.location.state.error} /> | ||
</OpenSearchDashboardsContextProvider>, | ||
element | ||
); | ||
|
||
return () => { | ||
ReactDOM.unmountComponentAtNode(element); | ||
}; | ||
}; |
180 changes: 180 additions & 0 deletions
180
...public/components/workspace_fatal_error/__snapshots__/workspace_fatal_error.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/plugins/workspace/public/components/workspace_fatal_error/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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { WorkspaceFatalError } from './workspace_fatal_error'; |
71 changes: 71 additions & 0 deletions
71
src/plugins/workspace/public/components/workspace_fatal_error/workspace_fatal_error.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,71 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { WorkspaceFatalError } from './workspace_fatal_error'; | ||
import { context } from '../../../../opensearch_dashboards_react/public'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
|
||
describe('<WorkspaceFatalError />', () => { | ||
it('render normally', async () => { | ||
const { findByText, container } = render( | ||
<IntlProvider locale="en"> | ||
<WorkspaceFatalError /> | ||
</IntlProvider> | ||
); | ||
await findByText('Something went wrong'); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('render error with callout', async () => { | ||
const { findByText, container } = render( | ||
<IntlProvider locale="en"> | ||
<WorkspaceFatalError error="errorInCallout" /> | ||
</IntlProvider> | ||
); | ||
await findByText('errorInCallout'); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('click go back to home', async () => { | ||
const { location } = window; | ||
const setHrefSpy = jest.fn((href) => href); | ||
if (window.location) { | ||
// @ts-ignore | ||
delete window.location; | ||
} | ||
window.location = {} as Location; | ||
Object.defineProperty(window.location, 'href', { | ||
get: () => 'http://localhost/', | ||
set: setHrefSpy, | ||
}); | ||
const coreStartMock = coreMock.createStart(); | ||
const { getByText } = render( | ||
<IntlProvider locale="en"> | ||
<context.Provider | ||
value={ | ||
{ | ||
services: coreStartMock, | ||
} as any | ||
} | ||
> | ||
<WorkspaceFatalError error="errorInCallout" /> | ||
</context.Provider> | ||
</IntlProvider> | ||
); | ||
fireEvent.click(getByText('Go back to home')); | ||
await waitFor( | ||
() => { | ||
expect(setHrefSpy).toBeCalledTimes(1); | ||
}, | ||
{ | ||
container: document.body, | ||
} | ||
); | ||
window.location = location; | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
src/plugins/workspace/public/components/workspace_fatal_error/workspace_fatal_error.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,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
EuiButton, | ||
EuiEmptyPrompt, | ||
EuiPage, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiCallOut, | ||
} from '@elastic/eui'; | ||
import React from 'react'; | ||
import { FormattedMessage } from '@osd/i18n/react'; | ||
import { IBasePath } from 'opensearch-dashboards/public'; | ||
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; | ||
import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; | ||
|
||
export function WorkspaceFatalError(props: { error?: string }) { | ||
const { | ||
services: { application, http }, | ||
} = useOpenSearchDashboards(); | ||
const goBackToHome = () => { | ||
window.location.href = formatUrlWithWorkspaceId( | ||
application?.getUrlForApp('home') || '', | ||
'', | ||
http?.basePath as IBasePath | ||
); | ||
}; | ||
return ( | ||
<EuiPage style={{ minHeight: '100vh' }}> | ||
<EuiPageBody component="main"> | ||
<EuiPageContent verticalPosition="center" horizontalPosition="center"> | ||
<EuiEmptyPrompt | ||
iconType="alert" | ||
iconColor="danger" | ||
title={ | ||
<h2> | ||
<FormattedMessage | ||
id="core.fatalErrors.somethingWentWrongTitle" | ||
defaultMessage="Something went wrong" | ||
/> | ||
</h2> | ||
} | ||
body={ | ||
<p> | ||
<FormattedMessage | ||
id="core.fatalErrors.tryGoBackToDefaultWorkspaceDescription" | ||
defaultMessage="The workspace you want to go can not be found, try go back to home." | ||
/> | ||
</p> | ||
} | ||
actions={[ | ||
<EuiButton color="primary" fill onClick={goBackToHome}> | ||
<FormattedMessage | ||
id="core.fatalErrors.goBackToHome" | ||
defaultMessage="Go back to home" | ||
/> | ||
</EuiButton>, | ||
]} | ||
/> | ||
{props.error ? <EuiCallOut title={props.error} color="danger" iconType="alert" /> : null} | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</EuiPage> | ||
); | ||
} |
Oops, something went wrong.