-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add recipe title in import form #4625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1638eb8
add RecipeTitleField
amed-xyz a443acd
ImportRecipeForm use recipeTitle field instead of recipeName
amed-xyz 1b6d6b8
add title uniqueness validation
amed-xyz 9c29327
update form schema validation for title requirements
amed-xyz 5aff0b0
set title onsubmit
amed-xyz ab1c25f
cosmetics
amed-xyz 9f253e5
add deprecation notice
amed-xyz d255691
Merge branch 'main' into amed/swap-recipe-title-name
amed-xyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ui/desktop/src/components/recipes/shared/RecipeTitleField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| interface RecipeTitleFieldProps { | ||
| id: string; | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| onBlur: () => void; | ||
| errors: string[]; | ||
| label?: string; | ||
| required?: boolean; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| export function RecipeTitleField({ | ||
| id, | ||
| value, | ||
| onChange, | ||
| onBlur, | ||
| errors, | ||
| label = 'Recipe Title', | ||
| required = true, | ||
| disabled = false, | ||
| }: RecipeTitleFieldProps) { | ||
| return ( | ||
| <div> | ||
| <label htmlFor={id} className="block text-sm font-medium text-text-standard mb-2"> | ||
| {label} {required && <span className="text-red-500">*</span>} | ||
| </label> | ||
| <input | ||
| id={id} | ||
| type="text" | ||
| value={value} | ||
| onChange={(e) => onChange(e.target.value)} | ||
| onBlur={onBlur} | ||
| disabled={disabled} | ||
| className={`w-full p-3 border rounded-lg bg-background-default text-text-standard focus:outline-none focus:ring-2 focus:ring-blue-500 ${ | ||
| errors.length > 0 ? 'border-red-500' : 'border-border-subtle' | ||
| } ${disabled ? 'opacity-50 cursor-not-allowed' : ''}`} | ||
| placeholder="My Recipe Title" | ||
| /> | ||
| <p className="text-xs text-text-muted mt-1"> | ||
| This will be the display name shown in your recipe library | ||
| </p> | ||
| {errors.length > 0 && <p className="text-red-500 text-sm mt-1">{errors[0]}</p>} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { validateRecipe, getValidationErrorMessages } from './validation'; | |
|
|
||
| export interface SaveRecipeOptions { | ||
| name: string; | ||
| title?: string; | ||
| global?: boolean; // true for global (~/.config/goose/recipes/), false for project-specific (.goose/recipes/) | ||
| } | ||
|
|
||
|
|
@@ -70,12 +71,23 @@ async function saveRecipeToFile(recipe: SavedRecipe): Promise<boolean> { | |
| * Save a recipe to a file using IPC. | ||
| */ | ||
| export async function saveRecipe(recipe: Recipe, options: SaveRecipeOptions): Promise<string> { | ||
| const { name, global = true } = options; | ||
| const { name, title, global = true } = options; | ||
|
|
||
| // Sanitize name | ||
| const sanitizedName = sanitizeRecipeName(name); | ||
| if (!sanitizedName) { | ||
| throw new Error('Invalid recipe name'); | ||
| let sanitizedName: string; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call it
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually for setting the recipe's name derived from the title |
||
|
|
||
| if (title) { | ||
| recipe.title = title.trim(); | ||
| sanitizedName = generateRecipeFilename(recipe); | ||
| if (!sanitizedName) { | ||
| throw new Error('Invalid recipe title - cannot generate filename'); | ||
| } | ||
| } else { | ||
| // This branch should now be considered deprecated and will be removed once the same functionality | ||
| // is incorporated in CreateRecipeForm | ||
| sanitizedName = sanitizeRecipeName(name); | ||
| if (!sanitizedName) { | ||
| throw new Error('Invalid recipe name'); | ||
| } | ||
| } | ||
|
|
||
| const validationResult = validateRecipe(recipe); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameshould now be considered deprecated and will be removed once the same functionality is incorporated in recipe creation formUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a drawback to continuing to set name for now for backwards compatibility purposes? Also we might want to indicate that its deprecated in the api/types and check that its actually ok to deprecate from a backend perspective before we deprecate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No drawback, but
value.recipeNameused to come from an input field that's been replaced byvalue.recipeTitle. We're still setting and using recipe's name inrecipeStorage.saveRecipethough, it's just derived from the name now.Although we're not fully deprecating it. The only thing changing is that we no longer set it directly from this form, it's rather derived from the recipe title, which the user can now control