Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feo modules spec merging #2137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions navnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ Same as `bundleSegmentRef`, but for global segments.
### frontendRef

Required to match nav item in bundle to current app

# Search interceptor notes

## frontendRef

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

# Service tiles interceptor

## 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
139 changes: 139 additions & 0 deletions packages/config-utils/src/feo/feo-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
export type SupportCaseData = {
version: string;
product: string;
};

export type ChromeGlobalModuleConfig = {
supportCaseData?: SupportCaseData;
ssoScopes?: string[];
};

export type ChromePermissions = {
method: string;
apps?: string[];
args?: unknown[];
};

export type ChromeEntryModuleRoute = {
pathname: string;
exact?: boolean;
props?: object;
supportCaseData?: SupportCaseData;
permissions?: ChromePermissions;
};

export type ChromeEntryModule = {
id: string;
module: string;
routes: ChromeEntryModuleRoute[];
};

type ChromeModuleAnalytics = {
APIKey: string;
};

export type ChromeModule = {
manifestLocation: string;
defaultDocumentTitle?: string;
/**
* @deprecated
* use `moduleConfig` instead
*/
config?: object;
moduleConfig?: ChromeGlobalModuleConfig;
modules?: ChromeEntryModule[];
/**
* @deprecated
* Use feo generated resources to get permitted modules
*/
isFedramp?: boolean;
analytics?: ChromeModuleAnalytics;
};

export type ChromeModuleRegistry = {
[moduleName: string]: ChromeModule;
};

export type ChromeStaticSearchEntry = {
frontendRef: string;
id: string;
href: string;
title: string;
description: string;
alt_title?: string[];
isExternal?: boolean;
};

export type SegmentRef = {
segmentId: string;
frontendName: string;
};

export type DirectNavItem = {
id?: string;
frontendRef?: string;
href?: string;
title?: string;
expandable?: boolean;
// should be removed
appId?: string;
routes?: DirectNavItem[];
navItems?: DirectNavItem[];
bundleSegmentRef?: string;
segmentRef?: SegmentRef;
segmentId?: string;
};

export type Nav = {
title?: string;
id: string;
navItems: DirectNavItem[];
};

export type BundleSegment = {
segmentId: string;
bundleId: string;
position: number;
navItems: DirectNavItem[];
};

export type ServiceTile = {
section: string;
group: string;
id: string;
frontendRef: string;
};

export type ServiceGroup = {
id: string;
tiles: ServiceTile[];
};

export type ServiceCategory = {
id: string;
groups: ServiceGroup[];
};

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

export type CRDObject = {
metadata: {
name: string;
};
spec: {
bundleSegments?: BundleSegment[];
navigationSegments?: DirectNavItem[];
module: ChromeModule;
searchEntries?: ChromeStaticSearchEntry[];
serviceTiles?: ServiceTile[];
widgetRegistry?: ChromeWidgetEntry[];
};
};

export type FrontendCRD = {
objects: CRDObject[];
};
61 changes: 61 additions & 0 deletions packages/config-utils/src/feo/module-interceptor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ChromeModule, ChromeModuleRegistry, FrontendCRD } from './feo-types';
import moduleInterceptor from './module-interceptor';

describe('module-interceptor', () => {
it('should replace existing entry in moduleRegistry with new entry', () => {
const moduleName = 'module-name';
const newEntry: ChromeModule = {
manifestLocation: 'new-location',
};
const frontendCRD: FrontendCRD = {
objects: [
{
metadata: {
name: moduleName,
},
spec: {
module: newEntry,
},
},
],
};
const remoteModuleRegistry: ChromeModuleRegistry = {
[moduleName]: {
manifestLocation: 'old-location',
},
};
const expectedResult: ChromeModuleRegistry = {
[moduleName]: newEntry,
};

const result = moduleInterceptor(remoteModuleRegistry, frontendCRD);
expect(result).toEqual(expectedResult);
});

it('should add new entry to moduleRegistry', () => {
const moduleName = 'module-name';
const newEntry: ChromeModule = {
manifestLocation: 'new-location',
};
const frontendCRD: FrontendCRD = {
objects: [
{
metadata: {
name: moduleName,
},
spec: {
module: newEntry,
},
},
],
};
const remoteModuleRegistry: ChromeModuleRegistry = {};

const expectedResult: ChromeModuleRegistry = {
[moduleName]: newEntry,
};

const result = moduleInterceptor(remoteModuleRegistry, frontendCRD);
expect(result).toEqual(expectedResult);
});
});
11 changes: 11 additions & 0 deletions packages/config-utils/src/feo/module-interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ChromeModuleRegistry, FrontendCRD } from './feo-types';

function moduleInterceptor(moduleRegistry: ChromeModuleRegistry, frontendCRD: FrontendCRD): ChromeModuleRegistry {
const moduleName = frontendCRD.objects[0].metadata.name;
return {
...moduleRegistry,
[moduleName]: frontendCRD.objects[0].spec.module,
};
}

export default moduleInterceptor;
Loading