Skip to content

Commit 316aa4f

Browse files
authored
fix(Frontend): Enum Registry not reflecting frontend state (#66)
1 parent 3365e45 commit 316aa4f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

fastapi_forge/frontend/state.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ModelRelationship,
2020
ProjectSpec,
2121
)
22+
from fastapi_forge.type_info_registry import enum_registry
2223

2324

2425
class ProjectState(BaseModel):
@@ -170,6 +171,7 @@ def select_enum(self, enum: CustomEnum) -> None:
170171
def delete_enum(self, enum: CustomEnum) -> None:
171172
"""Remove an enum from the project."""
172173
self.custom_enums.remove(enum)
174+
enum_registry.remove(enum.name)
173175
self._deselect_content()
174176
self._trigger_ui_refresh()
175177

@@ -182,6 +184,7 @@ def update_enum_name(self, enum: CustomEnum, new_name: str) -> None:
182184
notify_enum_exists(new_name)
183185
return
184186

187+
enum_registry.update_key(enum.name, new_name)
185188
enum.name = new_name
186189

187190
if enum == self.selected_enum and self.select_enum_fn:

fastapi_forge/type_info_registry.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TypeInfo:
2727
faker_field_value: The factory field value for this type (can be a Faker method)
2828
test_value: Value to insert into models for post/patch tests.
2929
test_func: A function to call with the `test_value`.
30-
encapsulate_assert: Wraps the `test_value` value (e.g, UUID(test_value))
30+
encapsulate_assert: Wraps the `test_value` value (e.g, "UUID" => UUID(test_value))')
3131
3232
"""
3333

@@ -58,6 +58,18 @@ def get(self, key: T) -> TypeInfo:
5858
raise KeyError(f"Key '{key}' not found.")
5959
return self._registry[key]
6060

61+
def remove(self, key: T) -> None:
62+
if key not in self:
63+
raise KeyError(f"Key '{key}' not found.")
64+
del self._registry[key]
65+
66+
def update_key(self, old_key: T, new_key: T) -> None:
67+
if old_key not in self:
68+
raise KeyError(
69+
f"Key '{old_key}' not found. All names: {self._registry.keys()}"
70+
)
71+
self._registry[new_key] = self._registry.pop(old_key)
72+
6173
def all(self) -> list[TypeInfo]:
6274
return list(self._registry.values())
6375

0 commit comments

Comments
 (0)