fix: properly handle RecipeTag union type in CookbookDetail
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (pull_request) Successful in 1m10s
Basil CI/CD Pipeline / Code Linting (pull_request) Successful in 1m15s
Basil CI/CD Pipeline / Web Tests (pull_request) Successful in 1m22s
Basil CI/CD Pipeline / API Tests (pull_request) Successful in 1m37s
Basil CI/CD Pipeline / Security Scanning (pull_request) Successful in 1m12s
Basil CI/CD Pipeline / Build All Packages (pull_request) Failing after 1m25s
Basil CI/CD Pipeline / E2E Tests (pull_request) Has been skipped
Basil CI/CD Pipeline / Build & Push Docker Images (pull_request) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (pull_request) Has been skipped
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (pull_request) Successful in 1m10s
Basil CI/CD Pipeline / Code Linting (pull_request) Successful in 1m15s
Basil CI/CD Pipeline / Web Tests (pull_request) Successful in 1m22s
Basil CI/CD Pipeline / API Tests (pull_request) Successful in 1m37s
Basil CI/CD Pipeline / Security Scanning (pull_request) Successful in 1m12s
Basil CI/CD Pipeline / Build All Packages (pull_request) Failing after 1m25s
Basil CI/CD Pipeline / E2E Tests (pull_request) Has been skipped
Basil CI/CD Pipeline / Build & Push Docker Images (pull_request) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (pull_request) Has been skipped
- Add name property to RecipeTag interface for backward compatibility - Add getTagName helper function to extract tag names from union type - Update tag iteration to use helper function Fixes TypeScript errors where string | RecipeTag was passed to string-only contexts. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -100,6 +100,7 @@ export interface Tag {
|
||||
|
||||
export interface RecipeTag {
|
||||
tag: Tag;
|
||||
name?: string; // Optional for backward compatibility with code that accesses .name directly
|
||||
}
|
||||
|
||||
export interface Cookbook {
|
||||
|
||||
@@ -4,6 +4,11 @@ import { CookbookWithRecipes, Recipe } from '@basil/shared';
|
||||
import { cookbooksApi } from '../services/api';
|
||||
import '../styles/CookbookDetail.css';
|
||||
|
||||
// Helper function to extract tag name from string or RecipeTag object
|
||||
const getTagName = (tag: string | { tag: { name: string } }): string => {
|
||||
return typeof tag === 'string' ? tag : tag.tag.name;
|
||||
};
|
||||
|
||||
function CookbookDetail() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
@@ -75,7 +80,7 @@ function CookbookDetail() {
|
||||
if (!cookbook) return [];
|
||||
const tagSet = new Set<string>();
|
||||
cookbook.recipes.forEach(recipe => {
|
||||
recipe.tags?.forEach(tag => tagSet.add(tag));
|
||||
recipe.tags?.forEach(tag => tagSet.add(getTagName(tag)));
|
||||
});
|
||||
return Array.from(tagSet).sort();
|
||||
};
|
||||
@@ -301,9 +306,10 @@ function CookbookDetail() {
|
||||
</div>
|
||||
{recipe.tags && recipe.tags.length > 0 && (
|
||||
<div className="recipe-tags">
|
||||
{recipe.tags.map(tag => (
|
||||
<span key={tag} className="tag">{tag}</span>
|
||||
))}
|
||||
{recipe.tags.map(tag => {
|
||||
const tagName = getTagName(tag);
|
||||
return <span key={tagName} className="tag">{tagName}</span>;
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user