From f150e29dff4404319cf2ed7f6300da40dec9eebb Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Mon, 22 Jul 2024 11:31:06 -0400 Subject: [PATCH] STCOR-867 Add permission display names lookup table to Redux (#1505) * Add permission display names lookup table to Redux * Sonar fixes --- src/discoverServices.js | 17 +++++++++++++++-- src/discoverServices.test.js | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/discoverServices.js b/src/discoverServices.js index 6ea2a63b9..0da05c8a9 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,12 +43,17 @@ function parseApplicationDescriptor(store, descriptor) { data: descriptor.moduleDescriptors, }) ); + if (descriptor.moduleDescriptors) { - list.push(...descriptor.moduleDescriptors?.map((i) => dispatchDescriptor(i))); + 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))); + list.push(...descriptor.uiModules.map((i) => dispatchDescriptor(i))); } list.push(dispatchApplication(descriptor)); @@ -286,6 +292,13 @@ 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 { permissionDisplayNames: { ...state.permissionDisplayNames, ...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'