summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
new file mode 100644
index 000000000..5722811ce
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
@@ -0,0 +1,25 @@
+import * as _ from "lodash";
+import {ActionOnFirstLevel} from "./firstLevel/firstLevel.actions";
+import {ServiceInstanceActions} from "../../models/serviceInstanceActions";
+import {ServiceState} from "./main.reducer";
+
+export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean)
+{
+ let newState = _.cloneDeep(state);
+ let firstLevel = newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey];
+ let oldAction = firstLevel.action;
+ if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState;
+ if (shouldUpdateServiceValidationCounter){
+ updateServiceValidationCounter(newState, firstLevel['isMissingData'], false, action.serviceId);
+ }
+ newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey].action = (oldAction + '_Delete') as ServiceInstanceActions;
+ return newState;
+}
+
+export function updateServiceValidationCounter(newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) {
+ if (oldValidationState && !newValidationState) {
+ newState.serviceInstance[serviceUuid].validationCounter--;
+ } else if (!oldValidationState && newValidationState) {
+ newState.serviceInstance[serviceUuid].validationCounter++;
+ }
+};