Skip to content

Commit c1614ab

Browse files
committed
Add disabled reason to flow
1 parent e8e7f1d commit c1614ab

File tree

9 files changed

+64
-5
lines changed

9 files changed

+64
-5
lines changed

app/graphql/types/flow_type.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class FlowType < Types::BaseObject
88

99
field :name, String, null: false, description: 'Name of the flow'
1010

11+
field :disabled_reason, String,
12+
null: true,
13+
description: 'The reason why the flow is disabled, if it is disabled'
14+
1115
field :input_type, Types::DataTypeType,
1216
null: true,
1317
description: 'The input data type of the flow'
@@ -19,7 +23,7 @@ class FlowType < Types::BaseObject
1923
method: :flow_settings,
2024
description: 'The settings of the flow'
2125
field :starting_node_id, Types::GlobalIdType[::NodeFunction],
22-
null: false,
26+
null: true,
2327
description: 'The ID of the starting node of the flow'
2428
field :type, Types::FlowTypeType,
2529
null: false,
@@ -38,7 +42,7 @@ class FlowType < Types::BaseObject
3842
timestamps
3943

4044
def starting_node_id
41-
object.starting_node.to_global_id
45+
object.starting_node&.to_global_id
4246
end
4347
end
4448
end

app/graphql/types/input/flow_input_type.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class FlowInputType < Types::BaseInputObject
99

1010
argument :settings, [Types::Input::FlowSettingInputType], required: false,
1111
description: 'The settings of the flow'
12-
argument :starting_node_id, Types::GlobalIdType[::NodeFunction], required: true,
12+
argument :starting_node_id, Types::GlobalIdType[::NodeFunction], required: false,
1313
description: 'The starting node of the flow'
1414

1515
argument :nodes, [Types::Input::NodeFunctionInputType], required: true,
1616
description: 'The node functions of the flow'
1717

1818
argument :type, Types::GlobalIdType[::FlowType], required: true,
1919
description: 'The identifier of the flow type'
20+
21+
argument :disabled_reason, String, required: false,
22+
description: 'The reason why the flow is disabled, if applicable, if not set the flow is enabled'
2023
end
2124
end
2225
end

app/grpc/flow_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FlowHandler < Tucana::Sagittarius::FlowService::Service
1010
def self.update_runtime(runtime)
1111
flows = []
1212
runtime.project_assignments.compatible.each do |assignment|
13-
assignment.namespace_project.flows.each do |flow|
13+
assignment.namespace_project.flows.enabled.each do |flow|
1414
flows << flow.to_grpc
1515
end
1616
end

app/models/flow.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ class Flow < ApplicationRecord
1414
allow_blank: false,
1515
uniqueness: { case_sensitive: false, scope: :project_id }
1616

17+
validates :disabled_reason, presence: false,
18+
allow_blank: true,
19+
length: { maximum: 100, minimum: 0 }
20+
21+
scope :enabled, -> { where(disabled_reason: nil) }
22+
scope :disabled, -> { where.not(disabled_reason: nil) }
23+
24+
def disabled?
25+
disabled_reason.present?
26+
end
27+
1728
def to_grpc
1829
Tucana::Shared::ValidationFlow.new(
1930
flow_id: id,

app/services/namespaces/projects/flows/update_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def update_flow(t)
5151

5252
def update_flow_attributes
5353
flow.name = flow_input.name
54+
flow.disabled_reason = flow_input.disabled_reason
5455
end
5556

5657
def update_settings(t)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddDisabledReasontoFlows < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
add_column :flows, :disabled_reason, :text, null: true, default: nil
6+
add_index :flows, :disabled_reason, length: 100
7+
end
8+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4b5be2b087ebee13e1319410194a92b64672b7cf3b7b1c9abb7e8bc59d2e94e5

db/structure.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ CREATE TABLE flows (
252252
starting_node_id bigint,
253253
name text NOT NULL,
254254
created_at timestamp with time zone NOT NULL,
255-
updated_at timestamp with time zone NOT NULL
255+
updated_at timestamp with time zone NOT NULL,
256+
disabled_reason text
256257
);
257258

258259
CREATE SEQUENCE flows_id_seq
@@ -1100,6 +1101,8 @@ CREATE INDEX index_flow_types_on_return_type_id ON flow_types USING btree (retur
11001101

11011102
CREATE UNIQUE INDEX index_flow_types_on_runtime_id_and_identifier ON flow_types USING btree (runtime_id, identifier);
11021103

1104+
CREATE INDEX index_flows_on_disabled_reason ON flows USING btree (disabled_reason);
1105+
11031106
CREATE INDEX index_flows_on_flow_type_id ON flows USING btree (flow_type_id);
11041107

11051108
CREATE INDEX index_flows_on_input_type_id ON flows USING btree (input_type_id);

spec/requests/graphql/mutation/namespace/projects/flows/update_mutation_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,34 @@
155155
target_type: 'NamespaceProject'
156156
)
157157
end
158+
159+
context 'when flow is disabled' do
160+
let(:input) do
161+
{
162+
flowId: flow.to_global_id.to_s,
163+
flowInput: {
164+
name: generate(:flow_name),
165+
disabledReason: 'Some reason',
166+
type: flow_type.to_global_id.to_s,
167+
startingNodeId: nil,
168+
settings: [],
169+
nodes: [],
170+
},
171+
}
172+
end
173+
174+
it 'updates flow as disabled' do
175+
mutate!
176+
177+
updated_flow_id = graphql_data_at(:namespaces_projects_flows_update, :flow, :id)
178+
expect(updated_flow_id).to be_present
179+
flow = SagittariusSchema.object_from_id(updated_flow_id)
180+
181+
expect(flow).to be_present
182+
expect(project.flows).to include(flow)
183+
expect(flow.disabled_reason).to eq('Some reason')
184+
end
185+
end
158186
end
159187

160188
context 'when removing nodes' do

0 commit comments

Comments
 (0)