# UI App Development Based on Rainbow Framework
insureMO platform provides Rainbow as the frontend UI framework to boost productivity when developing UI App.

## About Rainbow

Rainbow is a next-generation UI framework that provides strong UI development capabilities for insurance applications. Developed based on Bootstrap and React.js, Rainbow offers comprehensive UI components with a strong focus on making UI development faster and easier. By using out-of-the-box components and SDKs, UI developers can quickly make changes and numerous variations in response to rapid market changes while maintaining standardization of basic capabilities.

For details, see [Rainbow UI Guide](https://rainbow-doc.insuremo.com/ui/sugar-doc/).

## Design UI Interfaces

Before frontend UI development, you need to design the user interface for UI App that will interact with insureMO's services. This involves determining the layout, elements, and overall design of the application's front-end. This ensures that it is user-friendly and enhances the intended user experience. Designers will focus on the functionality, usability, and aesthetics of the interface,  helping users interact smoothly with insureMO's platform.

## Frontend UI Development
The following are steps of frontend UI development:
- Access Github to find the target repository, create your UI App by forking the template project.
- Setup CICD jobs on insureMO.
- Build and deploy APPs to insureMO environment.
- Check the status of your build and deployment.

### Create Your UI App by Forking the Template Project
The following are steps of creating an UI application by forking the template project:

1. Access GitHub and find the target repository. Your GitHub account must be granted access to insureMO’s template repository.
2. Select appframework-rainbow5ui repository.
3. Fork the template project.
> - If you need team collaboration for the development, please fork it to either your organization GitHub space or insureMO's GitHub space.
> - If you want to fork it into insureMO's GitHub space, contact insureMO siteops team to complete the setup.

### Set Up CI/CD Jobs on insureMO
The specific steps of setting up CI/CD jobs for UI application is similar to service application's. 

Please refer to the following steps of the service application's setup: 
1. Log in to [insureMO Portal](https://visitor.insuremo.com/#/home) with your personal account.
2. Click **Category** on the top navigation bar of the insureMO Portal home page.
3. Select **Utility And Admin** > **DevOps** > **CI/CD**.
4. Find your tenant and click **Quick Create**.
5. Fill in the following information:
   - **Template** with BFF template filling in insureMO-standard-service.
   - **Service Name** with BFF service name (naming rule:"repoName"-service).
   - **Repository URL** with GitHub repository path
   - **User Name** with GitHub email account.
   - **Access Token** with GitHub account token. Click here and generate a personal access token.

<div class="docs-note"><span class="docs-admonitions-text">note</span>

As for UI template, you can fill in insuremo-rainbow50-travel-ui.

</div>

### Build and Deploy Apps to insureMO Environment
Compared with traditional method which can only be triggered by developer, insureMO provides application deployment function that is user-friendly. 
There are two ways to build and deploy applications:
- You can deploy your jobs through **My Console**.
- You can also directly deploy your jobs by insureMO **CI/CD**.

The following are steps of building and deploying applications to insureMO through **My Console**:
1. Log in to [insureMO Portal](https://visitor.insuremo.com/#/home) with your personal account.
2. Click **My Console** on the top navigation bar of insureMO Portal home page.
3. Select **Design Time** > **Applications/ Microservices** > **Deploy** in the UI application to bring up the DevOps tool to start building and deploying.

For more information about build and deploy App, see [insureMO DevOps](https://docs.insuremo.com/common/doc_00000298).

### Check the Status of Building and Deployment
The building and deployment history can be viewed in the menu. You can click and view your building and deployment logs.

Upon successful deployment, you can view your application by the following methods:  

   - Clicking **launch** .
   - Or using URL: `https://{env-domain}/ui/{appname}/`, such as: 
     
     `https://trialzone1-gi-sandbox-2-sg.insuremo.com/ui/travel50-web/`

<div class="docs-info"><span class="docs-admonitions-text">info</span>

The above URL is only for example purpose and not intended for access.

</div>


## After merging the new gateway, the api request path processing method

### 1、ajax request path splicing rules
When the environment variable `UI_API_GATEWAY_PROXY_WITH_TENANT` is true, "`api/{tenantCode}`" is added to the api of ajax requests:

When the service name exists in `UI_API_PLATFORM_PATHS`, the platform api is:
`https://domain/api/platform/dd`

If not:
`https://domain/api/{{tenant}}/xxxxxx`

（for example microsite）:`https://domain/api/microsite/microsite-bff-app`


### 2、ajax request the unified modification method of path splicing

-- After upgrading the component version, use "UrlUtil.getConfigUrl"
```
//rainbow 4.0
import { UrlUtil } from 'rainbow-desktop-tools';
//rainbow 5.0
import { UrlUtil } from '@insuremo/rainbowui-sugar-tools';

//Common writing method 1 (standard use):
const langUrl = UrlUtil.getConfigUrl('UI_API_GATEWAY_PROXY', 'USER', 'GET_USER_LANG');

//Common writing method 2:
const langUrl = UrlUtil.getConfigUrl('UI_API_GATEWAY_PROXY')+'urp/public/users/v1/getlang';
//update:
const langUrl = UrlUtil.getConfigUrl(UrlUtil.getConfigUrl('UI_API_GATEWAY_PROXY') + 'urp/public/users/v1/getlang');


//Common writing method 3:
const langUrl = config.UI_API_GATEWAY_PROXY+'urp/public/users/v1/getlang';
//update:
const langUrl = UrlUtil.getConfigUrl(config.UI_API_GATEWAY_PROXY + 'urp/public/users/v1/getlang');
```

## Node version greater than 18.13.X related configurations

### Preconditions:
- node > 18.13.x
- npm  >= 9
Node recommends V18.13+ 
<div style={{color:"red"}}>* Please keep the server and local node versions synchronized.</div>

### Modifying .npmrc file 
![github01](./image/rainbow-_ui_framework/node_01.jpg)

#### 1. Modify properties.json to control the node version packaged by the server

![node22_01](./image/rainbow-_ui_framework/node22_01.png)

#### 2、Modify webpack.common.js
##### Rainbow 4.0（Don't miss the 'vela-parent-ui'）
```js
if (require(rootPath + 'package-lock.json')['lockfileVersion'] < 3) {
    for (let lockKey in require(rootPath + 'package-lock.json')['dependencies']) {
        if (lockKey.indexOf('rainbow') > -1 || lockKey.indexOf('vela-parent-ui') > -1) {
            buildRainbowModule.push(path.resolve(__dirname, './node_modules/' + lockKey));
        }
    }
} else {
    for (let lockKey in require(rootPath + 'package-lock.json')['packages']) {
        if (lockKey.indexOf('rainbow') > -1 || lockKey.indexOf('vela-parent-ui') > -1) {
            buildRainbowModule.push(path.resolve(__dirname, lockKey));
        }
    }
}
```

##### Rainbow 5.0
```js
if (require(rootPath + 'package-lock.json')['lockfileVersion'] < 3) {
    for (let lockKey in require(rootPath + 'package-lock.json')['dependencies']) {
        if (lockKey.indexOf('rainbowui') > -1) {
            buildRainbowModule.push(path.resolve(__dirname, './node_modules/' + lockKey));
        }
    }
} else {
    for (let lockKey in require(rootPath + 'package-lock.json')['packages']) {
        if (lockKey.indexOf('rainbowui') > -1) {
            buildRainbowModule.push(path.resolve(__dirname, lockKey));
        }
    }
}
```
![node22_02](./image/rainbow-_ui_framework/node22_02.png)

## Customize the font for theme colors

### 1、Use the default font for the theme color, but the font is special and needs to be introduced into the font library
Global Configuration->Global Parameter->UIConfig:

|  Key   | Value  |
|  :----  | :----  |
| UI_FONT_GROUP  | {"orange":"Roboto","sky":"Roboto"} |

    Rules:
    * {"skin1":"font1","skin2":"font2"}；
    * The name font1 \ font2 is determined by my specific static resource, corresponding to the font library name uploaded in the static resource;
    * Currently, there is only one: Roboto；

![fontGroup](./image/rainbow-_ui_framework/fontGroup.jpg)

### 2、Customize the fontFamily for theme colors
Global Configuration->Global Parameter->UIConfig:

|  Key   | Value  |
|  :----  | :----  |
| UI_SKIN_FONT_FAMILY_GROUP  | {"default":"Meiryo UI, Hiragino Kaku Gothic Pro, Osaka, arial, verdana, sans-serif","ruby":"arial, Hiragino Sans GB, Microsoft Yahei, Tahoma, Arial, Helvetica"}|

    Rules:
    * {"skin1":"fontFamily","skin2":"fontFamily"}；
    * FontFamily corresponds to the fontFamily attribute of CSS；

![fontFamilyGroup](./image/rainbow-_ui_framework/fontFamilyGroup.jpg)

## Tenant's static resources-Customize Global Files

### 1、Building tenant level static resources
Contact CM to copy the static git and CICD to the tenant environment in need.

![tenantStatic](./image/rainbow-_ui_framework/tenantStatic.png)

<div style={{color:"red"}}>* Tenant static resource URL rules："/tenantCode-static/xxx"</div>

### Custom Theme Colors

#### Global Configuration->Global Parameter->UIConfig:

* Customization requires distinction between Rainbow 4.0 and Rainbow 5.0;

* The path is the file path in the tenant's static resources;

* Write the relative path based on the current environment, which will correspond to the hosts of each environment (in special cases of cross environment calls, if it is necessary to point to a unified path, write the complete path);

|  Key   | Value  |
|  :----  | :----  |
| tenantSkinUrlGroup  | {"skinKey1":{"V5":"Rainbow5.0 Url","V4":"/Rainbow4.0 Url"},"skinKey2":{"V5":"Rainbow5.0 Url","V4":"/Rainbow4.0 Url"}}|

```json
//Example
{"punmpkin":{"V5":"/TenantCode-static/theme/pumpkin.css","V4":"/TenantCode-static/theme/pumpkin-core.css"}}
```

![fontFamilyGroup](./image/rainbow-_ui_framework/cusSkin.png)

#### Related dependency version requirements
* At least "rainbow-static:24.02.006"
* At least "admin-ui:24.02.003"
* At least "rainbowui-sugar-common-ui@5.1.154"