Skip to content
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

UI - Introduce a solutions navbar #3106

Merged
merged 2 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions solutions-ui-navbar/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[ignore]
.*/node_modules/module-deps/.*
.*/build/.*

[include]
src/.*

[libs]

[lints]
all=error
untyped-import=off
unclear-type=off
sketchy-null=off
unsafe-getters-setters=warn

[options]
esproposal.optional_chaining=enable
react.runtime=automatic

[strict]

[untyped]
.*/node_modules/react-select/.*
2 changes: 2 additions & 0 deletions solutions-ui-navbar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
5 changes: 5 additions & 0 deletions solutions-ui-navbar/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
56 changes: 56 additions & 0 deletions solutions-ui-navbar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# solutions-navbar

Common navbar that can be integrated in metalk8s solution UI to provide the following features :

- Authentication : token negociation, token renewal, claims provider
- Theming : provide the selected theme to solution UIs
- I18n : provide a language selector and expose selected language to solution UIs

## Contribute

```js
$ npm run start
```

## Build

```js
$ npm run build
```

## Use

```html
<script src="./dist/main.js"></script>
<solutions-navbar
oidc-provider-url="https://oidc.provider/"
scopes="openid mail scope"

/>
```

### Attributes

- oidc-provider-url : string, required, the component will suffix it with .well-known/openid-configuration to retrieve OIDC configuration
- scopes : string, required, scopes negiciated with the oidc provider
- client-id : string, required

- redirect-url : string, customized redirect uri
- options : {[url: string]: {en: string, fr: string, roles: string[]}} -- eg : {"/": {en: "Overview", fr: "Vue generale", roles: ["admin"]}, "/platform": {en: "Platform", fr: "Infrastructure"}, ...} - by default we display the full navbar in static mode, this attribute can be used if we want to extends the menu in a specific context

## Methods

- logOut(): void - force logOut, might be called when an UI receive a 401 or 403 status code for example
- getClaims(): Promise<Claims>
- getIdToken(): Promise<string> - jwtToken
- getLanguage(): "en" | "fr"
- getTheme(): Theme
- getOptions(): {[url: string]: {en: string, fr: string}}

## Events

- solutions--authenticated, payload: {token, claims: {roles, instanceIds, firstName, lastName, email, scopes, ...}} --- also called when the token is renewed
- solutions--logged-out, payload : {}
- solutions--theme-changed, payload: {theme}
- solutions--language-changed, payload: {language: "en" | "fr"}

16 changes: 16 additions & 0 deletions solutions-ui-navbar/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if (process.env.NODE_ENV === "test") {
module.exports = {
"presets": ["@babel/preset-env", "@babel/preset-flow", ["@babel/preset-react", {
"runtime": "automatic"
}]],
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
} else {
module.exports = {
"presets": ["@babel/preset-env", "@babel/preset-flow", ["@babel/preset-react", {
"runtime": "automatic"
}]]
}

}

12 changes: 12 additions & 0 deletions solutions-ui-navbar/index-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
</body>
</html>

4 changes: 4 additions & 0 deletions solutions-ui-navbar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ReactDOM from 'react-dom';
import Mdx from './src/index.mdx';

ReactDOM.render(<Mdx />, document.getElementById('app'));
3 changes: 3 additions & 0 deletions solutions-ui-navbar/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"transformIgnorePatterns": ["/node_modules/(?!react-to-webcomponent)"]
}
Loading