PromucFlow_constructor/app/client/src/widgets/MetaWidgetContextProvider.tsx

110 lines
3.4 KiB
TypeScript
Raw Normal View History

feat: List V2 (#15839) ## Description TL;DR This is a complete architectural change of of List widget works to support all widgets we currently have and should automatically support any future widgets. It also introduces nested List widgets i.e a list widget can have a another list widget which in turn can have another list widget. Fixes #18206 Fixes #6775 Fixes #13211 Fixes #16582 Fixes #11739 Fixes #15094 Fixes #6840 Fixes #10841 Fixes #17386 Fixes #18340 Fixes #16898 Fixes #17555 Fixes #6858 Fixes #9568 Fixes #17480 Fixes #18523 Fixes #18206 Fixes #16586 Fixes #18106 Fixes #16576 Fixes #14697 Fixes #9607 Fixes #19648 Fixes #19739 Fixes #19652 Fixes #18730 Fixes #19503 Fixes #19498 Fixes #19437 Fixes #5245 Fixes #19150 Fixes #18638 Fixes #11332 Fixes #17901 Fixes #19043 Fixes #17777 Fixes #8237 Fixes #15487 Fixes #15988 Fixes #18621 Fixes #16788 Fixes #18110 Fixes #18382 Fixes #17427 Fixes #18105 Fixes #18287 Fixes #19808 Fixes #14655 ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Cypress - Jest - Manual ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes --------- Co-authored-by: Tolulope Adetula <31691737+Tooluloope@users.noreply.github.com> Co-authored-by: Favour Ohanekwu <fohanekwu@gmail.com>
2023-02-14 16:07:31 +00:00
import React, { useContext, useMemo } from "react";
import {
EditorContext,
EditorContextType,
} from "components/editorComponents/EditorContextProvider";
type MetaWidgetContextProviderProps = React.PropsWithChildren<
EditorContextType
>;
// TODO (Ashit) - Add test for this provider
// test to always returning the exact number of functions defined in the EditorContextProvider
// so that when a new function is introduced there, one does not misses adding it here as well.
function MetaWidgetContextProvider({
children,
...metaEditorContextProps
}: MetaWidgetContextProviderProps) {
const editorContextProps = useContext(EditorContext);
if (!editorContextProps.executeAction) {
throw new Error(
"EditorContext not found - Use EditorContextProvider in a parent component.",
);
}
const executeAction =
metaEditorContextProps.executeAction ?? editorContextProps.executeAction;
const updateWidget =
metaEditorContextProps.updateWidget ?? editorContextProps.updateWidget;
const updateWidgetProperty =
metaEditorContextProps.updateWidgetProperty ??
editorContextProps.updateWidgetProperty;
const syncUpdateWidgetMetaProperty =
metaEditorContextProps.syncUpdateWidgetMetaProperty ??
editorContextProps.syncUpdateWidgetMetaProperty;
const disableDrag =
metaEditorContextProps.disableDrag ?? editorContextProps.disableDrag;
const resetChildrenMetaProperty =
metaEditorContextProps.resetChildrenMetaProperty ??
editorContextProps.resetChildrenMetaProperty;
const deleteWidgetProperty =
metaEditorContextProps.deleteWidgetProperty ??
editorContextProps.deleteWidgetProperty;
const batchUpdateWidgetProperty =
metaEditorContextProps.batchUpdateWidgetProperty ??
editorContextProps.batchUpdateWidgetProperty;
const triggerEvalOnMetaUpdate =
metaEditorContextProps.triggerEvalOnMetaUpdate ??
editorContextProps.triggerEvalOnMetaUpdate;
const modifyMetaWidgets =
metaEditorContextProps.modifyMetaWidgets ??
editorContextProps.modifyMetaWidgets;
const setWidgetCache =
metaEditorContextProps.setWidgetCache ?? editorContextProps.setWidgetCache;
const getWidgetCache =
metaEditorContextProps.getWidgetCache ?? editorContextProps.getWidgetCache;
const deleteMetaWidgets =
metaEditorContextProps.deleteMetaWidgets ??
editorContextProps.deleteMetaWidgets;
const updateMetaWidgetProperty =
metaEditorContextProps.updateMetaWidgetProperty ??
editorContextProps.updateMetaWidgetProperty;
const contextValue = useMemo(
() => ({
executeAction,
updateWidget,
updateWidgetProperty,
syncUpdateWidgetMetaProperty,
disableDrag,
resetChildrenMetaProperty,
deleteWidgetProperty,
batchUpdateWidgetProperty,
triggerEvalOnMetaUpdate,
modifyMetaWidgets,
setWidgetCache,
getWidgetCache,
deleteMetaWidgets,
updateMetaWidgetProperty,
}),
[
executeAction,
updateWidget,
updateWidgetProperty,
syncUpdateWidgetMetaProperty,
disableDrag,
resetChildrenMetaProperty,
deleteWidgetProperty,
batchUpdateWidgetProperty,
triggerEvalOnMetaUpdate,
modifyMetaWidgets,
setWidgetCache,
getWidgetCache,
deleteMetaWidgets,
updateMetaWidgetProperty,
],
);
return (
<EditorContext.Provider value={contextValue}>
{children}
</EditorContext.Provider>
);
}
export default MetaWidgetContextProvider;