@dhis2/app-service-plugin
Advanced tools
"use strict"; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _PluginError = _interopRequireDefault(require("../PluginError")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
// empty tests (to no trigger test failure) | ||
@@ -18,3 +13,2 @@ describe('<PluginError />', () => { | ||
const appShortName = 'some_app'; | ||
const wrapper = () => /*#__PURE__*/React.createElement(_PluginError.default, { | ||
@@ -21,0 +15,0 @@ missingEntryPoint: missingEntryPoint, |
@@ -12,3 +12,2 @@ "use strict"; | ||
}); | ||
var _Plugin = require("./Plugin"); |
@@ -7,19 +7,10 @@ "use strict"; | ||
exports.Plugin = void 0; | ||
var _appServiceAlerts = require("@dhis2/app-service-alerts"); | ||
var _appServiceData = require("@dhis2/app-service-data"); | ||
var _postRobot = _interopRequireDefault(require("post-robot")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _PluginError = _interopRequireDefault(require("./PluginError")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const appsInfoQuery = { | ||
@@ -29,7 +20,7 @@ apps: { | ||
} | ||
}; // sample logic subject to change depending on actual endpoint details | ||
}; | ||
const getPluginEntryPoint = (_ref) => { | ||
// sample logic subject to change depending on actual endpoint details | ||
const getPluginEntryPoint = _ref => { | ||
var _apps$find; | ||
let { | ||
@@ -39,3 +30,3 @@ apps, | ||
} = _ref; | ||
return (_apps$find = apps.find((_ref2) => { | ||
return (_apps$find = apps.find(_ref2 => { | ||
let { | ||
@@ -47,4 +38,3 @@ short_name | ||
}; | ||
const Plugin = (_ref3) => { | ||
const Plugin = _ref3 => { | ||
let { | ||
@@ -72,10 +62,9 @@ pluginSource, | ||
const [resizedHeight, setPluginHeight] = (0, _react.useState)(150); | ||
const [resizedWidth, setPluginWidth] = (0, _react.useState)(500); // since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop | ||
const [resizedWidth, setPluginWidth] = (0, _react.useState)(500); | ||
// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop | ||
// we exclude height/width from memoization to avoid updates for these properties | ||
const memoizedPropsToPass = (0, _react.useMemo)(() => propsToPassNonMemoized, | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
const memoizedPropsToPass = (0, _react.useMemo)(() => propsToPassNonMemoized, /* eslint-disable react-hooks/exhaustive-deps */ | ||
[...Object.keys(propsToPassNonMemoized).sort().map(k => propsToPassNonMemoized[k])] | ||
/* eslint-enable react-hooks/exhaustive-deps */ | ||
); | ||
/* eslint-enable react-hooks/exhaustive-deps */); | ||
(0, _react.useEffect)(() => { | ||
@@ -88,9 +77,8 @@ setCommunicationReceived(false); | ||
setPrevCommunicationReceived(communicationReceived); | ||
if (prevCommunication === false && communicationReceived === true) { | ||
return; | ||
} | ||
if (iframeRef !== null && iframeRef !== void 0 && iframeRef.current) { | ||
const iframeProps = { ...memoizedPropsToPass, | ||
const iframeProps = { | ||
...memoizedPropsToPass, | ||
alertsAdd, | ||
@@ -101,6 +89,8 @@ setPluginHeight: !height ? setPluginHeight : null, | ||
setCommunicationReceived | ||
}; // if iframe has not sent initial request, set up a listener | ||
}; | ||
// if iframe has not sent initial request, set up a listener | ||
if (!communicationReceived && !inErrorState) { | ||
const listener = _postRobot.default.on('getPropsFromParent', // listen for messages coming only from the iframe rendered by this component | ||
const listener = _postRobot.default.on('getPropsFromParent', | ||
// listen for messages coming only from the iframe rendered by this component | ||
{ | ||
@@ -112,7 +102,6 @@ window: iframeRef.current.contentWindow | ||
}); | ||
return () => listener.cancel(); | ||
} // if iframe has sent initial request, send new props | ||
} | ||
// if iframe has sent initial request, send new props | ||
if (communicationReceived && iframeRef.current.contentWindow && !inErrorState) { | ||
@@ -124,7 +113,6 @@ _postRobot.default.send(iframeRef.current.contentWindow, 'updated', iframeProps).catch(err => { | ||
} | ||
} // prevCommunicationReceived update should not retrigger this hook | ||
} | ||
// prevCommunicationReceived update should not retrigger this hook | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [memoizedPropsToPass, communicationReceived, inErrorState, alertsAdd]); | ||
if (data && !pluginEntryPoint) { | ||
@@ -136,3 +124,2 @@ return /*#__PURE__*/_react.default.createElement(_PluginError.default, { | ||
} | ||
if (pluginEntryPoint) { | ||
@@ -149,6 +136,4 @@ return /*#__PURE__*/_react.default.createElement("iframe", { | ||
} | ||
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null); | ||
}; | ||
exports.Plugin = Plugin; |
@@ -7,10 +7,8 @@ "use strict"; | ||
exports.default = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
// PLACEHOLDER plugin error component (e.g. for dealing with missing/inaccessible plugin) | ||
// note that d2-i18n does not work with typescript projects, so we cannot currently translate | ||
const PluginError = (_ref) => { | ||
const PluginError = _ref => { | ||
let { | ||
@@ -22,4 +20,2 @@ missingEntryPoint, | ||
}; | ||
var _default = PluginError; | ||
exports.default = _default; | ||
var _default = exports.default = PluginError; |
"use strict"; | ||
require("@testing-library/jest-dom/extend-expect"); | ||
require("@testing-library/jest-dom"); | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); |
import * as React from 'react'; | ||
import PluginError from '../PluginError'; // empty tests (to no trigger test failure) | ||
import PluginError from '../PluginError'; | ||
// empty tests (to no trigger test failure) | ||
describe('<PluginError />', () => { | ||
@@ -8,3 +9,2 @@ it('should render without failing', async () => { | ||
const appShortName = 'some_app'; | ||
const wrapper = () => /*#__PURE__*/React.createElement(PluginError, { | ||
@@ -11,0 +11,0 @@ missingEntryPoint: missingEntryPoint, |
@@ -10,7 +10,7 @@ import { AlertsManagerContext } from '@dhis2/app-service-alerts'; | ||
} | ||
}; // sample logic subject to change depending on actual endpoint details | ||
}; | ||
const getPluginEntryPoint = (_ref) => { | ||
// sample logic subject to change depending on actual endpoint details | ||
const getPluginEntryPoint = _ref => { | ||
var _apps$find; | ||
let { | ||
@@ -20,3 +20,3 @@ apps, | ||
} = _ref; | ||
return (_apps$find = apps.find((_ref2) => { | ||
return (_apps$find = apps.find(_ref2 => { | ||
let { | ||
@@ -28,4 +28,3 @@ short_name | ||
}; | ||
export const Plugin = (_ref3) => { | ||
export const Plugin = _ref3 => { | ||
let { | ||
@@ -53,10 +52,9 @@ pluginSource, | ||
const [resizedHeight, setPluginHeight] = useState(150); | ||
const [resizedWidth, setPluginWidth] = useState(500); // since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop | ||
const [resizedWidth, setPluginWidth] = useState(500); | ||
// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop | ||
// we exclude height/width from memoization to avoid updates for these properties | ||
const memoizedPropsToPass = useMemo(() => propsToPassNonMemoized, | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
const memoizedPropsToPass = useMemo(() => propsToPassNonMemoized, /* eslint-disable react-hooks/exhaustive-deps */ | ||
[...Object.keys(propsToPassNonMemoized).sort().map(k => propsToPassNonMemoized[k])] | ||
/* eslint-enable react-hooks/exhaustive-deps */ | ||
); | ||
/* eslint-enable react-hooks/exhaustive-deps */); | ||
useEffect(() => { | ||
@@ -69,9 +67,8 @@ setCommunicationReceived(false); | ||
setPrevCommunicationReceived(communicationReceived); | ||
if (prevCommunication === false && communicationReceived === true) { | ||
return; | ||
} | ||
if (iframeRef !== null && iframeRef !== void 0 && iframeRef.current) { | ||
const iframeProps = { ...memoizedPropsToPass, | ||
const iframeProps = { | ||
...memoizedPropsToPass, | ||
alertsAdd, | ||
@@ -82,6 +79,8 @@ setPluginHeight: !height ? setPluginHeight : null, | ||
setCommunicationReceived | ||
}; // if iframe has not sent initial request, set up a listener | ||
}; | ||
// if iframe has not sent initial request, set up a listener | ||
if (!communicationReceived && !inErrorState) { | ||
const listener = postRobot.on('getPropsFromParent', // listen for messages coming only from the iframe rendered by this component | ||
const listener = postRobot.on('getPropsFromParent', | ||
// listen for messages coming only from the iframe rendered by this component | ||
{ | ||
@@ -94,5 +93,5 @@ window: iframeRef.current.contentWindow | ||
return () => listener.cancel(); | ||
} // if iframe has sent initial request, send new props | ||
} | ||
// if iframe has sent initial request, send new props | ||
if (communicationReceived && iframeRef.current.contentWindow && !inErrorState) { | ||
@@ -104,7 +103,6 @@ postRobot.send(iframeRef.current.contentWindow, 'updated', iframeProps).catch(err => { | ||
} | ||
} // prevCommunicationReceived update should not retrigger this hook | ||
} | ||
// prevCommunicationReceived update should not retrigger this hook | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [memoizedPropsToPass, communicationReceived, inErrorState, alertsAdd]); | ||
if (data && !pluginEntryPoint) { | ||
@@ -116,3 +114,2 @@ return /*#__PURE__*/React.createElement(PluginError, { | ||
} | ||
if (pluginEntryPoint) { | ||
@@ -129,4 +126,3 @@ return /*#__PURE__*/React.createElement("iframe", { | ||
} | ||
return /*#__PURE__*/React.createElement(React.Fragment, null); | ||
}; |
@@ -1,5 +0,7 @@ | ||
import React from 'react'; // PLACEHOLDER plugin error component (e.g. for dealing with missing/inaccessible plugin) | ||
import React from 'react'; | ||
// PLACEHOLDER plugin error component (e.g. for dealing with missing/inaccessible plugin) | ||
// note that d2-i18n does not work with typescript projects, so we cannot currently translate | ||
const PluginError = (_ref) => { | ||
const PluginError = _ref => { | ||
let { | ||
@@ -11,3 +13,2 @@ missingEntryPoint, | ||
}; | ||
export default PluginError; |
@@ -1,4 +0,4 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import '@testing-library/jest-dom'; | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); |
@@ -1,6 +0,6 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
declare const PluginError: ({ missingEntryPoint, appShortName, }: { | ||
missingEntryPoint: boolean; | ||
appShortName?: string | undefined; | ||
}) => JSX.Element; | ||
}) => React.JSX.Element; | ||
export default PluginError; |
{ | ||
"name": "@dhis2/app-service-plugin", | ||
"version": "3.11.3", | ||
"version": "3.12.0-alpha.1", | ||
"main": "./build/cjs/index.js", | ||
@@ -29,6 +29,6 @@ "module": "./build/es/index.js", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"@dhis2/app-service-alerts": "3.11.3", | ||
"@dhis2/app-service-data": "3.11.3" | ||
"react": "^16.8.6 || ^18", | ||
"react-dom": "^16.8.6 || ^18", | ||
"@dhis2/app-service-alerts": "3.12.0-alpha.1", | ||
"@dhis2/app-service-data": "3.12.0-alpha.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
326
2.84%16676
-1.88%2
100%