Skip to content

retain the selected component (if any) when previewing a form configu… #2687

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConfigurableFormRenderer, SidebarContainer } from '@/components';
import ConditionalWrap from '@/components/conditionalWrapper';
import { MetadataProvider, useCanvas, useForm } from '@/providers';
import { useFormDesignerActions, useFormDesignerState } from '@/providers/formDesigner';
import { useFormDesignerState } from '@/providers/formDesigner';
import ParentProvider from '@/providers/parentProvider';
import React, { FC, useEffect } from 'react';
import React, { FC } from 'react';
import { ComponentPropertiesPanel } from '../componentPropertiesPanel';
import { ComponentPropertiesTitle } from '../componentPropertiesTitle';
import { DebugPanel } from '../debugPanel';
Expand All @@ -16,17 +16,10 @@ export interface IDesignerMainAreaProps {

export const DesignerMainArea: FC<IDesignerMainAreaProps> = () => {
const { isDebug, readOnly } = useFormDesignerState();
const { setSelectedComponent } = useFormDesignerActions();
const { form, formMode, formSettings } = useForm();
const { designerWidth, zoom } = useCanvas();
const { styles } = useStyles();

useEffect(() => {
if (formMode !== 'designer') {
setSelectedComponent(null);
}
}, [formMode]);

return (
<div className={styles.mainArea} style={{
borderTop: '1px solid #d3d3d3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import React, { FC } from 'react';
import { Button } from 'antd';
import { EyeOutlined } from '@ant-design/icons';
import { useForm } from '@/providers';
import { useFormDesignerActions, useFormDesignerState } from '@/providers/formDesigner';

export interface IPreviewButtonProps {

}

export const PreviewButton: FC<IPreviewButtonProps> = () => {
const { setFormMode, formMode } = useForm();
const { setFormMode, formMode, } = useForm();
const { isPreview } = useFormDesignerState();
const { setPreviewMode } = useFormDesignerActions();

return (
<Button
onClick={() => {
setFormMode(formMode === 'designer' ? 'edit' : 'designer');
setPreviewMode(!isPreview);
}}
type={formMode === 'designer' ? 'default' : 'primary'}
shape="circle"
Expand Down
2 changes: 2 additions & 0 deletions shesha-reactjs/src/providers/formDesigner/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum FormActionEnums {

SetFlatComponentsAction = 'SET_FLAT_COMPONENTS',
SetDebugMode = 'SET_DEBUG_MODE',
SetPreviewMode = 'SET_PREVIEW_MODE',
StartDraggingNewItem = 'START_DRAGGING_NEW_ITEM',
EndDraggingNewItem = 'END_DRAGGING_NEW_ITEM',
StartDragging = 'START_DRAGGING',
Expand Down Expand Up @@ -98,6 +99,7 @@ export const setFlatComponentsAction = createAction<IFlatComponentsStructure, IF
);

export const setDebugModeAction = createAction<boolean, boolean>(FormActionEnums.SetDebugMode, (p) => p);
export const setPreviewModeAction = createAction<boolean, boolean>(FormActionEnums.SetPreviewMode, (p) => p);

export const startDraggingNewItemAction = createAction(FormActionEnums.StartDraggingNewItem);
export const endDraggingNewItemAction = createAction(FormActionEnums.EndDraggingNewItem);
Expand Down
3 changes: 3 additions & 0 deletions shesha-reactjs/src/providers/formDesigner/contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IFormDesignerStateContext {
hasDragged: boolean;
dataSources: IDataSource[];
isDebug: boolean;
isPreview: boolean;
readOnly: boolean;

settingsPanelRef?: MutableRefObject<any>;
Expand Down Expand Up @@ -102,6 +103,7 @@ export interface IFormDesignerActionsContext {
setValidationErrors: (payload: IFormValidationErrors) => void;

setDebugMode: (isDebug: boolean) => void;
setPreviewMode: (isPreview: boolean) => void;

updateFormSettings: (settings: IFormSettings) => void;

Expand All @@ -125,6 +127,7 @@ export const FORM_DESIGNER_CONTEXT_INITIAL_STATE: IFormDesignerStateContext = {
hasDragged: false,
isDragging: false,
isDebug: false,
isPreview: false,
formSettings: DEFAULT_FORM_SETTINGS,
formFlatMarkup: {
allComponents: {},
Expand Down
9 changes: 8 additions & 1 deletion shesha-reactjs/src/providers/formDesigner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
setActiveDataSourceAction,
setDebugModeAction,
setFlatComponentsAction,
setPreviewModeAction,
setReadOnlyAction,
setSelectedComponentAction,
setValidationErrorsAction,
Expand Down Expand Up @@ -179,6 +180,10 @@ const FormDesignerProvider: FC<PropsWithChildren<IFormDesignerProviderProps>> =
dispatch(setDebugModeAction(isDebug));
}, [dispatch]);

const setPreviewMode = useCallback((isPreview: boolean) => {
dispatch(setPreviewModeAction(isPreview));
}, [dispatch]);

const startDraggingNewItem = useCallback(() => {
dispatch(startDraggingNewItemAction());
}, [dispatch]);
Expand Down Expand Up @@ -244,6 +249,7 @@ const FormDesignerProvider: FC<PropsWithChildren<IFormDesignerProviderProps>> =
duplicateComponent,
updateComponent,
setDebugMode,
setPreviewMode,
startDraggingNewItem,
endDraggingNewItem,
startDragging,
Expand Down Expand Up @@ -284,7 +290,8 @@ const FormDesignerProvider: FC<PropsWithChildren<IFormDesignerProviderProps>> =
addDataSource,
removeDataSource,
setActiveDataSource,
setReadOnly
setReadOnly,
setPreviewMode,
/* NEW_ACTION_GOES_HERE */
]);

Expand Down
8 changes: 8 additions & 0 deletions shesha-reactjs/src/providers/formDesigner/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ const reducer = handleActions<IFormDesignerStateContext, any>(
isDebug: payload,
};
},
[FormActionEnums.SetPreviewMode]: (state: IFormDesignerStateContext, action: ReduxActions.Action<boolean>) => {
const { payload } = action;

return {
...state,
isPreview: payload,
};
},

[FormActionEnums.StartDraggingNewItem]: (state: IFormDesignerStateContext) => {
return {
Expand Down