@digitaldefiance/express-suite-react-components 5.0.1 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/express-suite-react-components",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"homepage": "https://github.com/Digital-Defiance/react-components",
|
|
5
5
|
"description": "React MUI components for Digital Defiance Express Suite",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prettier:fix": "prettier --write 'src/**/*.{ts,tsx}'",
|
|
25
25
|
"format": "npx nx format:write --projects=digitaldefiance-express-suite-react-components",
|
|
26
26
|
"format:check": "npx nx format:check --projects=digitaldefiance-express-suite-react-components",
|
|
27
|
-
"prepublishOnly": "
|
|
27
|
+
"prepublishOnly": "node -e \"if(!require('fs').existsSync('src/index.js')){console.error('Do not publish from the source package. Run: nx build digitaldefiance-express-suite-react-components, then npm publish from dist/packages/digitaldefiance-express-suite-react-components');process.exit(1)}\"",
|
|
28
28
|
"publish:public": "npm publish --access public"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -6,6 +6,14 @@ interface MenuProviderProps {
|
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
menuConfigs?: IMenuConfig[];
|
|
8
8
|
enableBackupCodes?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* IDs of menu options to suppress from every menu. Matches both the built-in
|
|
11
|
+
* options (e.g. 'change-password', 'user-settings', 'logout') and any option
|
|
12
|
+
* registered via `menuConfigs`. Dividers left orphaned by the removal are
|
|
13
|
+
* cleaned up automatically. Defaults to none hidden, so existing consumers are
|
|
14
|
+
* unaffected.
|
|
15
|
+
*/
|
|
16
|
+
hiddenMenuIds?: readonly string[];
|
|
9
17
|
}
|
|
10
18
|
interface MenuContextType {
|
|
11
19
|
menuOptions: IMenuOption[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuContext.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/MenuContext.tsx"],"names":[],"mappings":"AAqBA,OAAO,EACL,EAAE,EACF,SAAS,EAQV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAa,MAAM,mBAAmB,CAAC;AAMxD,UAAU,iBAAiB;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MenuContext.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/MenuContext.tsx"],"names":[],"mappings":"AAqBA,OAAO,EACL,EAAE,EACF,SAAS,EAQV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAa,MAAM,mBAAmB,CAAC;AAMxD,UAAU,iBAAiB;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,UAAU,eAAe;IACvB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,cAAc,EAAE,CACd,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,OAAO,KACrB,WAAW,EAAE,CAAC;IACnB,kBAAkB,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,MAAM,IAAI,CAAC;IACxD,mBAAmB,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,IAAI,CAAC;IAC5D,WAAW,EAAE,MAAM,KAAK,CAAC,WAAW,CAAC,CAAC;CACvC;AAID,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CA4V9C,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,eAM1B,CAAC"}
|
|
@@ -14,7 +14,7 @@ const I18nProvider_1 = require("./I18nProvider");
|
|
|
14
14
|
const SuiteConfigProvider_1 = require("./SuiteConfigProvider");
|
|
15
15
|
const ThemeProvider_1 = require("./ThemeProvider");
|
|
16
16
|
const MenuContext = (0, react_1.createContext)(undefined);
|
|
17
|
-
const MenuProvider = ({ children, menuConfigs = [], enableBackupCodes = true, }) => {
|
|
17
|
+
const MenuProvider = ({ children, menuConfigs = [], enableBackupCodes = true, hiddenMenuIds = [], }) => {
|
|
18
18
|
const { userData: user, isAuthenticated, admin: isGlobalAdmin, mnemonic, clearMnemonic, wallet, clearWallet, } = (0, AuthProvider_1.useAuth)();
|
|
19
19
|
const { mode: colorMode } = (0, ThemeProvider_1.useTheme)();
|
|
20
20
|
const registeredMenuOptions = (0, react_1.useRef)(new Set());
|
|
@@ -210,7 +210,11 @@ const MenuProvider = ({ children, menuConfigs = [], enableBackupCodes = true, })
|
|
|
210
210
|
enableBackupCodes,
|
|
211
211
|
]);
|
|
212
212
|
const getMenuOptions = (0, react_1.useCallback)((menuType, includeDividers) => {
|
|
213
|
+
const hidden = new Set(hiddenMenuIds);
|
|
213
214
|
const MenuFilter = (o) => {
|
|
215
|
+
// Suppress any option whose id the consumer asked to hide.
|
|
216
|
+
if (hidden.has(o.id))
|
|
217
|
+
return false;
|
|
214
218
|
// Apply the custom filter first
|
|
215
219
|
let customFilterPasses = true;
|
|
216
220
|
if (o.filter !== undefined) {
|
|
@@ -225,8 +229,21 @@ const MenuProvider = ({ children, menuConfigs = [], enableBackupCodes = true, })
|
|
|
225
229
|
return (o.includeOnMenus.includes(menuType) &&
|
|
226
230
|
(o.requiresAuth === undefined || o.requiresAuth === isAuthenticated));
|
|
227
231
|
};
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
const filtered = menuOptions.filter(MenuFilter);
|
|
233
|
+
// Drop dividers left orphaned once hidden items are removed: a divider at
|
|
234
|
+
// the start or end of the list, or immediately following another divider,
|
|
235
|
+
// carries no meaning and would show as a stray separator.
|
|
236
|
+
return filtered.filter((o, i) => {
|
|
237
|
+
if (o.divider !== true)
|
|
238
|
+
return true;
|
|
239
|
+
const prev = filtered[i - 1];
|
|
240
|
+
if (prev === undefined || prev.divider === true)
|
|
241
|
+
return false;
|
|
242
|
+
if (i === filtered.length - 1)
|
|
243
|
+
return false;
|
|
244
|
+
return true;
|
|
245
|
+
});
|
|
246
|
+
}, [hiddenMenuIds, isAuthenticated, isGlobalAdmin, menuOptions]);
|
|
230
247
|
(0, react_1.useEffect)(() => {
|
|
231
248
|
if (menuConfigs.length > 0) {
|
|
232
249
|
return registerMenuOptions(menuConfigs.flatMap((config) => config.options));
|