@flipdish/portal-library 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ # Creating a new Project
11
+
12
+ Replace all occurences of `serverless-app-template` with your new app name. It's also important that this name is passed as the `microFrontendWindowName` in the Portal code (see Portal readme for implementation example).
13
+
14
+
15
+ # Testing the project
16
+
17
+ `pnpm run test`
18
+
19
+ # Starting the project
20
+
21
+ `pnpm run dev`
22
+
23
+ Local run uses the index.html attributes so you can locally change language etc.
24
+
25
+ Update the local url in your browser to `/home` otherwise the `Not Found page` will be displayed.
26
+
27
+ # Logging to datadog
28
+
29
+ To save each of the micro frontends initiating their own datadog client Portal sets its logger to the window object `fdlogger`. Typings are set in global.d.ts supporting:
30
+
31
+ `debug, error, info, log, warn`
32
+
33
+ For example:
34
+ `window.fdlogger?.info('Hello from the micro-frontend!');`
35
+
36
+ # Amplitude tracking
37
+
38
+ To save each of the micro frontends initiating their own Amplitude client Portal sets its logger to the window object `FdAmplitude`. Typings are set in global.d.ts supporting the useTracking hook.
39
+
40
+ For example:
41
+ ```
42
+ const { trackEvent } = window.FdAmplitude?.useTracking() || {};
43
+
44
+ useEffect(() => {
45
+ trackEvent('micro_frontend_test', {
46
+ action: logged_in,
47
+ });
48
+ },[])
49
+ ```
50
+
51
+ # Lazy loading components
52
+
53
+ Lazy loading reduces the bundle size improving load speeds on devices with poor internet connection.
54
+
55
+ We can lazy load components using the LazyComponent util component as follows:
56
+
57
+ ```
58
+ import LazyComponent from './ui/LazyComponent';
59
+
60
+ const About = lazyWithRetry(async () => await import('./About'));
61
+ ...
62
+ <Route
63
+ path="/about"
64
+ element={
65
+ <LazyComponent>
66
+ <About />
67
+ </LazyComponent>
68
+ }
69
+ />
70
+ ...
71
+ ```
72
+
73
+ # Translations
74
+
75
+ ### Using the translate hook
76
+ To use translations in the code you:
77
+
78
+ ```
79
+ import { useTranslation } from '../providers/TranslationProvider';
80
+
81
+ const SomeComponent = () => {
82
+ const { translate } = useTranslation();
83
+
84
+ return <div>{translate('translation_key', { count })}</div>
85
+ }
86
+ ```
87
+
88
+ Note: {count} should be referenced in the translation string for replacement such as "Count is {count}"
89
+
90
+ ### Adding new translations
91
+ We use Loco as a source of all translations `https://localise.biz`. Don't edit json lozalization files manually. Update language sources in Loco projecs (`https://localise.biz/conor/serverless-app-template#!l=1` as example).
92
+
93
+
94
+ We use chatGPT4 (chatgpt.com) for translations.
95
+ 1. Pass the `en` example to chatGPT with the required languages:
96
+ ```translate the following to dutch, us english, german, french, italian, spain spanish, portugese and mexican spanish "Welcome_about_page": { "value": "Welcome to the About Page" }```
97
+ 2. Update the related translations in Loco and trigger `.github/workflows/translations.yml` in GitHub Actions.
98
+
99
+ ### Adding new languages
100
+ 1. Copy and paste the english version into chatGPT and ask for the new language that you want.
101
+ 2. Add the language key along with translations to Loco and trigger `.github/workflows/translations.yml` in GitHub Actions.
102
+ 3. Add the language key to `languagesToLoad` in `providers/TranslationProvider.tsx`
103
+
104
+ ### WDIO Integration testing
105
+ We use [WDIO](https://webdriver.io/) for integration testing with a similar set up to Portal. You should have the bulk of your e2e tests for the MF here and add a WDIO test in Portal to verify that the micro-frontend loads successfully.
106
+
107
+ To run the tests locally in the `packages/frontend/e2e/wdio` directory run `pnpm run wdio:local` which will run your `<fileName>.feature` files.
108
+
109
+ To run individual feature files in the `packages/frontend/e2e/wdio` directory run `pnpm run wdio:local --spec features/login.feature`.
110
+
111
+ The urls used to load the Portal and the specific MF version are defined on run in `config.ts`:
112
+ PORTAL_URL: 'https://prod-staging.portal.flipdishdev.com'
113
+
114
+ MICROFRONTEND_INDEX_URL: '${{ steps.variables.outputs.distributionUrl }}assets/index.js'
115
+
116
+ The WDIO for MFs run in [AWS Device Farm](https://aws.amazon.com/device-farm/).