-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
chore: decouple widget-config.json from main chunk #36924
Changes from all commits
3e86da9
5aeea62
6501304
62284ec
32806b9
7307a7d
ae14b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,7 @@ const migrateUnversionedDSL = (currentDSL: DSLWidget) => { | |
// A rudimentary transform function which updates the DSL based on its version. | ||
// A more modular approach needs to be designed. | ||
// This needs the widget config to be already built to migrate correctly | ||
const migrateVersionedDSL = (currentDSL: DSLWidget, newPage = false) => { | ||
const migrateVersionedDSL = async (currentDSL: DSLWidget, newPage = false) => { | ||
if (currentDSL.version === 1) { | ||
if (currentDSL.children && currentDSL.children.length > 0) | ||
currentDSL.children = currentDSL.children.map(updateContainers); | ||
|
@@ -205,7 +205,7 @@ const migrateVersionedDSL = (currentDSL: DSLWidget, newPage = false) => { | |
} | ||
|
||
if (currentDSL.version === 12) { | ||
currentDSL = migrateIncorrectDynamicBindingPathLists(currentDSL); | ||
currentDSL = await migrateIncorrectDynamicBindingPathLists(currentDSL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Properly handle errors when awaiting 'migrateIncorrectDynamicBindingPathLists' Awaiting the asynchronous function |
||
currentDSL.version = 13; | ||
} | ||
|
||
|
@@ -619,15 +619,15 @@ const migrateVersionedDSL = (currentDSL: DSLWidget, newPage = false) => { | |
return currentDSL; | ||
}; | ||
|
||
export const migrateDSL = ( | ||
export const migrateDSL = async ( | ||
currentDSL: DSLWidget, | ||
newPage = false, | ||
): DSLWidget => { | ||
): Promise<DSLWidget> => { | ||
Comment on lines
+622
to
+625
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure error handling in the asynchronous function 'migrateDSL' Now that |
||
if (currentDSL.version === undefined) { | ||
const initialDSL = migrateUnversionedDSL(currentDSL); | ||
|
||
return migrateVersionedDSL(initialDSL, newPage) as DSLWidget; | ||
return (await migrateVersionedDSL(initialDSL, newPage)) as DSLWidget; | ||
} else { | ||
return migrateVersionedDSL(currentDSL, newPage) as DSLWidget; | ||
return (await migrateVersionedDSL(currentDSL, newPage)) as DSLWidget; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,6 @@ import isString from "lodash/isString"; | |||||||||||||||||||||||||
import memoize from "micro-memoize"; | ||||||||||||||||||||||||||
import { isObject, isUndefined } from "lodash"; | ||||||||||||||||||||||||||
import { generateReactKey, isDynamicValue } from "../utils"; | ||||||||||||||||||||||||||
import widgetConfigs from "../helpers/widget-configs.json"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const WidgetHeightLimits = { | ||||||||||||||||||||||||||
MAX_HEIGHT_IN_ROWS: 9000, | ||||||||||||||||||||||||||
|
@@ -511,8 +510,33 @@ export function addSearchConfigToPanelConfig(config: readonly any[]) { | |||||||||||||||||||||||||
return configItem; | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
// Cache for lazy-loaded widget configurations | ||||||||||||||||||||||||||
let cachedWidgetConfigs: any | null = null; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||
Lazily load this file since it is very large and used in migrations for certain DSL versions. By lazily loading | ||||||||||||||||||||||||||
this large file it can be reduce the main chunk only be loaded for certain limited conditions. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
Comment on lines
+516
to
+519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve the clarity of the comment block The multi-line comment contains grammatical errors that could affect comprehension. Let's revise it for better readability: /*
- Lazily load this file since it is very large and used in migrations for certain DSL versions. By lazily loading
- this large file it can be reduce the main chunk only be loaded for certain limited conditions.
+ Lazily load this file since it is very large and used in migrations for certain DSL versions. By lazily loading
+ this large file, we can reduce the main chunk size, ensuring it is only loaded under certain limited conditions.
*/ 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
const loadWidgetConfig = async () => { | ||||||||||||||||||||||||||
if (!cachedWidgetConfigs) { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
const { default: widgetConfigs } = await import( | ||||||||||||||||||||||||||
"../helpers/widget-configs.json" | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
cachedWidgetConfigs = widgetConfigs; // Cache the module for future use | ||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||
log.error("Error loading WidgetConfig", e); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getWidgetPropertyPaneContentConfig = (type: string): readonly any[] => { | ||||||||||||||||||||||||||
return cachedWidgetConfigs; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getWidgetPropertyPaneContentConfig = async ( | ||||||||||||||||||||||||||
type: string, | ||||||||||||||||||||||||||
): Promise<readonly any[]> => { | ||||||||||||||||||||||||||
const widgetConfigs = await loadWidgetConfig(); | ||||||||||||||||||||||||||
const propertyPaneContentConfig = (widgetConfigs as any)[type] | ||||||||||||||||||||||||||
.propertyPaneContentConfig; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -540,7 +564,11 @@ const getWidgetPropertyPaneContentConfig = (type: string): readonly any[] => { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getWidgetPropertyPaneStyleConfig = (type: string): readonly any[] => { | ||||||||||||||||||||||||||
const getWidgetPropertyPaneStyleConfig = async ( | ||||||||||||||||||||||||||
type: string, | ||||||||||||||||||||||||||
): Promise<readonly any[]> => { | ||||||||||||||||||||||||||
const widgetConfigs = await loadWidgetConfig(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const propertyPaneStyleConfig = (widgetConfigs as any)[type] | ||||||||||||||||||||||||||
.propertyPaneStyleConfig; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Comment on lines
+570
to
574
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add null check for Just as before, we should verify that Consider adding a null check: const widgetConfigs = await loadWidgetConfig();
+ if (!widgetConfigs) {
+ throw new Error("Failed to load widget configurations");
+ }
const propertyPaneStyleConfig = (widgetConfigs as any)[type]
.propertyPaneStyleConfig; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
|
@@ -567,14 +595,20 @@ const getWidgetPropertyPaneStyleConfig = (type: string): readonly any[] => { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getWidgetPropertyPaneCombinedConfig = (type: string): readonly any[] => { | ||||||||||||||||||||||||||
const contentConfig = getWidgetPropertyPaneContentConfig(type); | ||||||||||||||||||||||||||
const styleConfig = getWidgetPropertyPaneStyleConfig(type); | ||||||||||||||||||||||||||
const getWidgetPropertyPaneCombinedConfig = async ( | ||||||||||||||||||||||||||
type: string, | ||||||||||||||||||||||||||
): Promise<readonly any[]> => { | ||||||||||||||||||||||||||
const contentConfig = await getWidgetPropertyPaneContentConfig(type); | ||||||||||||||||||||||||||
const styleConfig = await getWidgetPropertyPaneStyleConfig(type); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return [...contentConfig, ...styleConfig]; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getWidgetPropertyPaneConfig = (type: string): readonly any[] => { | ||||||||||||||||||||||||||
const getWidgetPropertyPaneConfig = async ( | ||||||||||||||||||||||||||
type: string, | ||||||||||||||||||||||||||
): Promise<readonly any[]> => { | ||||||||||||||||||||||||||
const widgetConfigs = await loadWidgetConfig(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const propertyPaneConfig = (widgetConfigs as any)[type].propertyPaneConfig; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const features = (widgetConfigs as any)[type].features; | ||||||||||||||||||||||||||
Comment on lines
+610
to
614
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add null check for Again, let's ensure that Here's the suggested modification: const widgetConfigs = await loadWidgetConfig();
+ if (!widgetConfigs) {
+ throw new Error("Failed to load widget configurations");
+ }
const propertyPaneConfig = (widgetConfigs as any)[type].propertyPaneConfig;
|
||||||||||||||||||||||||||
|
@@ -590,7 +624,7 @@ const getWidgetPropertyPaneConfig = (type: string): readonly any[] => { | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return enhancedPropertyPaneConfig; | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
const config = getWidgetPropertyPaneCombinedConfig(type); | ||||||||||||||||||||||||||
const config = await getWidgetPropertyPaneCombinedConfig(type); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (config === undefined) { | ||||||||||||||||||||||||||
log.error("Widget property pane config not defined", type); | ||||||||||||||||||||||||||
|
@@ -957,14 +991,14 @@ const getAllPathsFromPropertyConfig = memoize( | |||||||||||||||||||||||||
{ maxSize: 1000 }, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const migrateIncorrectDynamicBindingPathLists = ( | ||||||||||||||||||||||||||
export const migrateIncorrectDynamicBindingPathLists = async ( | ||||||||||||||||||||||||||
currentDSL: Readonly<DSLWidget>, | ||||||||||||||||||||||||||
): DSLWidget => { | ||||||||||||||||||||||||||
): Promise<DSLWidget> => { | ||||||||||||||||||||||||||
const migratedDsl = { | ||||||||||||||||||||||||||
...currentDSL, | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
const dynamicBindingPathList: any[] = []; | ||||||||||||||||||||||||||
const propertyPaneConfig = getWidgetPropertyPaneConfig(currentDSL.type); | ||||||||||||||||||||||||||
const propertyPaneConfig = await getWidgetPropertyPaneConfig(currentDSL.type); | ||||||||||||||||||||||||||
const { bindingPaths } = getAllPathsFromPropertyConfig( | ||||||||||||||||||||||||||
currentDSL, | ||||||||||||||||||||||||||
propertyPaneConfig, | ||||||||||||||||||||||||||
|
@@ -984,8 +1018,10 @@ export const migrateIncorrectDynamicBindingPathLists = ( | |||||||||||||||||||||||||
migratedDsl.dynamicBindingPathList = dynamicBindingPathList; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (currentDSL.children) { | ||||||||||||||||||||||||||
migratedDsl.children = currentDSL.children.map( | ||||||||||||||||||||||||||
migrateIncorrectDynamicBindingPathLists, | ||||||||||||||||||||||||||
migratedDsl.children = await Promise.all( | ||||||||||||||||||||||||||
currentDSL.children.map(async (value) => | ||||||||||||||||||||||||||
migrateIncorrectDynamicBindingPathLists(value), | ||||||||||||||||||||||||||
Comment on lines
+1022
to
+1023
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Simplify the Recall that if an arrow function doesn't use Here's the simplified code: - currentDSL.children.map(async (value) =>
+ currentDSL.children.map((value) =>
migrateIncorrectDynamicBindingPathLists(value), 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling in 'migrateVersionedDSL'
When converting
migrateVersionedDSL
into an asynchronous function, it's important to handle any potential errors that may occur during asynchronous operations. Remember, unhandled promise rejections can lead to unexpected behaviors in your application. Consider adding error handling, such as try/catch blocks, to make the function more robust.