Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dhis2/app-service-alerts

Package Overview
Dependencies
Maintainers
0
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhis2/app-service-alerts - npm Package Compare versions

Comparing version 3.11.3 to 3.12.0-alpha.1

160

build/cjs/__tests__/integration.test.js
"use strict";
var _reactHooks = require("@testing-library/react-hooks");
var _react = _interopRequireDefault(require("react"));
var _react = require("@testing-library/react");
var _react2 = _interopRequireDefault(require("react"));
var _index = require("../index");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
describe('useAlert and useAlerts used together', () => {
it('Can add an alert with static arguments', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {
children
} = _ref;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -36,3 +31,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show();

@@ -52,16 +47,15 @@ });

it('Can add an alert with dynamic arguments', () => {
const wrapper = (_ref2) => {
const wrapper = _ref2 => {
let {
children
} = _ref2;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();
const {
show
} = (0, _index.useAlert)((_ref3) => {
} = (0, _index.useAlert)(_ref3 => {
let {

@@ -71,3 +65,3 @@ username

return `Successfully deleted ${username}`;
}, (_ref4) => {
}, _ref4 => {
let {

@@ -89,3 +83,3 @@ isCurrentUser

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show({

@@ -108,12 +102,11 @@ username: 'hendrik',

it('Can remove an alert with the hide function from useAlerts', () => {
const wrapper = (_ref5) => {
const wrapper = _ref5 => {
let {
children
} = _ref5;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -134,3 +127,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show();

@@ -147,3 +140,3 @@ });

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.hide();

@@ -154,12 +147,11 @@ });

it('Can remove an alert with the remove function on the alert itself', () => {
const wrapper = (_ref6) => {
const wrapper = _ref6 => {
let {
children
} = _ref6;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -180,3 +172,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show();

@@ -193,3 +185,3 @@ });

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alerts[0].remove();

@@ -200,10 +192,9 @@ });

it('Will not create duplicate alerts because of rerenders', () => {
const wrapper = (_ref7) => {
const wrapper = _ref7 => {
let {
children
} = _ref7;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const hook = (0, _reactHooks.renderHook)(() => {
const hook = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -222,3 +213,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
hook.result.current.show();

@@ -231,12 +222,11 @@ hook.rerender();

it('Will not create duplicate alerts when show is called multiple times in a render cycle', () => {
const wrapper = (_ref8) => {
const wrapper = _ref8 => {
let {
children
} = _ref8;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -255,3 +245,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show();

@@ -263,16 +253,15 @@ result.current.show();

it('Will update the alert if show is called with different arguments', () => {
const wrapper = (_ref9) => {
const wrapper = _ref9 => {
let {
children
} = _ref9;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();
const {
show
} = (0, _index.useAlert)((_ref10) => {
} = (0, _index.useAlert)(_ref10 => {
let {

@@ -282,3 +271,3 @@ message

return message;
}, (_ref11) => {
}, _ref11 => {
let {

@@ -295,4 +284,4 @@ options

wrapper
}); // Show alert for first time
});
// Show alert for first time
const payload1 = {

@@ -305,13 +294,16 @@ message: 'Message 1',

};
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show(payload1);
});
expect(result.current.alerts).toHaveLength(1);
expect(result.current.alerts[0]).toEqual({ ...payload1,
expect(result.current.alerts[0]).toEqual({
...payload1,
id: 1,
remove: expect.any(Function),
options: { ...payload1.options
options: {
...payload1.options
}
}); // Show alert for second time
});
// Show alert for second time
const payload2 = {

@@ -323,10 +315,12 @@ message: 'Message 2',

};
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show(payload2);
});
expect(result.current.alerts).toHaveLength(1);
expect(result.current.alerts[0]).toEqual({ ...payload2,
expect(result.current.alerts[0]).toEqual({
...payload2,
id: 1,
remove: expect.any(Function),
options: { ...payload2.options
options: {
...payload2.options
}

@@ -336,12 +330,11 @@ });

it('Will increment IDs when multiple alerts are added', () => {
const wrapper = (_ref12) => {
const wrapper = _ref12 => {
let {
children
} = _ref12;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -366,3 +359,3 @@ const {

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.show1();

@@ -378,12 +371,11 @@ result.current.show2();

it('Removes the correct item from the alerts array', () => {
const wrapper = (_ref13) => {
const wrapper = _ref13 => {
let {
children
} = _ref13;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -402,3 +394,3 @@ const alert1 = (0, _index.useAlert)('show 1');

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.show();

@@ -409,3 +401,3 @@ result.current.alert2.show();

expect(result.current.alerts).toHaveLength(3);
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert2.hide();

@@ -418,12 +410,11 @@ });

it('Gets added into a new slot when show is called after hide', () => {
const wrapper = (_ref14) => {
const wrapper = _ref14 => {
let {
children
} = _ref14;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -440,3 +431,3 @@ const alert1 = (0, _index.useAlert)('show 1');

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.show();

@@ -448,3 +439,3 @@ result.current.alert2.show();

expect(result.current.alerts[1].id).toBe(2);
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.hide();

@@ -454,21 +445,20 @@ });

expect(result.current.alerts[0].id).toBe(2);
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.show();
});
expect(result.current.alerts).toHaveLength(2);
expect(result.current.alerts[0].id).toBe(2); // now is last item with id 3 because it was "re-added"
expect(result.current.alerts[0].id).toBe(2);
// now is last item with id 3 because it was "re-added"
expect(result.current.alerts[1].id).toBe(3);
});
it('Gets added into a new slot when show is called after remove is called on an alert', () => {
const wrapper = (_ref15) => {
const wrapper = _ref15 => {
let {
children
} = _ref15;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => {
} = (0, _react.renderHook)(() => {
const alerts = (0, _index.useAlerts)();

@@ -485,3 +475,3 @@ const alert1 = (0, _index.useAlert)('show 1');

});
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.show();

@@ -493,3 +483,3 @@ result.current.alert2.show();

expect(result.current.alerts[1].id).toBe(2);
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alerts[0].remove();

@@ -499,10 +489,10 @@ });

expect(result.current.alerts[0].id).toBe(2);
(0, _reactHooks.act)(() => {
(0, _react.act)(() => {
result.current.alert1.show();
});
expect(result.current.alerts).toHaveLength(2);
expect(result.current.alerts[0].id).toBe(2); // now is last item with id 3 because it was "re-added"
expect(result.current.alerts[0].id).toBe(2);
// now is last item with id 3 because it was "re-added"
expect(result.current.alerts[1].id).toBe(3);
});
});
"use strict";
var _reactHooks = require("@testing-library/react-hooks");
var _react = _interopRequireDefault(require("react"));
var _react = require("@testing-library/react");
var _react2 = _interopRequireDefault(require("react"));
var _index = require("../index");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
describe('useAlert', () => {
it('Hook returns a show and hide function', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {
children
} = _ref;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => (0, _index.useAlert)('test'), {
} = (0, _react.renderHook)(() => (0, _index.useAlert)('test'), {
wrapper

@@ -24,0 +19,0 @@ });

"use strict";
var _reactHooks = require("@testing-library/react-hooks");
var _react = _interopRequireDefault(require("react"));
var _react = require("@testing-library/react");
var _react2 = _interopRequireDefault(require("react"));
var _index = require("../index");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
describe('useAlerts', () => {
it('Renders without crashing', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {
children
} = _ref;
return /*#__PURE__*/_react.default.createElement(_index.AlertsProvider, null, children);
return /*#__PURE__*/_react2.default.createElement(_index.AlertsProvider, null, children);
};
const {
result
} = (0, _reactHooks.renderHook)(() => (0, _index.useAlerts)(), {
} = (0, _react.renderHook)(() => (0, _index.useAlerts)(), {
wrapper

@@ -24,0 +19,0 @@ });

@@ -7,9 +7,4 @@ "use strict";

exports.AlertsContext = void 0;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const AlertsContext = /*#__PURE__*/_react.default.createContext([]);
exports.AlertsContext = AlertsContext;
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AlertsContext = exports.AlertsContext = /*#__PURE__*/_react.default.createContext([]);

@@ -7,11 +7,7 @@ "use strict";

exports.AlertsManagerContext = 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 }; }
const placeholder = () => {
throw new Error('This function is a placeholder used when creating the AlertsManagerContext, it should be overridden');
};
const defaultAlertsManager = {

@@ -23,5 +19,2 @@ add: placeholder,

};
const AlertsManagerContext = /*#__PURE__*/_react.default.createContext(defaultAlertsManager);
exports.AlertsManagerContext = AlertsManagerContext;
const AlertsManagerContext = exports.AlertsManagerContext = /*#__PURE__*/_react.default.createContext(defaultAlertsManager);

@@ -7,16 +7,9 @@ "use strict";

exports.AlertsProvider = void 0;
var _react = _interopRequireWildcard(require("react"));
var _AlertsContext = require("./AlertsContext");
var _AlertsManagerContext = require("./AlertsManagerContext");
var _makeAlertsManager = require("./makeAlertsManager");
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; }
const AlertsProvider = (_ref) => {
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; }
const AlertsProvider = _ref => {
let {

@@ -31,3 +24,4 @@ plugin,

return /*#__PURE__*/_react.default.createElement(_AlertsManagerContext.AlertsManagerContext.Provider, {
value: { ...alertsManager,
value: {
...alertsManager,
parentAlertsAdd,

@@ -40,3 +34,2 @@ showAlertsInPlugin

};
exports.AlertsProvider = AlertsProvider;

@@ -30,9 +30,5 @@ "use strict";

});
var _AlertsProvider = require("./AlertsProvider");
var _useAlerts = require("./useAlerts");
var _useAlert = require("./useAlert");
var _AlertsManagerContext = require("./AlertsManagerContext");

@@ -7,14 +7,11 @@ "use strict";

exports.makeAlertsManager = void 0;
const toVisibleAlertsArray = alertsMap => Array.from(alertsMap.values());
const makeAlertsManager = (setAlerts, plugin) => {
const alertsMap = new Map();
let id = 0;
const add = (alert, alertRef) => {
var _alertRef$current$id, _alertRef$current;
const alertId = (_alertRef$current$id = (_alertRef$current = alertRef.current) === null || _alertRef$current === void 0 ? void 0 : _alertRef$current.id) !== null && _alertRef$current$id !== void 0 ? _alertRef$current$id : ++id;
const alertsMapAlert = { ...alert,
const alertsMapAlert = {
...alert,
id: alertId,

@@ -31,3 +28,2 @@ remove: () => {

};
return {

@@ -38,3 +34,2 @@ add,

};
exports.makeAlertsManager = makeAlertsManager;
"use strict";
require("@testing-library/jest-dom/extend-expect");
require("@testing-library/jest-dom");
process.on('unhandledRejection', err => {
throw err;
});

@@ -7,7 +7,4 @@ "use strict";

exports.useAlert = void 0;
var _react = require("react");
var _AlertsManagerContext = require("./AlertsManagerContext");
const useAlert = function (message) {

@@ -25,6 +22,4 @@ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

const resolvedOptions = typeof options === 'function' ? options(props) : options;
if (plugin && parentAlertsAdd && !showAlertsInPlugin) {
var _parentAlertsAdd;
// Functions passed through post-robot are asynchronous

@@ -34,3 +29,4 @@ (_parentAlertsAdd = parentAlertsAdd({

options: resolvedOptions
}, alertRef // Conditional chaining gives backwards compatibility
}, alertRef
// Conditional chaining gives backwards compatibility
// with cli-app-scripts < 12

@@ -49,3 +45,2 @@ )) === null || _parentAlertsAdd === void 0 ? void 0 : _parentAlertsAdd.then(newAlert => {

var _alertRef$current, _alertRef$current$rem;
(_alertRef$current = alertRef.current) === null || _alertRef$current === void 0 ? void 0 : (_alertRef$current$rem = _alertRef$current.remove) === null || _alertRef$current$rem === void 0 ? void 0 : _alertRef$current$rem.call(_alertRef$current);

@@ -58,3 +53,2 @@ }, []);

};
exports.useAlert = useAlert;

@@ -7,11 +7,7 @@ "use strict";

exports.useAlerts = void 0;
var _react = require("react");
var _AlertsContext = require("./AlertsContext");
const useAlerts = () => {
return (0, _react.useContext)(_AlertsContext.AlertsContext);
};
exports.useAlerts = useAlerts;

@@ -1,2 +0,2 @@

import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import React from 'react';

@@ -6,3 +6,3 @@ import { AlertsProvider, useAlerts, useAlert } from '../index';

it('Can add an alert with static arguments', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {

@@ -13,3 +13,2 @@ children

};
const {

@@ -46,3 +45,3 @@ result

it('Can add an alert with dynamic arguments', () => {
const wrapper = (_ref2) => {
const wrapper = _ref2 => {
let {

@@ -53,3 +52,2 @@ children

};
const {

@@ -61,3 +59,3 @@ result

show
} = useAlert((_ref3) => {
} = useAlert(_ref3 => {
let {

@@ -67,3 +65,3 @@ username

return `Successfully deleted ${username}`;
}, (_ref4) => {
}, _ref4 => {
let {

@@ -103,3 +101,3 @@ isCurrentUser

it('Can remove an alert with the hide function from useAlerts', () => {
const wrapper = (_ref5) => {
const wrapper = _ref5 => {
let {

@@ -110,3 +108,2 @@ children

};
const {

@@ -148,3 +145,3 @@ result

it('Can remove an alert with the remove function on the alert itself', () => {
const wrapper = (_ref6) => {
const wrapper = _ref6 => {
let {

@@ -155,3 +152,2 @@ children

};
const {

@@ -193,3 +189,3 @@ result

it('Will not create duplicate alerts because of rerenders', () => {
const wrapper = (_ref7) => {
const wrapper = _ref7 => {
let {

@@ -200,3 +196,2 @@ children

};
const hook = renderHook(() => {

@@ -224,3 +219,3 @@ const alerts = useAlerts();

it('Will not create duplicate alerts when show is called multiple times in a render cycle', () => {
const wrapper = (_ref8) => {
const wrapper = _ref8 => {
let {

@@ -231,3 +226,2 @@ children

};
const {

@@ -256,3 +250,3 @@ result

it('Will update the alert if show is called with different arguments', () => {
const wrapper = (_ref9) => {
const wrapper = _ref9 => {
let {

@@ -263,3 +257,2 @@ children

};
const {

@@ -271,3 +264,3 @@ result

show
} = useAlert((_ref10) => {
} = useAlert(_ref10 => {
let {

@@ -277,3 +270,3 @@ message

return message;
}, (_ref11) => {
}, _ref11 => {
let {

@@ -290,4 +283,4 @@ options

wrapper
}); // Show alert for first time
});
// Show alert for first time
const payload1 = {

@@ -304,9 +297,12 @@ message: 'Message 1',

expect(result.current.alerts).toHaveLength(1);
expect(result.current.alerts[0]).toEqual({ ...payload1,
expect(result.current.alerts[0]).toEqual({
...payload1,
id: 1,
remove: expect.any(Function),
options: { ...payload1.options
options: {
...payload1.options
}
}); // Show alert for second time
});
// Show alert for second time
const payload2 = {

@@ -322,6 +318,8 @@ message: 'Message 2',

expect(result.current.alerts).toHaveLength(1);
expect(result.current.alerts[0]).toEqual({ ...payload2,
expect(result.current.alerts[0]).toEqual({
...payload2,
id: 1,
remove: expect.any(Function),
options: { ...payload2.options
options: {
...payload2.options
}

@@ -331,3 +329,3 @@ });

it('Will increment IDs when multiple alerts are added', () => {
const wrapper = (_ref12) => {
const wrapper = _ref12 => {
let {

@@ -338,3 +336,2 @@ children

};
const {

@@ -373,3 +370,3 @@ result

it('Removes the correct item from the alerts array', () => {
const wrapper = (_ref13) => {
const wrapper = _ref13 => {
let {

@@ -380,3 +377,2 @@ children

};
const {

@@ -412,3 +408,3 @@ result

it('Gets added into a new slot when show is called after hide', () => {
const wrapper = (_ref14) => {
const wrapper = _ref14 => {
let {

@@ -419,3 +415,2 @@ children

};
const {

@@ -451,8 +446,8 @@ result

expect(result.current.alerts).toHaveLength(2);
expect(result.current.alerts[0].id).toBe(2); // now is last item with id 3 because it was "re-added"
expect(result.current.alerts[0].id).toBe(2);
// now is last item with id 3 because it was "re-added"
expect(result.current.alerts[1].id).toBe(3);
});
it('Gets added into a new slot when show is called after remove is called on an alert', () => {
const wrapper = (_ref15) => {
const wrapper = _ref15 => {
let {

@@ -463,3 +458,2 @@ children

};
const {

@@ -495,6 +489,6 @@ result

expect(result.current.alerts).toHaveLength(2);
expect(result.current.alerts[0].id).toBe(2); // now is last item with id 3 because it was "re-added"
expect(result.current.alerts[0].id).toBe(2);
// now is last item with id 3 because it was "re-added"
expect(result.current.alerts[1].id).toBe(3);
});
});

@@ -1,2 +0,2 @@

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import React from 'react';

@@ -6,3 +6,3 @@ import { AlertsProvider, useAlert } from '../index';

it('Hook returns a show and hide function', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {

@@ -13,3 +13,2 @@ children

};
const {

@@ -16,0 +15,0 @@ result

@@ -1,2 +0,2 @@

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import React from 'react';

@@ -6,3 +6,3 @@ import { AlertsProvider, useAlerts } from '../index';

it('Renders without crashing', () => {
const wrapper = (_ref) => {
const wrapper = _ref => {
let {

@@ -13,3 +13,2 @@ children

};
const {

@@ -16,0 +15,0 @@ result

import React from 'react';
const placeholder = () => {
throw new Error('This function is a placeholder used when creating the AlertsManagerContext, it should be overridden');
};
const defaultAlertsManager = {

@@ -8,0 +6,0 @@ add: placeholder,

@@ -5,3 +5,3 @@ import React, { useState } from 'react';

import { makeAlertsManager } from './makeAlertsManager';
export const AlertsProvider = (_ref) => {
export const AlertsProvider = _ref => {
let {

@@ -16,3 +16,4 @@ plugin,

return /*#__PURE__*/React.createElement(AlertsManagerContext.Provider, {
value: { ...alertsManager,
value: {
...alertsManager,
parentAlertsAdd,

@@ -19,0 +20,0 @@ showAlertsInPlugin

const toVisibleAlertsArray = alertsMap => Array.from(alertsMap.values());
export const makeAlertsManager = (setAlerts, plugin) => {
const alertsMap = new Map();
let id = 0;
const add = (alert, alertRef) => {
var _alertRef$current$id, _alertRef$current;
const alertId = (_alertRef$current$id = (_alertRef$current = alertRef.current) === null || _alertRef$current === void 0 ? void 0 : _alertRef$current.id) !== null && _alertRef$current$id !== void 0 ? _alertRef$current$id : ++id;
const alertsMapAlert = { ...alert,
const alertsMapAlert = {
...alert,
id: alertId,

@@ -23,3 +21,2 @@ remove: () => {

};
return {

@@ -26,0 +23,0 @@ add,

@@ -1,4 +0,4 @@

import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';
process.on('unhandledRejection', err => {
throw err;
});

@@ -15,6 +15,4 @@ import { useContext, useRef, useCallback } from 'react';

const resolvedOptions = typeof options === 'function' ? options(props) : options;
if (plugin && parentAlertsAdd && !showAlertsInPlugin) {
var _parentAlertsAdd;
// Functions passed through post-robot are asynchronous

@@ -24,3 +22,4 @@ (_parentAlertsAdd = parentAlertsAdd({

options: resolvedOptions
}, alertRef // Conditional chaining gives backwards compatibility
}, alertRef
// Conditional chaining gives backwards compatibility
// with cli-app-scripts < 12

@@ -39,3 +38,2 @@ )) === null || _parentAlertsAdd === void 0 ? void 0 : _parentAlertsAdd.then(newAlert => {

var _alertRef$current, _alertRef$current$rem;
(_alertRef$current = alertRef.current) === null || _alertRef$current === void 0 ? void 0 : (_alertRef$current$rem = _alertRef$current.remove) === null || _alertRef$current$rem === void 0 ? void 0 : _alertRef$current$rem.call(_alertRef$current);

@@ -42,0 +40,0 @@ }, []);

import { MutableRefObject } from 'react';
export declare type AlertOptions = Record<string, unknown>;
export declare type Alert = {
export type AlertOptions = Record<string, unknown>;
export type Alert = {
id?: number;

@@ -9,5 +9,5 @@ remove?: () => void;

};
export declare type AlertRef = MutableRefObject<Alert | null>;
export declare type AlertsMap = Map<number, Alert>;
export declare type AlertsManager = {
export type AlertRef = MutableRefObject<Alert | null>;
export type AlertsMap = Map<number, Alert>;
export type AlertsManager = {
add: (alert: Alert, alertRef: AlertRef) => Alert;

@@ -14,0 +14,0 @@ plugin: boolean;

{
"name": "@dhis2/app-service-alerts",
"version": "3.11.3",
"version": "3.12.0-alpha.1",
"main": "./build/cjs/index.js",

@@ -26,4 +26,4 @@ "module": "./build/es/index.js",

"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"react": "^16.8.6 || ^18",
"react-dom": "^16.8.6 || ^18"
},

@@ -30,0 +30,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc