Add action for update specific filter
[MAILPOET-3469]
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
AnyFormItem,
|
AnyFormItem,
|
||||||
SetSegmentActionType,
|
SetSegmentActionType,
|
||||||
SetErrorsActionType,
|
SetErrorsActionType,
|
||||||
|
SetSegmentFilerActionType,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
export function setSegment(segment: AnyFormItem): SetSegmentActionType {
|
export function setSegment(segment: AnyFormItem): SetSegmentActionType {
|
||||||
@@ -30,6 +31,15 @@ export function updateSegment(data: AnyFormItem): SetSegmentActionType {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateSegmentFilter(filter: AnyFormItem, filterIndex: number)
|
||||||
|
: SetSegmentFilerActionType {
|
||||||
|
return {
|
||||||
|
type: Actions.UPDATE_SEGMENT_FILTER,
|
||||||
|
filter,
|
||||||
|
filterIndex,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function updateSegmentFromEvent(
|
export function updateSegmentFromEvent(
|
||||||
propertyName: string,
|
propertyName: string,
|
||||||
event: ChangeEvent<HTMLSelectElement | HTMLInputElement>
|
event: ChangeEvent<HTMLSelectElement | HTMLInputElement>
|
||||||
@@ -42,6 +52,20 @@ export function updateSegmentFromEvent(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateSegmentFilterFromEvent(
|
||||||
|
propertyName: string,
|
||||||
|
filterIndex: number,
|
||||||
|
event: ChangeEvent<HTMLSelectElement | HTMLInputElement>
|
||||||
|
): SetSegmentFilerActionType {
|
||||||
|
return {
|
||||||
|
type: Actions.UPDATE_SEGMENT_FILTER,
|
||||||
|
filter: {
|
||||||
|
[propertyName]: event.target.value,
|
||||||
|
},
|
||||||
|
filterIndex,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function* pageLoaded(segmentId?: number): Generator<{
|
export function* pageLoaded(segmentId?: number): Generator<{
|
||||||
type: string;
|
type: string;
|
||||||
segmentId?: number;
|
segmentId?: number;
|
||||||
|
@@ -5,6 +5,7 @@ import {
|
|||||||
SetSegmentActionType,
|
SetSegmentActionType,
|
||||||
SetErrorsActionType,
|
SetErrorsActionType,
|
||||||
StateType,
|
StateType,
|
||||||
|
SetSegmentFilerActionType,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
function setSegment(state: StateType, action: SetSegmentActionType): StateType {
|
function setSegment(state: StateType, action: SetSegmentActionType): StateType {
|
||||||
@@ -29,6 +30,15 @@ function updateSegment(state: StateType, action: SetSegmentActionType): StateTyp
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSegmentFilter(state: StateType, action: SetSegmentFilerActionType): StateType {
|
||||||
|
const segment = { ...state.segment };
|
||||||
|
segment.filters[action.filterIndex] = assign(segment.filters[action.filterIndex], action.filter);
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
segment,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const createReducer = (defaultState: StateType) => (
|
export const createReducer = (defaultState: StateType) => (
|
||||||
state: StateType = defaultState,
|
state: StateType = defaultState,
|
||||||
action: ActionType
|
action: ActionType
|
||||||
@@ -37,6 +47,8 @@ export const createReducer = (defaultState: StateType) => (
|
|||||||
case Actions.SET_SEGMENT: return setSegment(state, action as SetSegmentActionType);
|
case Actions.SET_SEGMENT: return setSegment(state, action as SetSegmentActionType);
|
||||||
case Actions.SET_ERRORS: return setErrors(state, action as SetErrorsActionType);
|
case Actions.SET_ERRORS: return setErrors(state, action as SetErrorsActionType);
|
||||||
case Actions.UPDATE_SEGMENT: return updateSegment(state, action as SetSegmentActionType);
|
case Actions.UPDATE_SEGMENT: return updateSegment(state, action as SetSegmentActionType);
|
||||||
|
case Actions.UPDATE_SEGMENT_FILTER:
|
||||||
|
return updateSegmentFilter(state, action as SetSegmentFilerActionType);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -154,6 +154,7 @@ export enum Actions {
|
|||||||
SET_SEGMENT = 'SET_SEGMENT',
|
SET_SEGMENT = 'SET_SEGMENT',
|
||||||
SET_ERRORS = 'SET_ERRORS',
|
SET_ERRORS = 'SET_ERRORS',
|
||||||
UPDATE_SEGMENT = 'UPDATE_SEGMENT',
|
UPDATE_SEGMENT = 'UPDATE_SEGMENT',
|
||||||
|
UPDATE_SEGMENT_FILTER = 'UPDATE_SEGMENT_FILTER',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActionType {
|
export interface ActionType {
|
||||||
@@ -164,6 +165,11 @@ export interface SetSegmentActionType extends ActionType {
|
|||||||
segment: AnyFormItem;
|
segment: AnyFormItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SetSegmentFilerActionType extends ActionType {
|
||||||
|
filter: AnyFormItem;
|
||||||
|
filterIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SetErrorsActionType extends ActionType {
|
export interface SetErrorsActionType extends ActionType {
|
||||||
errors: string[];
|
errors: string[];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user