fix: filter out undefined tag names in RecipeDetail
All checks were successful
Basil CI/CD Pipeline / Code Linting (pull_request) Successful in 1m11s
Basil CI/CD Pipeline / Shared Package Tests (pull_request) Successful in 1m10s
Basil CI/CD Pipeline / Web Tests (pull_request) Successful in 1m20s
Basil CI/CD Pipeline / API Tests (pull_request) Successful in 1m39s
Basil CI/CD Pipeline / Security Scanning (pull_request) Successful in 1m11s
Basil CI/CD Pipeline / Build All Packages (pull_request) Successful in 1m31s
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
All checks were successful
Basil CI/CD Pipeline / Code Linting (pull_request) Successful in 1m11s
Basil CI/CD Pipeline / Shared Package Tests (pull_request) Successful in 1m10s
Basil CI/CD Pipeline / Web Tests (pull_request) Successful in 1m20s
Basil CI/CD Pipeline / API Tests (pull_request) Successful in 1m39s
Basil CI/CD Pipeline / Security Scanning (pull_request) Successful in 1m11s
Basil CI/CD Pipeline / Build All Packages (pull_request) Successful in 1m31s
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 filter to remove undefined values when extracting tag names - Add null check in render to skip undefined tags - Ensures type safety with (string | RecipeTag)[] type
This commit is contained in:
@@ -127,9 +127,11 @@ function RecipeDetail() {
|
||||
const trimmedTag = tagInput.trim();
|
||||
|
||||
// Convert existing tags to string array (handle both string and object formats)
|
||||
const existingTagNames = (recipe.tags || []).map(tagItem =>
|
||||
typeof tagItem === 'string' ? tagItem : tagItem.tag?.name || tagItem.name
|
||||
);
|
||||
const existingTagNames = (recipe.tags || [])
|
||||
.map(tagItem =>
|
||||
typeof tagItem === 'string' ? tagItem : tagItem.tag?.name || tagItem.name
|
||||
)
|
||||
.filter((tag): tag is string => tag !== undefined);
|
||||
|
||||
// Check if tag already exists on recipe
|
||||
if (existingTagNames.includes(trimmedTag)) {
|
||||
@@ -168,9 +170,11 @@ function RecipeDetail() {
|
||||
try {
|
||||
setSavingTags(true);
|
||||
// Convert existing tags to string array and filter out the removed tag
|
||||
const existingTagNames = (recipe.tags || []).map(tagItem =>
|
||||
typeof tagItem === 'string' ? tagItem : tagItem.tag?.name || tagItem.name
|
||||
);
|
||||
const existingTagNames = (recipe.tags || [])
|
||||
.map(tagItem =>
|
||||
typeof tagItem === 'string' ? tagItem : tagItem.tag?.name || tagItem.name
|
||||
)
|
||||
.filter((tag): tag is string => tag !== undefined);
|
||||
const updatedTags = existingTagNames.filter(tag => tag !== tagToRemove);
|
||||
await recipesApi.update(id, { tags: updatedTags });
|
||||
|
||||
@@ -265,6 +269,7 @@ function RecipeDetail() {
|
||||
recipe.tags.map(tagItem => {
|
||||
// Handle both string tags and object tags from API
|
||||
const tagName = typeof tagItem === 'string' ? tagItem : tagItem.tag?.name || tagItem.name;
|
||||
if (!tagName) return null; // Skip if tagName is undefined
|
||||
return (
|
||||
<span key={tagName} className="tag-chip-inline">
|
||||
{tagName}
|
||||
|
||||
Reference in New Issue
Block a user