Garage Door OS Docs
Price Book

Category Attributes

Define custom attributes per price book category for structured item data.
7 min read

Category Attributes Feature Implementation

Overview

This feature allows category markups to store default attributes that will be automatically prepopulated when a category is selected for new items. When items are saved with attributes, those attributes are automatically merged into the category data structure for future use.

Implementation Summary

1. Updated CategoryMarkup Data Structure

File: HomeImprovment/apps/web/src/pages/settings/CategoryMarkupSettings.tsx
Added attributes field to the CategoryMarkup interface:
interface CategoryMarkup {
  id: string
  category: string
  markup: number
  description?: string
  attributes?: Record<string, string> // NEW: Category-level attributes that will be prepopulated
  isActive: boolean
  createdAt?: string
  context: 'inventory' | 'price_book' | 'services' | 'all'
}

2. Category Settings UI Enhancements

File: HomeImprovment/apps/web/src/pages/settings/CategoryMarkupSettings.tsx

Added AttributesManager to Edit Modal

  • Added AttributesManager component import
  • Added "Default Attributes (Optional)" field to the category edit form
  • Users can now add, edit, and remove default attributes for each category

Added Attributes Column to Category Table

  • Displays up to 2 attributes inline with tags
  • Shows "+X more" indicator when more than 2 attributes exist
  • Shows "No attributes" when category has no attributes

3. Inventory Item Attribute Prepopulation & Merging

File: HomeImprovment/apps/web/src/pages/inventory/Inventory.tsx

Prepopulate Attributes on Category Selection

When a user selects a category for a new inventory item:
  • Checks if the category has default attributes defined
  • Prepopulates the attributes field with category defaults (only for new items, not when editing)
  • Shows info message: "Prepopulated attributes from category [name]"

Merge Attributes When Saving Items

When a user saves an inventory item with attributes:
  • Checks if the item has a category and attributes
  • Finds the matching category markup (inventory or all context)
  • Merges the item's attributes with existing category attributes
  • Updates the category markup in business settings automatically
  • This enriches the category's attribute collection over time

4. Price Book Item Attribute Prepopulation & Merging

File: HomeImprovment/apps/web/src/pages/priceBook/PriceBook.tsx

Prepopulate Attributes on Category Selection

When a user selects a category for a new price book item:
  • Checks if the category has default attributes defined
  • Prepopulates the attributes field with category defaults (only for new items)
  • Shows info message: "Prepopulated attributes from category [name]"

Merge Attributes When Saving Items

When a user saves a price book item with attributes:
  • Checks if the item has a category and attributes
  • Finds the matching category markup (price_book or all context)
  • Merges the item's attributes with existing category attributes
  • Updates the category markup in business settings automatically
  • This enriches the category's attribute collection over time

5. Added Required Imports

  • Added AttributesManager component to CategoryMarkupSettings
  • Added useUpdateBusinessSettingsMutation to Inventory.tsx
  • Added useUpdateBusinessSettingsMutation to PriceBook.tsx

How It Works (User Flow)

Setting Up Category Attributes

  1. Go to Settings → Category Markup Settings
  2. Edit or create a category
  3. Add default attributes in the "Default Attributes (Optional)" section
  4. Save the category

Using Category Attributes in Inventory

  1. Create a new inventory item
  2. Select a category from the dropdown
  3. Attributes field auto-populates with category defaults
  4. User can edit or add more attributes
  5. When saved, any new attributes are merged back into the category

Using Category Attributes in Price Book

  1. Create a new price book item
  2. Select a category from the dropdown
  3. Attributes field auto-populates with category defaults
  4. User can edit or add more attributes
  5. When saved, any new attributes are merged back into the category

Viewing Category Attributes

  1. Go to Settings → Category Markup Settings
  2. View the "Attributes" column in the table
  3. See which attributes are associated with each category
  4. Click edit to modify attributes directly

Benefits

  1. Consistency: Ensures consistent attributes across items in the same category
  2. Efficiency: Reduces manual data entry for common attributes
  3. Flexibility: Users can still override or add custom attributes per item
  4. Learning System: Attributes automatically accumulate as items are created
  5. Centralized Management: Edit attributes for all future items from category settings

Technical Details

Attribute Merging Strategy

  • Uses spread operator to merge attributes: { ...existingAttributes, ...newAttributes }
  • New attribute values override existing ones with the same key
  • Preserves all existing attributes that don't conflict
  • Updates happen silently in the background (no user notification for merge)

Context-Aware Category Matching

  • Inventory items only use markups with context: 'inventory' or 'all'
  • Price book items only use markups with context: 'price_book' or 'all'
  • Services would use markups with context: 'services' or 'all'

Performance Considerations

  • Attribute prepopulation only happens for new items (empty attributes object)
  • Attribute merging happens after successful item creation/update
  • Failed attribute merges are logged but don't block item creation
  • Business settings update is async and doesn't block the UI

Future Enhancements (Optional)

  1. Attribute Templates: Create reusable attribute templates for common patterns
  2. Attribute Validation: Set required attributes per category
  3. Attribute Type Constraints: Define data types (text, number, date, etc.)
  4. Bulk Attribute Update: Update attributes across multiple items in a category
  5. Attribute History: Track changes to category attributes over time
  6. Attribute Suggestions: AI-powered suggestions based on item names/descriptions

Testing Checklist

  • Create category with default attributes in settings
  • Create inventory item with that category
  • Verify attributes are prepopulated
  • Save inventory item with additional attributes
  • Verify category attributes updated
  • Create price book item with same category
  • Verify attributes include both original and merged ones
  • Edit category attributes directly in settings
  • Verify changes appear for new items
  • Verify attributes display correctly in category table

Files Modified

  1. HomeImprovment/apps/web/src/pages/settings/CategoryMarkupSettings.tsx
    • Added attributes field to CategoryMarkup interface
    • Added AttributesManager to edit form
    • Added attributes column to table
  2. HomeImprovment/apps/web/src/pages/inventory/Inventory.tsx
    • Updated handleCategoryChange to prepopulate attributes
    • Updated handleItemSubmit to merge attributes into category
    • Added useUpdateBusinessSettingsMutation import
  3. HomeImprovment/apps/web/src/pages/priceBook/PriceBook.tsx
    • Updated handleCategoryChange to prepopulate attributes
    • Updated handleModalOk to merge attributes into category
    • Added useUpdateBusinessSettingsMutation import

Database/API Changes

No database schema changes required. The feature uses the existing categoryMarkups field in business settings, which is a JSON field that can accommodate the new attributes property.

Deployment Notes

  • No migration required
  • Existing categories without attributes will continue to work normally
  • Feature is backward compatible
  • No breaking changes to existing functionality