Skip to content

Commit 9172f99

Browse files
committed
Fix bug where we don't use the name of a custom type when we could
1 parent 22b61c5 commit 9172f99

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## [0.0.5] - 2025-02-21
1+
## [0.0.6] - 2025-02-21
22

3-
-
3+
- Fix a bug where we don't use the name of a custom type when we could
44

5-
## [0.0.4] - 2025-02-21
5+
## [0.0.5] - 2025-02-21
66

77
- Bump Ruby to 3.4.2
88
- Include custom types in form generator

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ gemspec
88
gem "rake"
99

1010
# gem "foobara", path: "../foobara"
11-
# gem "foobara-files-generator", path: "../files-generator"
1211
# gem "foobara-typescript-remote-command-generator", path: "../typescript-remote-command-generator"
1312

1413
group :development do

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-typescript-react-command-form-generator (0.0.5)
4+
foobara-typescript-react-command-form-generator (0.0.6)
55
foobara
66
foobara-files-generator
77
foobara-typescript-remote-command-generator
@@ -16,7 +16,7 @@ GEM
1616
diff-lcs (1.6.0)
1717
docile (1.4.1)
1818
ffi (1.17.1-x86_64-linux-gnu)
19-
foobara (0.0.61)
19+
foobara (0.0.62)
2020
bigdecimal
2121
foobara-util
2222
foobara-files-generator (0.0.5)
@@ -26,7 +26,7 @@ GEM
2626
rubocop-rspec
2727
foobara-spec-helpers (0.0.4)
2828
foobara-util
29-
foobara-typescript-remote-command-generator (0.0.8)
29+
foobara-typescript-remote-command-generator (0.0.9)
3030
foobara
3131
foobara-files-generator
3232
foobara-util (0.0.11)

spec/generate_typescript_react_command_form_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@
5656

5757
it "is successful" do
5858
expect(outcome).to be_success
59+
5960
expect(result.keys).to eq(["forms/Foobara/Ai/AnswerBot/AskForm.tsx"])
61+
62+
ask_form_text = result["forms/Foobara/Ai/AnswerBot/AskForm.tsx"]
63+
expect(ask_form_text).to include("import { model } from")
64+
expect(ask_form_text).to match(/setModel\(e.target.value as model/)
65+
expect(ask_form_text).to match(/<select\s+value=\{model \?\? ""}/m)
6066
end
6167
end
6268
end

src/typescript_react_command_form_generator.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def non_colliding_inputs(type_declaration = inputs_type, result = [], path = [])
105105
non_colliding_inputs(type_declaration.to_type.attributes_type, result, path)
106106
elsif type_declaration.array?
107107
if type_declaration.element_type
108+
# TODO: isn't this a no-op??
108109
type_generators(type_declaration.element_type, false)
109110
end
110111
else
@@ -166,6 +167,25 @@ def initialize(generator, path, type_declaration)
166167
self.type_declaration = type_declaration
167168
end
168169

170+
def custom?
171+
type_declaration.custom?
172+
end
173+
174+
def one_of
175+
real_type_declaration.one_of
176+
end
177+
178+
# TODO: something feels kind of wrong here, hmmm
179+
def real_type_declaration
180+
@real_type_declaration ||= if custom?
181+
# We are dealing with a reference to a registered type
182+
# so we need the declaration this type name was registered to
183+
type_declaration.to_type.to_type_declaration_from_declaration_data
184+
else
185+
type_declaration
186+
end
187+
end
188+
169189
def name
170190
first, *rest = path
171191

@@ -187,11 +207,11 @@ def ts_type
187207
end
188208

189209
def has_default?
190-
type_declaration.attribute? && default
210+
real_type_declaration.attribute? && default
191211
end
192212

193213
def default
194-
type_declaration.default
214+
real_type_declaration.default
195215
end
196216

197217
def ts_default
@@ -204,8 +224,6 @@ def name_english
204224

205225
def html_input
206226
# TODO: handle boolean, etc
207-
one_of = type_declaration.one_of
208-
209227
if one_of
210228
ts_type = generator.foobara_type_to_ts_type(type_declaration)
211229

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Foobara
22
module Generators
33
module TypescriptReactCommandFormGenerator
4-
VERSION = "0.0.5".freeze
4+
VERSION = "0.0.6".freeze
55

66
local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
77
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]

0 commit comments

Comments
 (0)