Skip to content

Commit 65144a9

Browse files
authored
Merge pull request #632 from code0-tech/add-name-field
Add name field for flow
2 parents 4485e78 + 8821336 commit 65144a9

File tree

12 files changed

+30
-3
lines changed

12 files changed

+30
-3
lines changed

app/graphql/mutations/namespaces/projects/flows/create.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def resolve(project_id:, flow:, **_params)
2727
namespace_project: project,
2828
flow_type: flow_type,
2929
starting_node: flow.starting_node,
30-
flow_settings: flow.settings || []
30+
flow_settings: flow.settings || [],
31+
name: flow.name
3132
).execute.to_mutation_response(success_key: :flow)
3233
end
3334

app/graphql/types/flow_type.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class FlowType < Types::BaseObject
66

77
authorize :read_flow
88

9-
# field :name, String, null: false does exist in pictor but not in grpc
9+
field :name, String, null: false, description: 'Name of the flow'
10+
1011
field :input_type, Types::DataTypeType,
1112
null: true,
1213
description: 'The input data type of the flow'

app/graphql/types/input/flow_input_type.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Input
55
class FlowInputType < Types::BaseInputObject
66
description 'Input type for creating or updating a flow'
77

8+
argument :name, String, required: true, description: 'The name of the flow'
9+
810
argument :settings, [Types::Input::FlowSettingInputType], required: false,
911
description: 'The settings of the flow'
1012
argument :starting_node, Types::Input::NodeFunctionInputType, required: true,

app/models/flow.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Flow < ApplicationRecord
99

1010
has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow
1111

12+
validates :name, presence: true,
13+
allow_blank: false,
14+
uniqueness: { case_sensitive: false, scope: :project_id }
15+
1216
def to_grpc
1317
Tucana::Shared::ValidationFlow.new(
1418
flow_id: id,

db/migrate/20250526124346_create_flows.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def change
5959

6060
t.references :starting_node, null: false, foreign_key: { to_table: :node_functions, on_delete: :restrict }
6161

62+
t.text :name, null: false
63+
64+
t.index %i[name project_id], unique: true
65+
6266
t.timestamps_with_timezone
6367
end
6468

db/structure.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ CREATE TABLE flows (
250250
input_type_id bigint,
251251
return_type_id bigint,
252252
starting_node_id bigint NOT NULL,
253+
name text NOT NULL,
253254
created_at timestamp with time zone NOT NULL,
254255
updated_at timestamp with time zone NOT NULL
255256
);
@@ -1099,6 +1100,8 @@ CREATE INDEX index_flows_on_flow_type_id ON flows USING btree (flow_type_id);
10991100

11001101
CREATE INDEX index_flows_on_input_type_id ON flows USING btree (input_type_id);
11011102

1103+
CREATE UNIQUE INDEX index_flows_on_name_and_project_id ON flows USING btree (name, project_id);
1104+
11021105
CREATE INDEX index_flows_on_project_id ON flows USING btree (project_id);
11031106

11041107
CREATE INDEX index_flows_on_return_type_id ON flows USING btree (return_type_id);

docs/graphql/input_object/flowinput.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Input type for creating or updating a flow
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11+
| `name` | [`String!`](../scalar/string.md) | The name of the flow |
1112
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
1213
| `startingNode` | [`NodeFunctionInput!`](../input_object/nodefunctioninput.md) | The starting node of the flow |
1314
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |

docs/graphql/object/flow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Represents a flow
1111
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created |
1212
| `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow |
1313
| `inputType` | [`DataType`](../object/datatype.md) | The input data type of the flow |
14+
| `name` | [`String!`](../scalar/string.md) | Name of the flow |
1415
| `nodes` | [`NodeFunctionConnection!`](../object/nodefunctionconnection.md) | Nodes of the flow |
1516
| `returnType` | [`DataType`](../object/datatype.md) | The return data type of the flow |
1617
| `settings` | [`FlowSettingConnection!`](../object/flowsettingconnection.md) | The settings of the flow |

spec/factories/flows.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# frozen_string_literal: true
22

33
FactoryBot.define do
4+
sequence(:flow_name) { |n| "Flow#{n}" }
5+
46
factory :flow do
57
project factory: :namespace_project
68
flow_type
79
starting_node factory: :node_function
810
flow_settings { [] }
911
input_type { nil }
1012
return_type { nil }
13+
name { generate(:flow_name) }
1114
end
1215
end

spec/models/flow_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
it { is_expected.to have_many(:flow_settings) }
1616
end
1717

18+
describe 'validations' do
19+
it { is_expected.to validate_presence_of(:name) }
20+
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to(:project_id) }
21+
end
22+
1823
describe '#to_grpc' do
1924
let(:flow) do
2025
create(

0 commit comments

Comments
 (0)