Skip to content

Commit 899cfb4

Browse files
Merge pull request #510 from DrDroidLab/bug/global_variable_objects_ui
adds global variable as objects in the UI
2 parents 93f4541 + dda91c4 commit 899cfb4

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

web/src/utils/parser/playbook/executionToState.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,22 @@ function executionToState(playbook_execution: any): Playbook {
7575
? playbook.global_variable_set
7676
: playbook_execution?.execution_global_variable_set;
7777

78+
const globalVariables = Object.entries(variables ?? {}).reduce(
79+
(acc, [key, value]) => {
80+
if (typeof value === "string") {
81+
acc[key] = value;
82+
} else {
83+
acc[key] = JSON.stringify(value);
84+
}
85+
86+
return acc;
87+
},
88+
{},
89+
);
90+
7891
return {
7992
...(currentPlaybook ?? playbook),
80-
global_variable_set: variables ?? {},
93+
global_variable_set: globalVariables ?? {},
8194
steps: playbookSteps,
8295
step_relations: playbookRelations,
8396
ui_requirement: {

web/src/utils/parser/playbook/playbookToState.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ function playbookToState(playbook: Playbook): Playbook {
1717
showError: false,
1818
},
1919
}));
20+
21+
const globalVariables = Object.entries(
22+
playbook.global_variable_set ?? {},
23+
).reduce((acc, [key, value]) => {
24+
if (typeof value === "string") {
25+
acc[key] = value;
26+
} else {
27+
acc[key] = JSON.stringify(value);
28+
}
29+
30+
return acc;
31+
}, {});
32+
2033
steps.forEach((step: Step) => {
2134
const stepTasks: Task[] = (step.tasks as Task[])
2235
.map((e) => {
@@ -64,6 +77,7 @@ function playbookToState(playbook: Playbook): Playbook {
6477
relationToState(playbook, tasks, steps);
6578
return {
6679
...playbook,
80+
global_variable_set: globalVariables,
6781
steps,
6882
ui_requirement: {
6983
tasks,

web/src/utils/parser/playbook/stateToPlaybook.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Playbook, Step, Task } from "../../../types/index.ts";
55
import checkId from "../../common/checkId.ts";
66
import { extractTimeFromHours } from "../../../components/Playbooks/task/taskConfiguration/comparison/utils/extractTimeFromHours.ts";
77
import { handleMultipleRuleSets } from "./handleMultipleRuleSets.ts";
8+
import isJSONString from "../../../components/common/CodeAccordion/utils/isJSONString.ts";
89

910
function stateToPlaybook(): Playbook | null {
1011
handleMultipleRuleSets();
@@ -18,6 +19,17 @@ function stateToPlaybook(): Playbook | null {
1819
"ui_requirement",
1920
);
2021

22+
playbook.global_variable_set = Object.entries(
23+
playbook.global_variable_set ?? {},
24+
)?.reduce((gvs, [key, value]) => {
25+
if (isJSONString(value)) {
26+
gvs[key] = JSON.parse(value);
27+
} else {
28+
gvs[key] = value;
29+
}
30+
return gvs;
31+
}, {});
32+
2133
playbook.steps = playbook?.steps?.map((step: Step) => ({
2234
...step,
2335
id: checkId(step.id),

0 commit comments

Comments
 (0)