Skip to content

Commit

Permalink
STCOR-867 Add permission display names lookup table to Redux (#1505)
Browse files Browse the repository at this point in the history
* Add permission display names lookup table to Redux

* Sonar fixes
  • Loading branch information
ryandberger authored Jul 22, 2024
1 parent f93f21d commit f150e29
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/discoverServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
]);
};
Expand All @@ -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));
Expand Down Expand Up @@ -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, {
Expand Down
20 changes: 20 additions & 0 deletions src/discoverServices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f150e29

Please sign in to comment.