-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect legacy notebooks URL to current observability one (#141)
- Loading branch information
1 parent
6a06e24
commit d360344
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
public/components/notebooks/components/__test__/legacy_route_helpers.test.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,50 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { RedirectProps } from "react-router-dom"; | ||
import { convertLegacyNotebooksUrl } from "../helpers/legacy_route_helpers"; | ||
|
||
describe('Test legacy route helpers', () => { | ||
it('converts legacy notebooks url', () => { | ||
const locations = [ | ||
{ | ||
pathname: '/app/notebooks-dashboards', | ||
search: '', | ||
hash: '#/GQ5icXwBJCegTOBKO4Um', | ||
}, | ||
{ | ||
pathname: '/app/notebooks-dashboards', | ||
search: '?view=view_both', | ||
hash: '#/clPiPXwBEM7l9gC0xTpA', | ||
}, | ||
{ | ||
pathname: '/testBasePath/app/notebooks-dashboards', | ||
search: '?view=output_only&security_tenant=global', | ||
hash: `#/GQ5icXwBJCegTOBKO4Um?_g=(time:(from:'2021-10-15T20:25:09.556Z',to:'2021-10-15T20:55:09.556Z'))`, | ||
}, | ||
] as Location[]; | ||
const expected = [ | ||
{ | ||
pathname: '/app/observability', | ||
hash: '#/notebooks/GQ5icXwBJCegTOBKO4Um' | ||
}, | ||
{ | ||
pathname: '/app/observability', | ||
hash: '#/notebooks/clPiPXwBEM7l9gC0xTpA?view=view_both' | ||
}, | ||
{ | ||
pathname: '/testBasePath/app/observability', | ||
hash: `#/notebooks/GQ5icXwBJCegTOBKO4Um?_g=(time:(from:'2021-10-15T20:25:09.556Z',to:'2021-10-15T20:55:09.556Z'))&view=output_only&security_tenant=global` | ||
}, | ||
] as RedirectProps['to'][] | ||
expect(locations.map((location) => convertLegacyNotebooksUrl(location))).toEqual(expected); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
public/components/notebooks/components/helpers/legacy_route_helpers.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,20 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { RedirectProps } from 'react-router-dom'; | ||
|
||
export const convertLegacyNotebooksUrl = (location: Location): RedirectProps['to'] => { | ||
const pathname = location.pathname.replace('notebooks-dashboards', 'observability'); | ||
const hash = `#/notebooks${location.hash.replace(/^#/, '')}${ | ||
location.hash.includes('?') ? location.search.replace(/^\?/, '&') : location.search | ||
}`; | ||
return { pathname, hash }; | ||
}; |
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,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { BrowserRouter, Redirect, Switch } from 'react-router-dom'; | ||
import { AppMountParameters } from '../../../../../../src/core/public'; | ||
import { convertLegacyNotebooksUrl } from './helpers/legacy_route_helpers'; | ||
|
||
export const LegacyRoute = (AppMountParameters: AppMountParameters) => { | ||
ReactDOM.render( | ||
<BrowserRouter forceRefresh={true}> | ||
<Switch> | ||
<Redirect from="/" to={convertLegacyNotebooksUrl(window.location)} /> | ||
</Switch> | ||
</BrowserRouter>, | ||
AppMountParameters.element | ||
); | ||
return () => ReactDOM.unmountComponentAtNode(AppMountParameters.element); | ||
}; |
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