Skip to content

Commit ef338cd

Browse files
committed
feat: addressed comments
1 parent ca8a51d commit ef338cd

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

src/utils/flexipage/flexiPageTransformer.ts

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import {
1414
} from '../../migration/interfaces';
1515
import { StorageUtil } from '../storageUtil';
1616

17-
/** Attributes to remove during transformation */
18-
const attrsToRemove = ['target'];
19-
2017
/** Component name to look for during transformation */
2118
const lookupComponentName = 'vlocityLWCOmniWrapper';
2219
/** Target component name after transformation */
@@ -52,16 +49,6 @@ export function transformFlexipageBundle(
5249
const bundle: Flexipage = JSON.parse(JSON.stringify(ogBundle)) as Flexipage;
5350
let changes = false;
5451

55-
/**
56-
* Filters out properties that should be removed during transformation
57-
*
58-
* @param item - The component instance property to check
59-
* @returns true if the property should be kept, false if it should be removed
60-
*/
61-
const propRemover = (item: FlexiComponentInstanceProperty): boolean => {
62-
return !attrsToRemove.includes(item.name);
63-
};
64-
6552
for (const region of bundle.flexiPageRegions) {
6653
if (!region.itemInstances) {
6754
continue;
@@ -80,18 +67,19 @@ export function transformFlexipageBundle(
8067
if (!typeSubtypeLanguage) {
8168
throw new TargetPropertyNotFoundError(item.componentInstance.componentName);
8269
}
83-
const newProps = createNewProps(typeSubtypeLanguage.split(':')[1], namespace, mode);
84-
const targetComponentName = newProps.componentName;
85-
const targetIdentifier = newProps.identifier;
86-
delete newProps.componentName;
87-
delete newProps.identifier;
88-
const leftProps = item.componentInstance.componentInstanceProperties?.filter?.(propRemover) ?? [];
89-
const replacedProps = [
90-
...leftProps,
91-
...Object.entries(newProps).map(([key, value]: [string, string]) => ({ name: key, value })),
92-
];
70+
const newPropsWithComponentNameAndIdentifier = createNewProps(
71+
typeSubtypeLanguage.split(':')[1],
72+
namespace,
73+
mode,
74+
item.componentInstance.componentInstanceProperties
75+
);
76+
const newProps = newPropsWithComponentNameAndIdentifier.props;
77+
const targetComponentName = newPropsWithComponentNameAndIdentifier.componentName;
78+
const targetIdentifier = newPropsWithComponentNameAndIdentifier.identifier;
9379
changes = true;
94-
item.componentInstance.componentInstanceProperties = replacedProps;
80+
item.componentInstance.componentInstanceProperties = Object.entries(newProps).map(
81+
([key, value]: [string, string]) => ({ name: key, value })
82+
);
9583
item.componentInstance.componentName = targetComponentName;
9684
item.componentInstance.identifier = targetIdentifier;
9785
}
@@ -108,24 +96,24 @@ export function transformFlexipageBundle(
10896
* @returns Object containing the new properties for the transformed component
10997
*/
11098
// eslint-disable-next-line @typescript-eslint/no-unused-vars
111-
function createNewProps(nameKey: string, namespace: string, mode: 'assess' | 'migrate'): Record<string, string> {
99+
function createNewProps(
100+
nameKey: string,
101+
namespace: string,
102+
mode: 'assess' | 'migrate',
103+
componentInstanceProperties: FlexiComponentInstanceProperty[]
104+
): { componentName: string; identifier: string; props: Record<string, string> } {
112105
if (nameKey.startsWith(flexCardPrefix)) {
113106
return createNewPropsForFlexCard(nameKey.substring(flexCardPrefix.length), namespace, mode);
114107
}
115-
return createNewPropsForOmniScript(nameKey, namespace, mode);
116-
// return {
117-
// language: 'English',
118-
// subType: 'OSForCustomLWC',
119-
// theme: 'lightning',
120-
// type: 'OSForCustomLWC',
121-
// };
108+
return createNewPropsForOmniScript(nameKey, namespace, mode, componentInstanceProperties);
122109
}
123110

124111
function createNewPropsForOmniScript(
125112
nameKey: string,
126113
namespace: string,
127-
mode: 'assess' | 'migrate'
128-
): Record<string, string> {
114+
mode: 'assess' | 'migrate',
115+
componentInstanceProperties: FlexiComponentInstanceProperty[]
116+
): { componentName: string; identifier: string; props: Record<string, string> } {
129117
let migratedScriptName: OmniScriptStorage;
130118
if (mode === 'assess') {
131119
migratedScriptName = StorageUtil.getOmnistudioAssessmentStorage().osStorage.get(nameKey);
@@ -141,24 +129,29 @@ function createNewPropsForOmniScript(
141129
throw new DuplicateKeyError(nameKey, 'OmniScript');
142130
}
143131

144-
return {
145-
componentName: targetComponentNameOS,
146-
identifier: targetIdentifierOS,
132+
const newProps = {
147133
language: migratedScriptName.language || 'English',
148134
subType: migratedScriptName.subtype,
149135
type: migratedScriptName.type,
150-
theme: 'OSForCustomLWC',
151-
direction: 'ltr',
152-
display: 'Display button to open Omniscript',
136+
theme: componentInstanceProperties.find((prop) => prop.name === 'layout')?.value || 'lightning',
153137
inlineVariant: 'brand',
138+
inlineLabel: '',
139+
display: 'Display OmniScript on page',
140+
direction: 'ltr',
141+
};
142+
143+
return {
144+
componentName: targetComponentNameOS,
145+
identifier: targetIdentifierOS,
146+
props: newProps,
154147
};
155148
}
156149

157150
function createNewPropsForFlexCard(
158151
nameKey: string,
159152
namespace: string,
160153
mode: 'assess' | 'migrate'
161-
): Record<string, string> {
154+
): { componentName: string; identifier: string; props: Record<string, string> } {
162155
let migratedCardName: FlexcardStorage;
163156
if (mode === 'assess') {
164157
migratedCardName = StorageUtil.getOmnistudioAssessmentStorage().fcStorage.get(nameKey);
@@ -174,11 +167,13 @@ function createNewPropsForFlexCard(
174167
throw new DuplicateKeyError(nameKey, 'Flexcard');
175168
}
176169

170+
const newProps = {
171+
flexcardName: migratedCardName.name,
172+
};
173+
177174
return {
178175
componentName: targetComponentNameFlexCard,
179176
identifier: targetIdentifierFlexCard,
180-
flexcardName: migratedCardName.name,
181-
objectApiName: '{!objectApiName}',
182-
recordId: '{!recordId}',
177+
props: newProps,
183178
};
184179
}

test/utils/flexipage/flexiPageTransformer.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ describe('transformFlexipageBundle', () => {
7878
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'type')).to.exist;
7979
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'subType')).to.exist;
8080
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'theme')).to.exist;
81-
// Should keep other properties
82-
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'other')).to.exist;
81+
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'inlineVariant')).to.exist;
82+
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'inlineLabel')).to.exist;
83+
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'display')).to.exist;
84+
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'direction')).to.exist;
85+
// Should not keep other properties (implementation replaces all properties)
86+
expect(item.componentInstance.componentInstanceProperties.find((p) => p.name === 'other')).to.be.undefined;
8387
});
8488

8589
it('returns false if no matching component', () => {

0 commit comments

Comments
 (0)