Skip to content

Commit

Permalink
feat(feo): add widget rehistry interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Dec 16, 2024
1 parent cd2c515 commit fe91199
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions navnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ search entries need a `frontendRef` attribute. Without the attribute, we can mod
## frontendRef

Service tile entries need a `frontendRef` attribute. Without the attribute, we can modify/add frontend entries, but we can't remove them

# Widget registry interceptor

## frontendRef

Widget registry entries need a `frontendRef` attribute. Without the attribute, we can modify/add frontend entries, but we can't remove them
8 changes: 8 additions & 0 deletions packages/config-utils/src/feo/feo-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ export type ServiceCategory = {
id: string;
groups: ServiceGroup[];
};

export type ChromeWidgetEntry = {
scope: string;
module: string;
frontendRef: string;
};

export type CRDObject = {
metadata: {
name: string;
Expand All @@ -123,6 +130,7 @@ export type CRDObject = {
module: ChromeModule;
searchEntries?: ChromeStaticSearchEntry[];
serviceTiles?: ServiceTile[];
widgetRegistry?: ChromeWidgetEntry[];
};
};

Expand Down
35 changes: 35 additions & 0 deletions packages/config-utils/src/feo/widget-registry-interceptor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FrontendCRD } from './feo-types';
import widgetRegistryInterceptor from './widget-registry-interceptor';

describe('Widget registry interceptor', () => {
it('should replace the widget registry with the one from the server', () => {
const frontendName = 'name';
const widgetEntries = [
{ module: 'module1', scope: 'scope1', frontendRef: frontendName },
{ module: 'module1', scope: 'scope2', frontendRef: frontendName },
{ module: 'module2', scope: 'scope1', frontendRef: 'foo' },
];
const frontendCrd: FrontendCRD = {
objects: [
{
metadata: {
name: 'name',
},
spec: {
module: {
manifestLocation: 'location',
},
widgetRegistry: [{ module: 'module1', scope: 'scope1', frontendRef: frontendName }],
},
},
],
};

const result = widgetRegistryInterceptor(widgetEntries, frontendCrd);

expect(result).toEqual([
{ module: 'module2', scope: 'scope1', frontendRef: 'foo' },
{ module: 'module1', scope: 'scope1', frontendRef: frontendName },
]);
});
});
10 changes: 10 additions & 0 deletions packages/config-utils/src/feo/widget-registry-interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChromeWidgetEntry, FrontendCRD } from './feo-types';

function widgetRegistryInterceptor(widgetEntries: ChromeWidgetEntry[], frontendCrd: FrontendCRD): ChromeWidgetEntry[] {
const frontendName = frontendCrd.objects[0].metadata.name;
const result = widgetEntries.filter((entry) => entry.frontendRef !== frontendName);

return [...result, ...(frontendCrd.objects[0].spec.widgetRegistry ?? [])];
}

export default widgetRegistryInterceptor;

0 comments on commit fe91199

Please sign in to comment.