-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into setup_global_learning_resources_page
- Loading branch information
Showing
16 changed files
with
1,322 additions
and
2,427 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
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,62 @@ | ||
import { getSharedScope } from '@scalprum/core'; | ||
import ScalprumProvider from '@scalprum/react-core'; | ||
import React, { ComponentType, PropsWithChildren, Suspense, lazy, useEffect, useState } from 'react'; | ||
import updateSharedScope, { hacApps } from '../../../src/chrome/update-shared-scope'; | ||
import { BrowserRouter, Link, Route, Routes } from 'react-router-dom'; | ||
|
||
const PatchedLink = lazy<ComponentType<PropsWithChildren<{ to: string }>>>(async () => { | ||
const m = await getSharedScope()['react-router-dom']['*'].get(); | ||
return { | ||
default: m().NavLink, | ||
}; | ||
}); | ||
|
||
const ScalprumBase = ({ children }: PropsWithChildren) => { | ||
const [ok, setOk] = useState(false); | ||
useEffect(() => { | ||
updateSharedScope(); | ||
setTimeout(() => { | ||
// delay the render to ensure the shared scope was patched | ||
setOk(true); | ||
}); | ||
}, []); | ||
return <ScalprumProvider config={{}}>{ok && <Suspense fallback={<div>Loading...</div>}>{children}</Suspense>}</ScalprumProvider>; | ||
}; | ||
|
||
describe('RouterOverrides', () => { | ||
const cases = [ | ||
...hacApps.map((app) => ({ | ||
name: `Should prefix hacApp link pathname with /hac for ${app}`, | ||
pathname: `/foo/hac${app}`, | ||
hasPrefix: true, | ||
})), | ||
{ | ||
name: 'Should not prefix hacApp link pathname with "hac" substring somewhere in the pathname', | ||
pathname: '/foo/hac-e2e-user/application/bar', | ||
hasPrefix: false, | ||
}, | ||
]; | ||
|
||
cases.forEach(({ name, pathname, hasPrefix }) => { | ||
it(name, () => { | ||
cy.mount( | ||
<BrowserRouter> | ||
<div> | ||
<Link to={pathname}>navigate</Link> | ||
</div> | ||
<ScalprumBase> | ||
<Routes> | ||
<Route path={pathname} element={<PatchedLink to="/application-pipeline/workspaces">trigger</PatchedLink>} /> | ||
</Routes> | ||
</ScalprumBase> | ||
</BrowserRouter> | ||
); | ||
|
||
cy.contains('navigate').click(); | ||
cy.contains('trigger') | ||
.first() | ||
.invoke('attr', 'href') | ||
.should('eq', `${hasPrefix ? '/hac' : ''}/application-pipeline/workspaces`); | ||
}); | ||
}); | ||
}); |
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,127 @@ | ||
# UI Preview environment | ||
|
||
Preview environment exists to allow the users to opt-in into experimental version of the HCC UI. This environment can contain future features. The environment is not considered stable! | ||
|
||
## Legacy preview environment | ||
|
||
> This environment is being decommissioned on **August 1, 2024**. | ||
This environment can be access on any valid HCC URL simply by adding `/preview` to the URL host. This environment uses standalone deployments of the frontend modules (deployments can share builds). | ||
|
||
## Upcoming preview environment | ||
|
||
As of June 2024, the new preview environment is available. The HCC UI will be switched to this new preview environment on **August 1, 2024**. | ||
|
||
### Accessing new preview | ||
|
||
To test the preview functionality before the switch a localStorage flag needs to ne enabled. In the browser console use this command: | ||
|
||
```js | ||
window.insights.chrome.enable.forceLocalPreview() | ||
``` | ||
|
||
After this, reload the browser window. | ||
|
||
### Toggling preview | ||
|
||
To toggle between stable/preview environments, use the preview toggle. Changing the URL will no longer have any effect. | ||
|
||
### Distinguishing between stable/preview environments | ||
|
||
## Using preview | ||
|
||
To enable/disable preview features use one of the following: | ||
|
||
> Using feature flags is recommended | ||
### Feature flags | ||
|
||
Feature flags can be used to enable/disable preview features. Chrome UI is adding a `platform.chrome.ui.preview` context variable. Use this context field in feature flags to enable/disable preview features. | ||
|
||
#### React components | ||
|
||
Follow the official docs: https://docs.getunleash.io/reference/sdks/react#check-feature-toggle-status | ||
|
||
```jsx | ||
import { useFlag } from '@unleash/proxy-client-react'; | ||
|
||
const TestComponent = () => { | ||
const enabled = useFlag('foo.bar'); | ||
|
||
if (enabled) { | ||
return <SomeComponent />; | ||
} | ||
return <AnotherComponent />; | ||
}; | ||
|
||
export default TestComponent; | ||
``` | ||
|
||
#### Navigation | ||
|
||
To conditionally display left navigation items based on feature flag values, use the `featureFlag` visibility function in the nav item definition: | ||
|
||
```JSON | ||
{ | ||
"id": "foo", | ||
"appId": "foo", | ||
"title": "Foo", | ||
"href": "/foo/bar", | ||
"permissions": [ | ||
{ | ||
"method": "featureFlag", | ||
"args": ["foo.bar", true] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
#### Search index | ||
|
||
To conditionally display items based on feature flags, use the `featureFlag` visibility functions in the associated link or static entry. | ||
|
||
```JSON | ||
{ | ||
"id": "foo", | ||
"appId": "foo", | ||
"title": "Foo", | ||
"href": "/foo/bar", | ||
"permissions": [ | ||
{ | ||
"method": "featureFlag", | ||
"args": ["foo.bar", true] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### `isBeta` Chrome API | ||
|
||
> This API is deprecated. Please use the feature flags. | ||
#### React components | ||
|
||
Use the `useChrome` hook to access the `isBeta` method: | ||
|
||
```jsx | ||
import useChrome from '@redhat-cloud-services/frontend-components/useChrome'; | ||
|
||
const Component = () => { | ||
const { isBeta } = useChrome() | ||
|
||
const isPreview = isBeta() | ||
|
||
return ( | ||
... | ||
) | ||
|
||
} | ||
``` | ||
|
||
#### Navigation | ||
|
||
Not supported via chrome API | ||
|
||
#### Search index | ||
|
||
Not supported via chrome API |
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
Oops, something went wrong.