From 1a161ed4cd00f442894ec3b8387848cb9033497b Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 10 Aug 2021 13:11:51 +0300 Subject: [PATCH] [refactor] GH-5 Remove parent --- src/DispatchCell.tsx | 3 +- src/Form.tsx | 13 +----- src/cells/AntdCellHorizontalLayout.tsx | 12 +----- src/layouts/AntdFormLayout.tsx | 2 - src/layouts/AntdHorizontalLayout.tsx | 14 ++----- src/layouts/AntdVerticalLayout.tsx | 7 ++-- src/layouts/SplitPaneLayout.tsx | 33 ++++----------- src/layouts/TabsLayout.tsx | 2 +- src/util/AntdModal.tsx | 10 +---- src/util/ContextToProps.tsx | 58 +++++++++++--------------- src/util/layout.tsx | 4 +- 11 files changed, 46 insertions(+), 112 deletions(-) diff --git a/src/DispatchCell.tsx b/src/DispatchCell.tsx index 0f9eaca..fbec2b1 100644 --- a/src/DispatchCell.tsx +++ b/src/DispatchCell.tsx @@ -19,7 +19,7 @@ import { MstContext } from './MstContext'; * Dispatch renderer component for cells. */ export const DispatchCell: React.FC = React.memo( - ({ data, onMeasureChange, uri, schema, viewElement, view, enabled, id, parent, CKey, rowData, ...rest }) => { + ({ data, onMeasureChange, uri, schema, viewElement, view, enabled, id, CKey, rowData, ...rest }) => { const { cells } = useContext(MstContext); const renderer = maxBy(cells, (r) => r.tester(viewElement, schema)); if (renderer === undefined || renderer.tester(viewElement, schema) === -1) { @@ -43,7 +43,6 @@ export const DispatchCell: React.FC = React.memo( enabled={enabled} view={view} id={id} - parent={parent} {...rest} /> diff --git a/src/Form.tsx b/src/Form.tsx index 59e3d08..ef64456 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -62,7 +62,6 @@ export interface FormsInitStateProps { } export interface FormsDispatchProps extends InitStateProps { enabled?: boolean; - parent?: string; form?: string; } export interface FormDispatchProps extends FormsDispatchProps { @@ -87,7 +86,7 @@ export interface DispatchCellProps extends RenderProps { } export const FormsDispatch: React.FC = observer( - ({ view, viewElement, parent, form, uri, enabled }: any) => { + ({ view, viewElement, form, uri, enabled }: any) => { const { store, renderers } = useContext(MstContext); const shapes = viewElement.resultsScope ? viewElement.resultsScope.split('/') : []; @@ -117,15 +116,7 @@ export const FormsDispatch: React.FC = observer = renderer.renderer; return ( {}}> - + ); } diff --git a/src/cells/AntdCellHorizontalLayout.tsx b/src/cells/AntdCellHorizontalLayout.tsx index 1582edd..e3a6f50 100644 --- a/src/cells/AntdCellHorizontalLayout.tsx +++ b/src/cells/AntdCellHorizontalLayout.tsx @@ -20,16 +20,7 @@ import { Idx } from '../util/layout'; export const AntdHorizontalLayoutRenderer: React.FC = ({ viewElement, view, data, schema }) => { //const layout = viewElement as Layout; - const Render: React.FC = ({ - idx, - schema, - viewElement, - view, - data, - enabled, - parent, - form, - }) => { + const Render: React.FC = ({ idx, schema, viewElement, view, data, enabled, form }) => { const options = viewElement.options || {}; //const style: any = options.style; const span = options.contentSize || !viewElement.elements ? undefined : Math.ceil(24 / viewElement.elements.length); @@ -46,7 +37,6 @@ export const AntdHorizontalLayoutRenderer: React.FC = ({ view rowData={data} schema={newSchema || schema} enabled={enabled} - parent={parent} form={form} /> diff --git a/src/layouts/AntdFormLayout.tsx b/src/layouts/AntdFormLayout.tsx index da8524c..825a789 100644 --- a/src/layouts/AntdFormLayout.tsx +++ b/src/layouts/AntdFormLayout.tsx @@ -79,7 +79,6 @@ export const AntdFormLayout: React.FC = ({ enabled, title, visible, - parent, formId, validation, editable, @@ -101,7 +100,6 @@ export const AntdFormLayout: React.FC = ({ viewElement={viewElement} enabled={enabled} view={view} - parent={parent} form={formId} /> diff --git a/src/layouts/AntdHorizontalLayout.tsx b/src/layouts/AntdHorizontalLayout.tsx index d908da3..3d18769 100644 --- a/src/layouts/AntdHorizontalLayout.tsx +++ b/src/layouts/AntdHorizontalLayout.tsx @@ -18,21 +18,15 @@ import { renderLayoutElements } from '../util/layout'; import { Idx } from '../util/layout'; import { LayoutComponent } from './LayoutComponent'; -export const AntdHorizontalLayoutRenderer: React.FC = ({ - viewElement, - view, - enabled, - visible, - parent, -}) => { +export const AntdHorizontalLayoutRenderer: React.FC = ({ viewElement, view, enabled, visible }) => { //const layout = viewElement as Layout; - const Render: React.FC = ({ idx, viewElement, view, enabled, parent, form }) => { + const Render: React.FC = ({ idx, viewElement, view, enabled, form }) => { const options = viewElement.options || {}; const style: any = options.style; const span = options.contentSize || !viewElement.elements ? undefined : Math.ceil(24 / viewElement.elements.length); return ( - + ); }; @@ -41,7 +35,7 @@ export const AntdHorizontalLayoutRenderer: React.FC = ({ if (viewElement.options && viewElement.options.width === 'all-empty-space') rowStyle.width = '100%'; return ( - {renderLayoutElements({ viewElement, view, enabled, Render, parent })} + {renderLayoutElements({ viewElement, view, enabled, Render })} ); }; diff --git a/src/layouts/AntdVerticalLayout.tsx b/src/layouts/AntdVerticalLayout.tsx index 5e9ff35..a21a64e 100644 --- a/src/layouts/AntdVerticalLayout.tsx +++ b/src/layouts/AntdVerticalLayout.tsx @@ -23,10 +23,9 @@ export const AntdVerticalLayoutRenderer: React.FC = ({ view, enabled, visible, - parent, form, }) => { - const Render: React.FC = ({ idx, viewElement, view, enabled, parent }) => { + const Render: React.FC = ({ idx, viewElement, view, enabled }) => { const options = viewElement.options || {}; const style: any = options.style; return ( @@ -36,7 +35,7 @@ export const AntdVerticalLayoutRenderer: React.FC = ({ flex: viewElement.options && viewElement.options.height === 'all-empty-space' ? '1 1 auto' : '', }}> - + ); @@ -44,7 +43,7 @@ export const AntdVerticalLayoutRenderer: React.FC = ({ return (
- {renderLayoutElements({ viewElement, view, enabled, Render, parent })} + {renderLayoutElements({ viewElement, view, enabled, Render })}
); diff --git a/src/layouts/SplitPaneLayout.tsx b/src/layouts/SplitPaneLayout.tsx index e789719..9df3a42 100644 --- a/src/layouts/SplitPaneLayout.tsx +++ b/src/layouts/SplitPaneLayout.tsx @@ -26,36 +26,17 @@ const divStyle: React.CSSProperties = { margin: '1px', }; -const renderSplitElements = ({ viewElement, view, enabled, Render, parent, form }: RenderLayoutProps) => { +const renderSplitElements = ({ viewElement, view, enabled, Render, form }: RenderLayoutProps) => { const elements = viewElement.elements; const defaultSize = viewElement.options && viewElement.options.defaultSize; - const id = viewElement['@id']; - const sort = id - ? viewElement.properties && viewElement.properties[id] && viewElement.properties[id].order - : undefined; - return sort ? ( - sort.reduce((res: ReactElement[], e: string, idx: number) => { - const key = elements ? elements.findIndex((el: ViewElement) => el['@id'] === e || el.scope === e) : -1; - if (key !== -1 && elements) { - const childView = elements[key]; - const id = childView['@id'] || childView.scope || ''; - const style = childView.options && childView.options.style; - res.push( - - - , - ); - } - return res; - }, []) - ) : elements ? ( + return elements ? ( elements.map((el: ViewElement, idx: number) => { const id = el['@id'] || el.resultsScope || ''; const style = el.options && el.options.style; return (
- +
); @@ -65,19 +46,19 @@ const renderSplitElements = ({ viewElement, view, enabled, Render, parent, form ); }; -export const SplitPaneLayoutRenderer: React.FC = ({ viewElement, view, enabled, visible, parent }) => { +export const SplitPaneLayoutRenderer: React.FC = ({ viewElement, view, enabled, visible }) => { //const layout = viewElement as Layout; - const Render: React.FC = ({ idx, viewElement, view, enabled, parent }) => { + const Render: React.FC = ({ idx, viewElement, view, enabled }) => { return (
- +
); }; return ( - {renderSplitElements({ viewElement, view, enabled, Render, parent })} + {renderSplitElements({ viewElement, view, enabled, Render })} ); diff --git a/src/layouts/TabsLayout.tsx b/src/layouts/TabsLayout.tsx index 0d3ee5d..bbd9552 100644 --- a/src/layouts/TabsLayout.tsx +++ b/src/layouts/TabsLayout.tsx @@ -22,7 +22,7 @@ export const TabsLayout: React.FC = (props) => { const title = e.options && e.options.title; return ( - + ); }) diff --git a/src/util/AntdModal.tsx b/src/util/AntdModal.tsx index 1747f04..18c22b2 100644 --- a/src/util/AntdModal.tsx +++ b/src/util/AntdModal.tsx @@ -41,15 +41,7 @@ export const AntdModal: React.FC = observer( cancelText='Отмена' width={1200} okText='Сохранить'> - + { diff --git a/src/util/ContextToProps.tsx b/src/util/ContextToProps.tsx index a9319f9..f3da76b 100644 --- a/src/util/ContextToProps.tsx +++ b/src/util/ContextToProps.tsx @@ -107,7 +107,7 @@ export const withStoreToControlProps = (Component: React.FC): ); }); export const withStoreToFormProps = (Component: React.FC): React.FC => - observer(({ viewElement, view, enabled, parent, form }) => { + observer(({ viewElement, view, enabled, form }) => { if (!view['@id']) { return null; } @@ -124,7 +124,6 @@ export const withStoreToFormProps = (Component: React.FC): React.FC store.onSaveFormData(id)} editing={store.editingData.get(id)} onEdit={() => store.setEditing(id, true)} @@ -148,7 +147,7 @@ export const withStoreToViewClassProps = (Component: any): any => export const withStoreToViewProps = (Component: any): any => observer(({ ...props }: any) => { - const { view, viewElement, parent } = props; + const { view, viewElement } = props; const { store } = useContext(MstContext); const scope = viewElement.resultsScope; const coll = store.getColl(scope); @@ -160,8 +159,8 @@ export const withStoreToViewProps = (Component: any): any => return ; } data = getSnapshot(data); - //if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - // store.setSaveLogic(parent, viewElement.resultsScope); + //if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + // store.setSaveLogic(viewElement.resultsScope); //} //const id = store.getSelectedDataJs(scope)['@type']; //const selection = getSnapshot(store.selectedData); @@ -187,10 +186,10 @@ export const withStoreToModalProps = (Component: any): any => }); export const withStoreToButtonProps = (Component: any): any => observer(({ ...props }: any) => { - const { schema, viewElement, parent } = props; + const { schema, viewElement } = props; const { store } = useContext(MstContext); - if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - store.setSaveLogic(parent, viewElement.resultsScope); + if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + store.setSaveLogic(viewElement.resultsScope); } const options = viewElement.options || {}; @@ -224,10 +223,10 @@ export const withStoreToCellProps = (Component: React.FC): React.FC => export const withStoreToDataControlProps = (Component: any): any => observer(({ ...props }: any) => { - const { viewElement, view, parent } = props; + const { viewElement, view } = props; const { store } = useContext(MstContext); - //if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - // store.setSaveLogic(parent, viewElement.resultsScope); + //if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + // store.setSaveLogic(viewElement.resultsScope); //} const custom = view[viewElement.resultsScope.split('/')[0]] ? view[view.resultsScope.split('/')[0]].customReq @@ -328,10 +327,10 @@ export const withStoreToSelectControlProps = (Component: any): any => export const withStoreToTabProps = (Component: any): any => observer(({ ...props }: any) => { - const { schema, viewElement, view, parent } = props; + const { schema, viewElement, view } = props; const { store } = useContext(MstContext); - //if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - // store.setSaveLogic(parent, viewElement.resultsScope); + //if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + // store.setSaveLogic(viewElement.resultsScope); //} const options = viewElement.options || {}; const custom = view[viewElement.resultsScope.split('/')[0]] @@ -361,10 +360,10 @@ export const withStoreToTabProps = (Component: any): any => export const withStoreToMenuProps = (Component: any): any => observer(({ ...props }: any) => { - const { schema, viewElement, view, parent } = props; + const { schema, viewElement, view } = props; const { store } = useContext(MstContext); - //if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - // store.setSaveLogic(parent, viewElement.resultsScope); + //if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + // store.setSaveLogic(viewElement.resultsScope); //} const options = viewElement.options || {}; const custom = view[viewElement.resultsScope.split('/')[0]] @@ -401,10 +400,10 @@ export const withStoreToCollapseProps = (Component: any): any => export const withStoreToArrayProps = (Component: any): any => observer(({ ...props }: any) => { - const { schema, viewElement, view, parent } = props; + const { schema, viewElement, view } = props; const { store } = useContext(MstContext); - //if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - // store.setSaveLogic(parent, viewElement.resultsScope); + //if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + // store.setSaveLogic(viewElement.resultsScope); //} const options = viewElement.options || {}; const custom = view[viewElement.resultsScope.split('/')[0]] @@ -454,7 +453,7 @@ export const withStoreToArrayProps = (Component: any): any => }); export const withLayoutProps = (Component: React.FC): React.FC => - observer(({ viewElement, view, enabled, form, parent }) => { + observer(({ viewElement, view, enabled, form }) => { const id = viewElement['@id'] || ''; const enabledLayout = enabled && checkProperty('editable', id, viewElement, view); const visible = checkProperty('visible', id, viewElement, view); @@ -462,23 +461,14 @@ export const withLayoutProps = (Component: React.FC): React.FC< if (viewElement.options && viewElement.options.connections) { viewElement.options.connections.forEach((e: any) => store.setSaveLogic(e.from, e.to)); } - return ( - - ); + return ; }); export const withStoreToSaveButtonProps = (Component: React.FC): React.FC => - observer(({ viewElement, view, enabled, parent }) => { + observer(({ viewElement, view, enabled }) => { const { store } = useContext(MstContext); - if (parent && viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { - store.setSaveLogic(parent, viewElement.resultsScope); + if (viewElement.resultsScope && !store.saveLogicTree[viewElement.resultsScope]) { + store.setSaveLogic(viewElement.resultsScope); } const key = viewElement.resultsScope; return ( diff --git a/src/util/layout.tsx b/src/util/layout.tsx index b94dc13..f918a6d 100644 --- a/src/util/layout.tsx +++ b/src/util/layout.tsx @@ -21,12 +21,12 @@ export interface RenderLayoutProps extends FormsDispatchProps { Render: React.FC; } -export const renderLayoutElements = ({ viewElement, view, enabled, Render, parent }: RenderLayoutProps) => { +export const renderLayoutElements = ({ viewElement, view, enabled, Render }: RenderLayoutProps) => { const elements = viewElement.elements; //const id = view['@id']; //const sort = id ? view.properties && view.properties[id] && view.properties[id].order : undefined; if (!elements || elements.length === 0) return <>; return elements.map((el: ViewElement, idx: number) => ( - + )); };