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

Commit 3cde9bc

Browse files
authored
Merge pull request #9 from topcoder-platform/dev
Release 1.0
2 parents e3d9465 + 2f8469a commit 3cde9bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1485
-10554
lines changed

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10.22.1

README.md

+71
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,74 @@ Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli
5656
- 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.
5757
- NOTE: Authorization would not work because only predefined list of domain allowed by `accounts-app`.
5858

59+
### Cross microfrontend imports
60+
61+
This app exports functions to be imported by other microapps.
62+
- `login` - redirects to login page
63+
- `logout` - clears session storage and redirects to logout page
64+
- `setAppMenu` - sets sidebar menu for the app by app's `path`
65+
- `getAuthUserTokens` - returns a promise which resolves to object with user tokens `{ tokenV3, tokenV2 }`
66+
- `getAuthUserProfile` - returns a promise which resolves to the user profile object
67+
- `disableSidebarForRoute` - disable (remove) sidebar for some route
68+
- `enableSidebarForRoute` - enable sidebar for the route, which was previously disabled
69+
70+
#### How to export
71+
72+
- To export any function we have to `export` in file [src/topcoder-micro-frontends-navbar-app.js](src/topcoder-micro-frontends-navbar-app.js).
73+
- 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).
74+
- We have to bind actions before exporting.
75+
- 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.
76+
77+
#### How to import
78+
79+
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).
80+
81+
##### How to import in React app
82+
83+
For example see https://github.com/topcoder-platform/micro-frontends-react-app
84+
85+
1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
86+
```js
87+
externals: {
88+
"@topcoder/micro-frontends-navbar-app": "@topcoder/micro-frontends-navbar-app",
89+
},
90+
```
91+
92+
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:
93+
```js
94+
module.exports = {
95+
login: () => {},
96+
logout: () => {},
97+
setAppMenu: () => {},
98+
getAuthUserTokens: () => new Promise(() => {}),
99+
getAuthUserProfile: () => new Promise(() => {}),
100+
disableSidebarForRoute: () => {},
101+
enableSidebarForRoute: () => {},
102+
};
103+
```
104+
105+
##### How to import in Angular app
106+
107+
For example see https://github.com/topcoder-platform/micro-frontends-angular-app
108+
109+
1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
110+
```js
111+
externals: {
112+
"@topcoder/micro-frontends-navbar-app": "@topcoder/micro-frontends-navbar-app",
113+
},
114+
```
115+
116+
2. Add type definition in `src/typings.d.ts`:
117+
```js
118+
declare module '@topcoder/micro-frontends-navbar-app' {
119+
export const login: any;
120+
export const logout: any;
121+
export const setAppMenu: any;
122+
export const getAuthUserTokens: any;
123+
export const getAuthUserProfile: any;
124+
export const disableSidebarForRoute: any;
125+
export const enableSidebarForRoute: any;
126+
}
127+
```
128+
129+
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'`

config/development.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
URL: {
3-
ACCOUNTS_APP_CONNECTOR: "https://accounts.topcoder-dev.com/connector.html",
4-
AUTH: "https://accounts.topcoder-dev.com",
3+
ACCOUNTS_APP_CONNECTOR: "https://accounts-auth0.topcoder-dev.com",
4+
AUTH: "https://accounts-auth0.topcoder-dev.com",
55
},
66
API: {
77
V3: "https://api.topcoder-dev.com/v3",

config/production.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
URL: {
3-
ACCOUNTS_APP_CONNECTOR: "https://accounts.topcoder.com/connector.html",
4-
AUTH: "https://accounts.topcoder.com",
3+
ACCOUNTS_APP_CONNECTOR: "https://accounts-auth0.topcoder.com",
4+
AUTH: "https://accounts-auth0.topcoder.com",
55
},
66
API: {
77
V3: "https://api.topcoder.com/v3",

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
transform: {
44
"^.+\\.(j|t)sx?$": "babel-jest",
55
},
6-
transformIgnorePatterns: ["node_modules/?!(tc-accounts)"],
6+
transformIgnorePatterns: ["node_modules/?!(tc-auth-lib)"],
77
moduleNameMapper: {
88
"\\.css$": "identity-obj-proxy",
99
"\\.svg$": "<rootDir>/__mocks__/fileMock.js",

0 commit comments

Comments
 (0)