Skip to content

Commit

Permalink
fix(gv-policy-studio): resolve consecutive saves
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux committed Jun 25, 2021
1 parent 1c412a8 commit 52c3710
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/policy-studio/gv-policy-studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import './gv-flow-step';
import './gv-policy-studio-menu';
import { empty } from '../styles/empty';
import { cache } from 'lit-html/directives/cache';
import { deepClone, deepEqual, uuid } from '../lib/utils';
import { deepClone, deepEqual } from '../lib/utils';
import { KeyboardElement, KEYS } from '../mixins/keyboard-element';

const FLOW_STEP_FORM_ID = 'flow-step-form';
Expand Down Expand Up @@ -492,6 +492,7 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
await this._askToValidateForms();

const policy = detail.policy;
const targetFlow = this._findFlowById(detail.flowId);

let name = policy.name;
let description = '';
Expand All @@ -504,13 +505,11 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
description = detail.flowStep.description || '';
configuration = detail.flowStep.configuration;
} else {
_id = uuid();
_id = this._generateFlowStepId(targetFlow._id, detail.flowKey, detail.position);
_new = true;
}

const flowStep = { _id, _new, name, policy: policy.id, description, enabled: true, configuration };

const targetFlow = this._findFlowById(detail.flowId);
const sourceFlow = detail.sourceFlowId != null ? this._findFlowById(detail.sourceFlowId) : targetFlow;

if (detail.sourcePosition != null) {
Expand Down Expand Up @@ -816,6 +815,7 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
) {
const flow = this._findFlowById(this._currentFlowStep.flow._id);
const position = flow[this._currentFlowStep.group].findIndex((step) => step._id === this._currentFlowStep.step._id);

flow[this._currentFlowStep.group][position].description = description;
flow[this._currentFlowStep.group][position].configuration = deepClone(configuration);
delete flow[this._currentFlowStep.group][position]._new;
Expand Down Expand Up @@ -1003,19 +1003,24 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
return this._generateId(plan.id, plan.flows, force, true);
}

_generateFlowStepId(flowId, flowKey, position) {
return `${flowId}_${flowKey}_${position}`;
}

_generateId(prefix, list, force = false, isFlow = false) {
if (list) {
return list.map((e, index) => {
const _id = `${prefix}_${index}`;
if (isFlow) {
if (e.pre) {
e.pre.forEach((step) => (step._id = uuid()));
e.pre.forEach((step, stepIndex) => (step._id = this._generateFlowStepId(_id, 'pre', stepIndex)));
}
if (e.post) {
e.post.forEach((step) => (step._id = uuid()));
e.post.forEach((step, stepIndex) => (step._id = this._generateFlowStepId(_id, 'post', stepIndex)));
}
}
if (force || e._id == null) {
return { ...e, _id: `${prefix}_${index}` };
return { ...e, _id };
}
return e;
});
Expand Down

0 comments on commit 52c3710

Please sign in to comment.