Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Release 1.0 #9

Merged
merged 18 commits into from
Dec 11, 2020
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.22.1
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,74 @@ Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli
- Now you have to configure frame app to use the URL provided by Heroku like `https://<APP-NAME>.herokuapp.com/topcoder-micro-frontends-navbar-app.js` to load this microapp.
- NOTE: Authorization would not work because only predefined list of domain allowed by `accounts-app`.

### Cross microfrontend imports

This app exports functions to be imported by other microapps.
- `login` - redirects to login page
- `logout` - clears session storage and redirects to logout page
- `setAppMenu` - sets sidebar menu for the app by app's `path`
- `getAuthUserTokens` - returns a promise which resolves to object with user tokens `{ tokenV3, tokenV2 }`
- `getAuthUserProfile` - returns a promise which resolves to the user profile object
- `disableSidebarForRoute` - disable (remove) sidebar for some route
- `enableSidebarForRoute` - enable sidebar for the route, which was previously disabled

#### How to export

- To export any function we have to `export` in file [src/topcoder-micro-frontends-navbar-app.js](src/topcoder-micro-frontends-navbar-app.js).
- If we want to prepare some function for exporting, the good place to do so is inside [src/utils/exports.js](src/utils/exports.js).
- We have to bind actions before exporting.
- It's not recommended to export the whole Redux Store to keep only navbar responsible for updating it. It's better to create promises which would return some particular value from the store.

#### How to import

When we want to use methods exported in the navbar microapp in other apps we have to make sure that webpack would not process imports from navbar as it is handled by `importmaps`, see [Cross microfrontend imports](https://single-spa.js.org/docs/recommended-setup/#cross-microfrontend-imports).

##### How to import in React app

For example see https://github.com/topcoder-platform/micro-frontends-react-app

1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
```js
externals: {
"@topcoder/micro-frontends-navbar-app": "@topcoder/micro-frontends-navbar-app",
},
```

2. As `importmaps` only work in browser and don't work in unit test, we have to mock this module in unit tests. For example by creating a file `src/__mocks__/@topcoder/micro-frontends-navbar-app.js` with the content like:
```js
module.exports = {
login: () => {},
logout: () => {},
setAppMenu: () => {},
getAuthUserTokens: () => new Promise(() => {}),
getAuthUserProfile: () => new Promise(() => {}),
disableSidebarForRoute: () => {},
enableSidebarForRoute: () => {},
};
```

##### How to import in Angular app

For example see https://github.com/topcoder-platform/micro-frontends-angular-app

1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
```js
externals: {
"@topcoder/micro-frontends-navbar-app": "@topcoder/micro-frontends-navbar-app",
},
```

2. Add type definition in `src/typings.d.ts`:
```js
declare module '@topcoder/micro-frontends-navbar-app' {
export const login: any;
export const logout: any;
export const setAppMenu: any;
export const getAuthUserTokens: any;
export const getAuthUserProfile: any;
export const disableSidebarForRoute: any;
export const enableSidebarForRoute: any;
}
```

3. TODO: How to make e2e tests work for Angular? So far they fail with error `Module not found: Error: Can't resolve '@topcoder/micro-frontends-navbar-app'`
4 changes: 2 additions & 2 deletions config/development.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
URL: {
ACCOUNTS_APP_CONNECTOR: "https://accounts.topcoder-dev.com/connector.html",
AUTH: "https://accounts.topcoder-dev.com",
ACCOUNTS_APP_CONNECTOR: "https://accounts-auth0.topcoder-dev.com",
AUTH: "https://accounts-auth0.topcoder-dev.com",
},
API: {
V3: "https://api.topcoder-dev.com/v3",
Expand Down
4 changes: 2 additions & 2 deletions config/production.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
URL: {
ACCOUNTS_APP_CONNECTOR: "https://accounts.topcoder.com/connector.html",
AUTH: "https://accounts.topcoder.com",
ACCOUNTS_APP_CONNECTOR: "https://accounts-auth0.topcoder.com",
AUTH: "https://accounts-auth0.topcoder.com",
},
API: {
V3: "https://api.topcoder.com/v3",
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
transform: {
"^.+\\.(j|t)sx?$": "babel-jest",
},
transformIgnorePatterns: ["node_modules/?!(tc-accounts)"],
transformIgnorePatterns: ["node_modules/?!(tc-auth-lib)"],
moduleNameMapper: {
"\\.css$": "identity-obj-proxy",
"\\.svg$": "<rootDir>/__mocks__/fileMock.js",
Expand Down
Loading