Skip to content

Commit

Permalink
feat(MyPortal): [#174883732] Adds MD documentation on webview injecte…
Browse files Browse the repository at this point in the history
…d script and original JS file (pagopa#2220)

* [#174883732] Adds documentation from webview scripts definition

* Rename JS file and updates documentation

* Rename JS file and updates documentation

* Rename JS file and updates documentation

* updates documentation

* updates documentation

* updates documentation

* updates documentation

* Fixes conflict error

* Minor improvements
  • Loading branch information
CrisTofani authored Sep 24, 2020
1 parent 6eef55f commit a32cf71
Show file tree
Hide file tree
Showing 4 changed files with 731 additions and 6 deletions.
151 changes: 151 additions & 0 deletions MYPORTAL_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
## Functions

<dl>
<dt><a href="#closeModal">closeModal()</a></dt>
<dd><p>This function sends to IO App the input to stop the webview communication and close the current screen.</p>
</dd>
<dt><a href="#showLoader">showLoader()</a></dt>
<dd><p>This function sends to IO App the input to show the activity indicator loader.</p>
</dd>
<dt><a href="#hideLoader">hideLoader()</a></dt>
<dd><p>This function sends to IO App the input to hide the activity indicator loader.</p>
</dd>
<dt><a href="#showSuccess">showSuccess(payload)</a></dt>
<dd><p>A function to show the success component on the IO App side.</p>
</dd>
<dt><a href="#showErrorMessage">showErrorMessage(payload)</a></dt>
<dd><p>A function to send an error message to IO App component</p>
</dd>
<dt><a href="#showAlertBox">showAlertBox(payload)</a></dt>
<dd><p>A function to show an AlertBox in the IO App component.</p>
</dd>
<dt><a href="#checkInjectionCompleted">checkInjectionCompleted()</a></dt>
<dd><p>This is a utility function to check if the injection is yet completed.
This calls onInjectionCompleted function which is implemented by the client and not injected by IO App.</p>
</dd>
</dl>

## Typedefs

<dl>
<dt><a href="#AlertContents">AlertContents</a> : <code>Object</code></dt>
<dd><p>An Object to define the values of Title and description of an alert box.</p>
</dd>
<dt><a href="#MessagePayloadS">MessagePayloadS</a> : <code>Object</code></dt>
<dd><p>An object defined for internationalization purpose.
The key is the language key and the value is the message text</p>
<p>Accepted keys:</p>
<ul>
<li>it</li>
<li>en</li>
</ul>
</dd>
<dt><a href="#MessagePayloadL">MessagePayloadL</a> : <code>Object</code></dt>
<dd><p>An object defined for internationalization purpose.
The key is the language key and the value is the payload for alert box</p>
</dd>
</dl>

<a name="closeModal"></a>

## closeModal()
This function sends to IO App the input to stop the webview communication and close the current screen.

**Kind**: global function
<a name="showLoader"></a>

## showLoader()
This function sends to IO App the input to show the activity indicator loader.

**Kind**: global function
<a name="hideLoader"></a>

## hideLoader()
This function sends to IO App the input to hide the activity indicator loader.

**Kind**: global function
<a name="showSuccess"></a>

## showSuccess(payload)
A function to show the success component on the IO App side.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| payload | [<code>MessagePayloadS</code>](#MessagePayloadS) | Will be the message showed in the success screen, otherwise a common text will be displayed |

<a name="showErrorMessage"></a>

## showErrorMessage(payload)
A function to send an error message to IO App component

**Kind**: global function

| Param | Type |
| --- | --- |
| payload | [<code>MessagePayloadS</code>](#MessagePayloadS) |

<a name="showAlertBox"></a>

## showAlertBox(payload)
A function to show an AlertBox in the IO App component.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| payload | [<code>MessagePayloadL</code>](#MessagePayloadL) | the value to display in the alert box. |

<a name="checkInjectionCompleted"></a>

## checkInjectionCompleted()
This is a utility function to check if the injection is yet completed.
This calls onInjectionCompleted function which is implemented by the client and not injected by IO App.

**Kind**: global function
<a name="AlertContents"></a>

## AlertContents : <code>Object</code>
An Object to define the values of Title and description of an alert box.

**Kind**: global typedef
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| title | <code>string</code> | The title of the alert box. |
| description | <code>string</code> | The main message of the alert box. |

<a name="MessagePayloadS"></a>

## MessagePayloadS : <code>Object</code>
An object defined for internationalization purpose.
The key is the language key and the value is the message text

Accepted keys:
- it
- en

**Kind**: global typedef
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| it | <code>string</code> | The message defined in Italian. |
| en | <code>string</code> | The message defined in English. |

<a name="MessagePayloadL"></a>

## MessagePayloadL : <code>Object</code>
An object defined for internationalization purpose.
The key is the language key and the value is the payload for alert box

**Kind**: global typedef
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| it | <code>AlertContent</code> | The values of the alert box in Italian language |
| en | <code>AlertContent</code> | The values of the alert box in English language |

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"generate:locales": "ts-node --skip-project -O '{\"lib\":[\"es2015\"]}' scripts/make-locales.ts",
"generate:content-definitions": "rimraf definitions/content && mkdir -p definitions/content && gen-api-models --api-spec $npm_package_io_content_specs --out-dir ./definitions/content",
"generate:all": "npm-run-all generate:mock-google-services-json generate:api-definitions generate:pagopa-api-definitions generate:content-definitions generate:bonus-vacanze-definitions generate:bpd-citizen generate:locales",
"locales_unused": "ts-node --skip-project -O '{\"lib\":[\"es2015\"]}' scripts/unused-locales.ts"
"locales_unused": "ts-node --skip-project -O '{\"lib\":[\"es2015\"]}' scripts/unused-locales.ts",
"generate-myportal-readme": "jsdoc2md ts/utils/webviewScripts/*.js > MYPORTAL_README.md"
},
"dependencies": {
"@pagopa/react-native-cie": "0.2.2",
Expand Down Expand Up @@ -174,6 +175,7 @@
"italia-utils": "^4.1.1",
"jest": "^25.1.0",
"js-yaml": "^3.13.1",
"jsdoc-to-markdown": "^6.0.1",
"metro-react-native-babel-preset": "^0.61.0",
"mock-http-server": "^1.3.0",
"node-fetch": "^2.3.0",
Expand Down
135 changes: 135 additions & 0 deletions ts/utils/webviewScripts/IOWebviewCommunicationAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* eslint-disable no-console */
/* eslint-disable no-undef */

/**
* An Object to define the values of Title and description of an alert box.
*
* @typedef {Object} AlertContents
* @property {string} title - The title of the alert box.
* @property {string} description - The main message of the alert box.
*/

/**
* An object defined for internationalization purpose.
* The key is the language key and the value is the message text
*
* Accepted keys:
* - it
* - en
* @typedef {Object} MessagePayloadS
* @property {string} it - The message defined in Italian.
* @property {string} en - The message defined in English.
*/

/**
* An object defined for internationalization purpose.
* The key is the language key and the value is the payload for alert box
*
* @typedef {Object} MessagePayloadL
* @property {AlertContent} it - The values of the alert box in Italian language
* @property {AlertContent} en - The values of the alert box in English language
*/

// /**
// * The object that defines the data exchange between IO App and webpage layers.
// *
// * @typedef {Object} Message
// * @property {string} type - The values of the alert box in Italian language
// * @property {(...MessagePayloadL|...MessagePayloadS)} - (Optional) The values of the alert box in English language
// */

// /**
// * This function sends messages to IO app layer.
// *
// * @param {Message} message
// */
function sendMessagesToRN(message) {
if (message) {
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage(JSON.stringify(message));
}
return;
}
console.error("Specify a message to send");
}

/**
* This function sends to IO App the input to stop the webview communication and close the current screen.
*/
function closeModal() {
const message = {
type: "CLOSE_MODAL"
};
sendMessagesToRN(message);
}

/**
* This function sends to IO App the input to show the activity indicator loader.
*/
function showLoader() {
const message = {
type: "START_LOAD"
};
sendMessagesToRN(message);
}

/**
* This function sends to IO App the input to hide the activity indicator loader.
*/
function hideLoader() {
const message = {
type: "END_LOAD"
};
sendMessagesToRN(message);
}

/**
* A function to show the success component on the IO App side.
*
* @param {MessagePayloadS} payload - Will be the message showed in the success screen, otherwise a common text will be displayed
*/
function showSuccess(payload) {
const message = {
type: "SHOW_SUCCESS",
...payload
};
sendMessagesToRN(message);
}

/**
* A function to send an error message to IO App component
*
* @param {MessagePayloadS} payload
*/
function showErrorMessage(payload) {
const message = {
type: "SHOW_ERROR",
...payload
};
sendMessagesToRN(message);
}

/**
* A function to show an AlertBox in the IO App component.
*
* @param {MessagePayloadL} payload - the value to display in the alert box.
*/
function showAlertBox(payload) {
const message = {
type: "SHOW_ALERT",
...payload
};
sendMessagesToRN(message);
}

/**
* This is a utility function to check if the injection is yet completed.
* This calls onInjectionCompleted function which is implemented by the client and not injected by IO App.
*/
function checkInjectionCompleted() {
if (typeof onInjectionCompleted === "function") {
onInjectionCompleted();
}
}

checkInjectionCompleted();
Loading

0 comments on commit a32cf71

Please sign in to comment.