Save current step to store when selected
[MAILPOET-4287]
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { __unstableCompositeItem as CompositeItem } from '@wordpress/components';
|
import { __unstableCompositeItem as CompositeItem } from '@wordpress/components';
|
||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
import { WorkflowCompositeContext } from './context';
|
import { WorkflowCompositeContext } from './context';
|
||||||
import { Step as StepType } from './types';
|
import { Step as StepType } from './types';
|
||||||
import { DelayIcon, EmailIcon, TriggerIcon } from '../icons';
|
import { DelayIcon, EmailIcon, TriggerIcon } from '../icons';
|
||||||
|
import { store } from '../../store';
|
||||||
|
|
||||||
// mocked data
|
// mocked data
|
||||||
function getIcon(step: StepType): JSX.Element | null {
|
function getIcon(step: StepType): JSX.Element | null {
|
||||||
@@ -57,6 +59,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function Step({ step }: Props): JSX.Element {
|
export function Step({ step }: Props): JSX.Element {
|
||||||
|
const { selectStep } = useDispatch(store);
|
||||||
const compositeState = useContext(WorkflowCompositeContext);
|
const compositeState = useContext(WorkflowCompositeContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -66,6 +69,9 @@ export function Step({ step }: Props): JSX.Element {
|
|||||||
className="mailpoet-automation-editor-step"
|
className="mailpoet-automation-editor-step"
|
||||||
key={step.id}
|
key={step.id}
|
||||||
focusable
|
focusable
|
||||||
|
onClick={() => {
|
||||||
|
selectStep(step);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="mailpoet-automation-editor-step-icon">
|
<div className="mailpoet-automation-editor-step-icon">
|
||||||
{getIcon(step)}
|
{getIcon(step)}
|
||||||
|
@@ -23,3 +23,10 @@ export function toggleInserterSidebar() {
|
|||||||
type: 'TOGGLE_INSERTER_SIDEBAR',
|
type: 'TOGGLE_INSERTER_SIDEBAR',
|
||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function selectStep(value) {
|
||||||
|
return {
|
||||||
|
type: 'SET_SELECTED_STEP',
|
||||||
|
value,
|
||||||
|
} as const;
|
||||||
|
}
|
||||||
|
@@ -79,6 +79,7 @@ const logicalSteps: Item[] = [
|
|||||||
|
|
||||||
export const initialState: State = {
|
export const initialState: State = {
|
||||||
workflowData: { ...window.mailpoet_automation_workflow },
|
workflowData: { ...window.mailpoet_automation_workflow },
|
||||||
|
selectedStep: undefined,
|
||||||
inserter: {
|
inserter: {
|
||||||
actionSteps,
|
actionSteps,
|
||||||
logicalSteps,
|
logicalSteps,
|
||||||
|
@@ -11,6 +11,11 @@ export function reducer(state: State, action: Action): State {
|
|||||||
isOpened: !state.inserterSidebar.isOpened,
|
isOpened: !state.inserterSidebar.isOpened,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
case 'SET_SELECTED_STEP':
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
selectedStep: action.value,
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
|
|||||||
import { storeName } from './constants';
|
import { storeName } from './constants';
|
||||||
import { Feature, State } from './types';
|
import { Feature, State } from './types';
|
||||||
import { Item } from '../components/inserter/item';
|
import { Item } from '../components/inserter/item';
|
||||||
import { Workflow } from '../components/workflow/types';
|
import { Step, Workflow } from '../components/workflow/types';
|
||||||
|
|
||||||
export const isFeatureActive = createRegistrySelector(
|
export const isFeatureActive = createRegistrySelector(
|
||||||
(select) =>
|
(select) =>
|
||||||
@@ -32,3 +32,7 @@ export function getInserterLogicalSteps(state: State): Item[] {
|
|||||||
export function getWorkflowData(state: State): Workflow {
|
export function getWorkflowData(state: State): Workflow {
|
||||||
return state.workflowData;
|
return state.workflowData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSelectedStep(state: State): Step | undefined {
|
||||||
|
return state.selectedStep;
|
||||||
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { Item } from '../components/inserter/item';
|
import { Item } from '../components/inserter/item';
|
||||||
import { Workflow } from '../components/workflow/types';
|
import { Step, Workflow } from '../components/workflow/types';
|
||||||
|
|
||||||
export interface AutomationEditorWindow extends Window {
|
export interface AutomationEditorWindow extends Window {
|
||||||
mailpoet_automation_workflow: Workflow;
|
mailpoet_automation_workflow: Workflow;
|
||||||
@@ -7,6 +7,7 @@ export interface AutomationEditorWindow extends Window {
|
|||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
workflowData: Workflow;
|
workflowData: Workflow;
|
||||||
|
selectedStep: Step | undefined;
|
||||||
inserter: {
|
inserter: {
|
||||||
actionSteps: Item[];
|
actionSteps: Item[];
|
||||||
logicalSteps: Item[];
|
logicalSteps: Item[];
|
||||||
|
Reference in New Issue
Block a user