Search documentation of phoenix_kit

# PhoenixKit.Config.AdminDashboardCategories (phoenix_kit v1.7.87)

Copy Markdown View Source

Admin dashboard categories configuration and validation for PhoenixKit.

This module provides a comprehensive system for configuring custom admin dashboard categories with subsections, including validation, type safety, and fallback to built-in categories.

## Category Structure

Each category should have the following structure:

    %{
      title: "Category Title",
      icon: "hero-icon-name",          # Optional Heroicon name
      subsections: [
        %{
          title: "Subsection Title",
          url: "/admin/some-path",
          icon: "hero-icon-name",          # Optional Heroicon name
          description: "Brief description" # Optional
        }
      ]
    }

## Field Validation

- title: Required string, max 100 characters
- icon: Optional string, validated to be a reasonable Heroicon name
- subsections: Required list, can be empty
- subsection.title: Required string, max 100 characters
- subsection.url: Required string, must start with "/"
- subsection.icon: Optional Heroicon name validation
- subsection.description: Optional string, max 200 characters

## Usage

    # Get all configured categories with validation
    categories = PhoenixKit.Config.AdminDashboardCategories.get_categories()

    # Returns validated list like:
    [
      %{
        title: "User Management",
        icon: "hero-users",
        subsections: [
          %{
            title: "All Users",
            url: "/admin/users",
            icon: "hero-user-group",
            description: "Manage user accounts"
          }
        ]
      }
    ]

## Summary

### Functions

get_categories()

Gets admin dashboard categories with comprehensive validation and defaults.

validate_categories(categories)

Validates admin dashboard categories structure and content.

## Functions

# get_categories()

    @spec get_categories() :: list()

Gets admin dashboard categories with comprehensive validation and defaults.

This function provides a fully validated list of admin dashboard categories with proper structure validation and fallback to built-in categories.

## Examples

    iex> PhoenixKit.Config.AdminDashboardCategories.get_categories()
    [
      %{
        title: "User Management",
        icon: "hero-users",
        subsections: [
          %{
            title: "Users",
            url: "/admin/users",
            icon: "hero-user-group",
            description: "Manage user accounts"
          }
        ]
      }
    ]

# validate_categories(categories)

    @spec validate_categories(list()) :: {:ok, list()} | {:error, String.t()}

Validates admin dashboard categories structure and content.

This function can be used to validate custom categories before setting them in the configuration.

## Examples

    iex> categories = [
    ...>   %{
    ...>     title: "My Category",
    ...>     subsections: [
    ...>       %{
    ...>         title: "My Subsection",
    ...>         url: "/admin/my-path"
    ...>       }
    ...>     ]
    ...>   }
    ...> ]
    iex> PhoenixKit.Config.AdminDashboardCategories.validate_categories(categories)
    {:ok, validated_categories}