Skip to content

Commit fabc4cd

Browse files
committed
feat: allow child to override parameters
1 parent 3937fc8 commit fabc4cd

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

shared.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6807,12 +6807,52 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) {
68076807
for _, action := range updatedActions {
68086808
for index, childAction := range childWorkflow.Actions {
68096809
if childAction.ID != action.ID {
6810+
// this means it's a new action
68106811
continue
68116812
}
68126813

68136814
// FIXME:
68146815
// Make sure it changes things such as environment & app auth appropriately
68156816

6817+
// implement by default parameter "unlocking"
6818+
// ie: unless action itself is changed,
6819+
// preserve child paramter.
6820+
6821+
// Also, allow a "locking" mechanism that
6822+
// overwrites to child if enabled.
6823+
finalLocks := []ParameterLock{}
6824+
finalParamters := action.Parameters
6825+
6826+
// lock clean up in incoming action
6827+
for _, lock := range action.ParameterLocks {
6828+
if action.Name == lock.ActionName {
6829+
finalLocks = append(finalLocks, lock)
6830+
}
6831+
}
6832+
6833+
action.ParameterLocks = finalLocks
6834+
if len(action.ParameterLocks) == 0 {
6835+
log.Printf("[DEBUG] No locks found for action %s", action.ID)
6836+
if childAction.Name == action.Name {
6837+
log.Printf("[DEBUG] Action %s is the same as child action %s", action.ID, childAction.ID)
6838+
// so, action itself is not changed
6839+
// preserve child parameters by default
6840+
finalParamters = childAction.Parameters
6841+
} else {
6842+
log.Printf("[DEBUG] Action %s (Name: %s, AppID: %s) is different from child action %s (Name: %s, AppID: %s)", action.ID, action.Name, action.AppID, childAction.ID, childAction.Name, childAction.AppID)
6843+
}
6844+
} else {
6845+
for _, lock := range action.ParameterLocks {
6846+
for paramIndex, param := range finalParamters {
6847+
if param.Name == lock.ParameterName && action.Name == lock.ActionName {
6848+
finalParamters[paramIndex].Value = childAction.Parameters[paramIndex].Value
6849+
}
6850+
}
6851+
}
6852+
}
6853+
6854+
action.Parameters = finalParamters
6855+
68166856
childWorkflow.Actions[index] = action
68176857
break
68186858
}

structs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,11 @@ type Position struct {
11391139
Y float64 `json:"y" datastore:"y"`
11401140
}
11411141

1142+
type ParameterLock struct {
1143+
ParameterName string `json:"parameter_name" datastore:"parameter_name"`
1144+
ActionName string `json:"action_name" datastore:"action_name"`
1145+
}
1146+
11421147
// This is for the nodes in a workflow, NOT the app action itself.
11431148
type Action struct {
11441149
AppName string `json:"app_name" datastore:"app_name"`
@@ -1177,6 +1182,8 @@ type Action struct {
11771182
Suggestion bool `json:"suggestion" datastore:"suggestion"` // Whether it was a suggestion in the workflow or not
11781183

11791184
ParentControlled bool `json:"parent_controlled" datastore:"parent_controlled"` // If the parent workflow node exists, and shouldn't be editable by child workflow
1185+
1186+
ParameterLocks []ParameterLock `json:"parameter_locks" datastore:"parameter_locks"`
11801187
}
11811188

11821189
// Added environment for location to execute

0 commit comments

Comments
 (0)