Skip to content

Commit

Permalink
Add permission display names lookup table to Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandberger committed Jul 17, 2024
1 parent f93f21d commit 6781351
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 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,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)));
}
Expand Down Expand Up @@ -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, {
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 6781351

Please sign in to comment.