-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feo): add widget rehistry interceptor
- Loading branch information
1 parent
cd2c515
commit fe91199
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/config-utils/src/feo/widget-registry-interceptor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
packages/config-utils/src/feo/widget-registry-interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |