Skip to content

Commit 9c842d0

Browse files
authored
fix: Prevent duplicate settings when copying workflow settings (#3204)
1 parent 3da750d commit 9c842d0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

frontend/src/pages/org/workflows-new.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { html } from "lit";
55
import { customElement, property } from "lit/decorators.js";
66
import { ifDefined } from "lit/directives/if-defined.js";
77
import { when } from "lit/directives/when.js";
8+
import mapValues from "lodash/fp/mapValues";
9+
import uniq from "lodash/fp/uniq";
810
import type { PartialDeep } from "type-fest";
911

1012
import {
@@ -26,6 +28,15 @@ import {
2628
type FormState as WorkflowFormState,
2729
} from "@/utils/workflow";
2830

31+
// Make array values unique since mergeDeep will concatenate arrays
32+
const makeArrUniq = mapValues((val: unknown) => {
33+
if (Array.isArray(val)) {
34+
return uniq(val) as unknown[];
35+
}
36+
37+
return val;
38+
});
39+
2940
/**
3041
* Usage:
3142
* ```ts
@@ -126,7 +137,7 @@ export class WorkflowsNew extends BtrixElement {
126137
</sl-button>
127138
</header>
128139
${when(this.org, (org) => {
129-
const initialWorkflow = mergeDeep(
140+
const mergedWorkflow = mergeDeep(
130141
this.defaultNewWorkflow,
131142
{
132143
profileid: org.crawlingDefaults?.profileid,
@@ -153,6 +164,11 @@ export class WorkflowsNew extends BtrixElement {
153164
this.initialWorkflow || {},
154165
);
155166
167+
const initialWorkflow = makeArrUniq({
168+
...mergedWorkflow,
169+
config: makeArrUniq(mergedWorkflow.config),
170+
}) as WorkflowParams;
171+
156172
const scopeType = this.scopeType || initialWorkflow.config.scopeType;
157173
158174
return html`

0 commit comments

Comments
 (0)