From 6781351259a652adc00e2f303f6ffbd98c72add1 Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Tue, 16 Jul 2024 21:42:20 -0400 Subject: [PATCH] Add permission display names lookup table to Redux --- src/discoverServices.js | 16 ++++++++++++++++ src/discoverServices.test.js | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/discoverServices.js b/src/discoverServices.js index 6ea2a63b9..cf17653bc 100644 --- a/src/discoverServices.js +++ b/src/discoverServices.js @@ -25,6 +25,7 @@ function parseApplicationDescriptor(store, descriptor) { const dispatchDescriptor = (d) => { return Promise.all([ store.dispatch({ type: 'DISCOVERY_INTERFACES', data: d }), + store.dispatch({ type: 'DISCOVERY_PERMISSION_DISPLAY_NAMES', data: d }), store.dispatch({ type: 'DISCOVERY_PROVIDERS', data: d }), ]); }; @@ -42,10 +43,15 @@ function parseApplicationDescriptor(store, descriptor) { data: descriptor.moduleDescriptors, }) ); + if (descriptor.moduleDescriptors) { list.push(...descriptor.moduleDescriptors?.map((i) => dispatchDescriptor(i))); } + if (descriptor.uiModuleDescriptors) { + list.push(...descriptor.uiModuleDescriptors?.map((i) => dispatchDescriptor(i))); + } + if (descriptor.uiModules) { list.push(...descriptor.uiModules?.map((i) => dispatchDescriptor(i))); } @@ -286,6 +292,16 @@ export function discoveryReducer(state = {}, action) { interfaces: Object.assign(state.interfaces || {}, interfaces), }); } + case 'DISCOVERY_PERMISSION_DISPLAY_NAMES': { + const permissions = {}; + for (const entry of action.data.permissionSets || []) { + permissions[entry.permissionName] = entry.displayName; + } + return Object.assign({}, state, { + permissionDisplayNames: state.permissionDisplayNames ? + Object.assign({}, state.permissionDisplayNames, permissions) : permissions, + }); + } case 'DISCOVERY_PROVIDERS': { if (action.data.provides?.length > 0) { return Object.assign({}, state, { diff --git a/src/discoverServices.test.js b/src/discoverServices.test.js index 3edbf5ebd..f1c42486f 100644 --- a/src/discoverServices.test.js +++ b/src/discoverServices.test.js @@ -140,6 +140,26 @@ describe('discoveryReducer', () => { expect(state).toMatchObject(mapped); }); + it('handles DISCOVERY_PERMISSION_DISPLAY_NAMES', () => { + let state = { + permissionDisplayNames: {} + }; + const action = { + type: 'DISCOVERY_PERMISSION_DISPLAY_NAMES', + data: { + permissionSets: [ + { 'permissionName': 'perm1', 'displayName': 'Admin Permission' }, + { 'permissionName': 'perm2', 'displayName': 'Read-only Permission' } + ] + }, + }; + + state = discoveryReducer(state, action); + + expect(state.permissionDisplayNames.perm1).toBe(action.data.permissionSets[0].displayName); + expect(state.permissionDisplayNames.perm2).toBe(action.data.permissionSets[1].displayName); + }); + it('handles DISCOVERY_OKAPI', () => { let state = { okapi: '0.0.0'