@dhis2/app-service-alerts
Advanced tools
Comparing version 3.9.0 to 3.10.0-alpha.1
@@ -17,3 +17,6 @@ "use strict"; | ||
const defaultAlertsManager = { | ||
add: placeholder | ||
add: placeholder, | ||
plugin: false, | ||
parentAlertsAdd: null, | ||
showAlertsInPlugin: false | ||
}; | ||
@@ -20,0 +23,0 @@ |
@@ -22,8 +22,14 @@ "use strict"; | ||
let { | ||
plugin, | ||
parentAlertsAdd, | ||
showAlertsInPlugin, | ||
children | ||
} = _ref; | ||
const [alerts, setAlerts] = (0, _react.useState)([]); | ||
const [alertsManager] = (0, _react.useState)(() => (0, _makeAlertsManager.makeAlertsManager)(setAlerts)); | ||
const [alertsManager] = (0, _react.useState)(() => (0, _makeAlertsManager.makeAlertsManager)(setAlerts, plugin)); | ||
return /*#__PURE__*/_react.default.createElement(_AlertsManagerContext.AlertsManagerContext.Provider, { | ||
value: alertsManager | ||
value: { ...alertsManager, | ||
parentAlertsAdd, | ||
showAlertsInPlugin | ||
} | ||
}, /*#__PURE__*/_react.default.createElement(_AlertsContext.AlertsContext.Provider, { | ||
@@ -30,0 +36,0 @@ value: alerts |
@@ -6,2 +6,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "AlertsManagerContext", { | ||
enumerable: true, | ||
get: function () { | ||
return _AlertsManagerContext.AlertsManagerContext; | ||
} | ||
}); | ||
Object.defineProperty(exports, "AlertsProvider", { | ||
@@ -30,2 +36,4 @@ enumerable: true, | ||
var _useAlert = require("./useAlert"); | ||
var _useAlert = require("./useAlert"); | ||
var _AlertsManagerContext = require("./AlertsManagerContext"); |
@@ -10,3 +10,3 @@ "use strict"; | ||
const makeAlertsManager = setAlerts => { | ||
const makeAlertsManager = (setAlerts, plugin) => { | ||
const alertsMap = new Map(); | ||
@@ -33,3 +33,4 @@ let id = 0; | ||
return { | ||
add | ||
add, | ||
plugin | ||
}; | ||
@@ -36,0 +37,0 @@ }; |
@@ -15,3 +15,6 @@ "use strict"; | ||
const { | ||
add | ||
add, | ||
plugin, | ||
parentAlertsAdd, | ||
showAlertsInPlugin | ||
} = (0, _react.useContext)(_AlertsManagerContext.AlertsManagerContext); | ||
@@ -22,7 +25,15 @@ const alertRef = (0, _react.useRef)(null); | ||
const resolvedOptions = typeof options === 'function' ? options(props) : options; | ||
alertRef.current = add({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
}, [add, message, options]); | ||
if (plugin && parentAlertsAdd && !showAlertsInPlugin) { | ||
alertRef.current = parentAlertsAdd({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
} else { | ||
alertRef.current = add({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
} | ||
}, [add, parentAlertsAdd, message, options, plugin, showAlertsInPlugin]); | ||
const hide = (0, _react.useCallback)(() => { | ||
@@ -29,0 +40,0 @@ var _alertRef$current, _alertRef$current$rem; |
@@ -8,4 +8,7 @@ import React from 'react'; | ||
const defaultAlertsManager = { | ||
add: placeholder | ||
add: placeholder, | ||
plugin: false, | ||
parentAlertsAdd: null, | ||
showAlertsInPlugin: false | ||
}; | ||
export const AlertsManagerContext = /*#__PURE__*/React.createContext(defaultAlertsManager); |
@@ -7,8 +7,14 @@ import React, { useState } from 'react'; | ||
let { | ||
plugin, | ||
parentAlertsAdd, | ||
showAlertsInPlugin, | ||
children | ||
} = _ref; | ||
const [alerts, setAlerts] = useState([]); | ||
const [alertsManager] = useState(() => makeAlertsManager(setAlerts)); | ||
const [alertsManager] = useState(() => makeAlertsManager(setAlerts, plugin)); | ||
return /*#__PURE__*/React.createElement(AlertsManagerContext.Provider, { | ||
value: alertsManager | ||
value: { ...alertsManager, | ||
parentAlertsAdd, | ||
showAlertsInPlugin | ||
} | ||
}, /*#__PURE__*/React.createElement(AlertsContext.Provider, { | ||
@@ -15,0 +21,0 @@ value: alerts |
export { AlertsProvider } from './AlertsProvider'; | ||
export { useAlerts } from './useAlerts'; | ||
export { useAlert } from './useAlert'; | ||
export { useAlert } from './useAlert'; | ||
export { AlertsManagerContext } from './AlertsManagerContext'; |
const toVisibleAlertsArray = alertsMap => Array.from(alertsMap.values()); | ||
export const makeAlertsManager = setAlerts => { | ||
export const makeAlertsManager = (setAlerts, plugin) => { | ||
const alertsMap = new Map(); | ||
@@ -25,4 +25,5 @@ let id = 0; | ||
return { | ||
add | ||
add, | ||
plugin | ||
}; | ||
}; |
@@ -6,3 +6,6 @@ import { useContext, useRef, useCallback } from 'react'; | ||
const { | ||
add | ||
add, | ||
plugin, | ||
parentAlertsAdd, | ||
showAlertsInPlugin | ||
} = useContext(AlertsManagerContext); | ||
@@ -13,7 +16,15 @@ const alertRef = useRef(null); | ||
const resolvedOptions = typeof options === 'function' ? options(props) : options; | ||
alertRef.current = add({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
}, [add, message, options]); | ||
if (plugin && parentAlertsAdd && !showAlertsInPlugin) { | ||
alertRef.current = parentAlertsAdd({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
} else { | ||
alertRef.current = add({ | ||
message: resolvedMessage, | ||
options: resolvedOptions | ||
}, alertRef); | ||
} | ||
}, [add, parentAlertsAdd, message, options, plugin, showAlertsInPlugin]); | ||
const hide = useCallback(() => { | ||
@@ -20,0 +31,0 @@ var _alertRef$current, _alertRef$current$rem; |
import React, { ReactElement } from 'react'; | ||
export declare const AlertsProvider: ({ children, }: { | ||
export declare const AlertsProvider: ({ plugin, parentAlertsAdd, showAlertsInPlugin, children, }: { | ||
plugin: boolean; | ||
parentAlertsAdd: any; | ||
showAlertsInPlugin: boolean; | ||
children: React.ReactNode; | ||
}) => ReactElement; |
export { AlertsProvider } from './AlertsProvider'; | ||
export { useAlerts } from './useAlerts'; | ||
export { useAlert } from './useAlert'; | ||
export { AlertsManagerContext } from './AlertsManagerContext'; |
import type { Alert, AlertsManager } from './types'; | ||
export declare const makeAlertsManager: (setAlerts: React.Dispatch<React.SetStateAction<Alert[]>>) => AlertsManager; | ||
export declare const makeAlertsManager: (setAlerts: React.Dispatch<React.SetStateAction<Alert[]>>, plugin: boolean) => AlertsManager; |
@@ -13,2 +13,5 @@ import { MutableRefObject } from 'react'; | ||
add: (alert: Alert, alertRef: AlertRef) => Alert; | ||
plugin: boolean; | ||
parentAlertsAdd?: any; | ||
showAlertsInPlugin?: boolean; | ||
}; |
{ | ||
"name": "@dhis2/app-service-alerts", | ||
"version": "3.9.0", | ||
"version": "3.10.0-alpha.1", | ||
"main": "./build/cjs/index.js", | ||
@@ -5,0 +5,0 @@ "module": "./build/es/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40528
1302
2