dashboard

package
v0.140.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 12 Imported by: 0

README

admin/internal/dashboard

Dashboard-related helpers and CMS-backed widget persistence.

Purpose

  • Centralize widget area/definition bootstrapping and provider wiring helpers.
  • Provide a CMS-backed store for widget instances (used by go-dashboard integration).

Key Files

  • types.go: Core dashboard/widget types shared with CMS bindings.
  • helpers.go: Widget areas/definitions + provider wiring helpers.
  • cms_widget_store.go: Widget instance store backed by CMS widget services.

Dependencies

  • May depend on CMS interfaces via admin/internal/cmsboot type aliases.
  • Must not import other peer feature packages (navigation, settings, etc).

Where To Change X

  • Default areas/definitions: helpers.go.
  • CMS widget instance persistence behavior: cms_widget_store.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractWidgetData added in v0.32.0

func ExtractWidgetData(meta map[string]any) map[string]any

ExtractWidgetData returns widget data from metadata in canonical map form.

func HiddenFromMetadata added in v0.32.0

func HiddenFromMetadata(meta map[string]any) bool

HiddenFromMetadata reports whether metadata marks the widget hidden.

func LocaleFromMetadata added in v0.32.0

func LocaleFromMetadata(meta map[string]any) string

LocaleFromMetadata extracts an optional widget locale from metadata.

func NumericToInt added in v0.32.0

func NumericToInt(val any) int

NumericToInt coerces numeric-ish values used in dashboard metadata.

func OrderFromMetadata added in v0.32.0

func OrderFromMetadata(meta map[string]any) int

OrderFromMetadata extracts explicit widget ordering from metadata.

func OrderedAreaCodes added in v0.32.0

func OrderedAreaCodes(areaMap map[string][]dashcmp.WidgetInstance) []string

OrderedAreaCodes returns dashboard layout areas in preferred order with extras sorted.

func RegisterDefaultWidgets

func RegisterDefaultWidgets(widgetSvc WidgetService, features FeatureFlags, registerProviders func() error) error

RegisterDefaultWidgets seeds default widget definitions and optionally invokes a provider registration callback.

func RegisterProviders

func RegisterProviders(host ProviderHost, widgetSvc WidgetService, auth Authorizer, features FeatureFlags, register func() error) error

RegisterProviders wires dashboard dependencies before invoking the provided registration callback.

func RegisterWidgetAreas

func RegisterWidgetAreas(registrar DashboardAreaRegistrar, widgetSvc WidgetService, features FeatureFlags) error

RegisterWidgetAreas seeds default widget areas into the dashboard or widget service.

func SanitizeWidgetData added in v0.32.0

func SanitizeWidgetData(data map[string]any) map[string]any

SanitizeWidgetData removes blocked payload fields and scrubs unsafe HTML-like values.

func SpanFromMetadata added in v0.32.0

func SpanFromMetadata(meta map[string]any) int

SpanFromMetadata extracts the widget width/span from layout metadata.

Types

type ActivityRecorder

type ActivityRecorder interface {
	RecordWidgetEvent(ctx context.Context, action string, inst godash.WidgetInstance)
}

ActivityRecorder captures widget lifecycle events for auditing/telemetry.

type Authorizer

type Authorizer interface {
	Can(ctx context.Context, action string, resource string) bool
}

Authorizer determines whether a subject can perform an action on a resource.

type CMSWidgetStore

type CMSWidgetStore struct {
	// contains filtered or unexported fields
}

CMSWidgetStore adapts the admin CMSWidgetService to go-dashboard's WidgetStore interface. It uses the underlying service for persistence and maps fields between the two models.

func NewCMSWidgetStore

func NewCMSWidgetStore(svc WidgetService) *CMSWidgetStore

NewCMSWidgetStore builds a widget store backed by the provided CMS widget service.

func NewCMSWidgetStoreWithActivity

func NewCMSWidgetStoreWithActivity(svc WidgetService, recorder ActivityRecorder) *CMSWidgetStore

NewCMSWidgetStoreWithActivity wires an optional activity recorder for widget events.

func (*CMSWidgetStore) AssignInstance

func (s *CMSWidgetStore) AssignInstance(ctx context.Context, input godash.AssignWidgetInput) error

AssignInstance associates a widget with an area and optional position.

func (*CMSWidgetStore) CreateInstance

CreateInstance stores a widget instance.

func (*CMSWidgetStore) DeleteInstance

func (s *CMSWidgetStore) DeleteInstance(ctx context.Context, instanceID string) error

DeleteInstance removes a widget instance.

func (*CMSWidgetStore) EnsureArea

func (s *CMSWidgetStore) EnsureArea(ctx context.Context, def godash.WidgetAreaDefinition) (bool, error)

EnsureArea registers an area definition when missing.

func (*CMSWidgetStore) EnsureDefinition

func (s *CMSWidgetStore) EnsureDefinition(ctx context.Context, def godash.WidgetDefinition) (bool, error)

EnsureDefinition registers a widget definition when missing.

func (*CMSWidgetStore) GetInstance

func (s *CMSWidgetStore) GetInstance(ctx context.Context, instanceID string) (godash.WidgetInstance, error)

GetInstance fetches a widget instance by ID.

func (*CMSWidgetStore) ReorderArea

func (s *CMSWidgetStore) ReorderArea(ctx context.Context, input godash.ReorderAreaInput) error

ReorderArea reassigns positions within an area.

func (*CMSWidgetStore) ResolveArea

ResolveArea returns the widgets for an area.

func (*CMSWidgetStore) UpdateInstance

UpdateInstance updates an existing widget instance.

type DashboardAreaRegistrar

type DashboardAreaRegistrar interface {
	Areas() []WidgetAreaDefinition
	RegisterArea(def WidgetAreaDefinition)
}

DashboardAreaRegistrar exposes minimal area registration hooks.

type DashboardPreferences

type DashboardPreferences interface {
	ForUser(userID string) []DashboardWidgetInstance
	Save(userID string, layout []DashboardWidgetInstance) error
}

DashboardPreferences stores per-user layouts.

type DashboardPreferencesWithContext

type DashboardPreferencesWithContext interface {
	DashboardPreferences
	ForUserWithContext(ctx context.Context, userID string) []DashboardWidgetInstance
	SaveWithContext(ctx context.Context, userID string, layout []DashboardWidgetInstance) error
}

DashboardPreferencesWithContext allows contextual access to preferences (for activity/locale-aware stores).

type DashboardWidgetInstance

type DashboardWidgetInstance struct {
	ID             string         `json:"id,omitempty"`
	DefinitionCode string         `json:"definition"`
	AreaCode       string         `json:"area"`
	Config         map[string]any `json:"config,omitempty"`
	Position       int            `json:"position,omitempty"`
	Span           int            `json:"span,omitempty"`
	Hidden         bool           `json:"hidden,omitempty"`
	Locale         string         `json:"locale,omitempty"`
}

DashboardWidgetInstance represents a widget placed in an area.

func CloneDashboardInstances

func CloneDashboardInstances(in []DashboardWidgetInstance) []DashboardWidgetInstance

CloneDashboardInstances copies widget instances.

type FeatureFlags

type FeatureFlags struct {
	CMS       bool `json:"cms"`
	Dashboard bool `json:"dashboard"`
	Settings  bool `json:"settings"`
}

FeatureFlags captures the minimal flags needed for dashboard helpers.

type GoDashPreferenceStore added in v0.32.0

type GoDashPreferenceStore struct {
	// contains filtered or unexported fields
}

GoDashPreferenceStore adapts persisted dashboard overrides to the go-dashboard preference store contract.

func NewGoDashPreferenceStore added in v0.32.0

func NewGoDashPreferenceStore(backend LayoutPreferenceBackend, store godash.WidgetStore, opts ...GoDashPreferenceStoreOption) *GoDashPreferenceStore

NewGoDashPreferenceStore builds the dashboard-local go-dashboard preference bridge.

func (*GoDashPreferenceStore) LayoutOverrides added in v0.32.0

LayoutOverrides returns persisted overrides for a viewer in go-dashboard format.

func (*GoDashPreferenceStore) SaveLayoutOverrides added in v0.32.0

func (s *GoDashPreferenceStore) SaveLayoutOverrides(ctx context.Context, viewer godash.ViewerContext, overrides godash.LayoutOverrides) error

SaveLayoutOverrides persists go-dashboard overrides and the derived dashboard layout.

type GoDashPreferenceStoreOption added in v0.32.0

type GoDashPreferenceStoreOption func(*GoDashPreferenceStore)

GoDashPreferenceStoreOption configures the dashboard-local go-dashboard preference bridge.

func WithMissingViewerUserIDError added in v0.32.0

func WithMissingViewerUserIDError(fn func() error) GoDashPreferenceStoreOption

WithMissingViewerUserIDError preserves caller-specific missing-viewer error contracts.

type InMemoryDashboardPreferences

type InMemoryDashboardPreferences struct {
	// contains filtered or unexported fields
}

InMemoryDashboardPreferences stores layouts in memory.

func NewInMemoryDashboardPreferences

func NewInMemoryDashboardPreferences() *InMemoryDashboardPreferences

NewInMemoryDashboardPreferences constructs a preference store.

func (*InMemoryDashboardPreferences) ForUser

ForUser returns the saved layout for a user.

func (*InMemoryDashboardPreferences) Save

Save stores a user layout.

type LayoutPreferenceBackend added in v0.32.0

type LayoutPreferenceBackend interface {
	LoadDashboardLayoutOverrides(ctx context.Context, userID string) StoredLayoutOverrides
	SaveDashboardLayoutOverrides(ctx context.Context, userID string, overrides StoredLayoutOverrides) error
	SaveDashboardLayout(ctx context.Context, userID string, layout []DashboardWidgetInstance) error
}

LayoutPreferenceBackend exposes the persistence hooks needed by the go-dashboard preference bridge.

type ProviderHost

type ProviderHost interface {
	WithWidgetService(WidgetService)
	WithAuthorizer(Authorizer)
}

ProviderHost exposes wiring hooks needed before registering providers.

type StoredLayoutOverrides added in v0.32.0

type StoredLayoutOverrides struct {
	Locale        string                       `json:"locale,omitempty"`
	AreaOrder     map[string][]string          `json:"area_order,omitempty"`
	AreaRows      map[string][]StoredLayoutRow `json:"area_rows,omitempty"`
	HiddenWidgets map[string]bool              `json:"hidden_widgets,omitempty"`
}

StoredLayoutOverrides is the dashboard-local persisted override contract.

type StoredLayoutRow added in v0.32.0

type StoredLayoutRow struct {
	Widgets []StoredLayoutSlot `json:"widgets,omitempty"`
}

StoredLayoutRow captures a persisted row of widget slots.

type StoredLayoutSlot added in v0.32.0

type StoredLayoutSlot struct {
	ID    string `json:"id"`
	Width int    `json:"width"`
}

StoredLayoutSlot captures a persisted widget slot.

type WidgetAreaDefinition

type WidgetAreaDefinition struct {
	Code  string `json:"code"`
	Name  string `json:"name"`
	Scope string `json:"scope"`
}

WidgetAreaDefinition captures CMS widget area metadata.

func DefaultAreaDefinitions added in v0.27.0

func DefaultAreaDefinitions() []WidgetAreaDefinition

DefaultAreaDefinitions returns the built-in dashboard area definitions.

type WidgetDefinition

type WidgetDefinition struct {
	Code   string         `json:"code"`
	Name   string         `json:"name"`
	Schema map[string]any `json:"schema"`
}

WidgetDefinition captures admin widget metadata.

type WidgetDefinitionSyncResult added in v0.52.0

type WidgetDefinitionSyncResult struct {
	Definition WidgetDefinition           `json:"definition"`
	Status     WidgetDefinitionSyncStatus `json:"status"`
}

type WidgetDefinitionSyncStatus added in v0.52.0

type WidgetDefinitionSyncStatus string
const (
	WidgetDefinitionSyncStatusCreated   WidgetDefinitionSyncStatus = "created"
	WidgetDefinitionSyncStatusUpdated   WidgetDefinitionSyncStatus = "updated"
	WidgetDefinitionSyncStatusUnchanged WidgetDefinitionSyncStatus = "unchanged"
)

type WidgetInstance

type WidgetInstance struct {
	ID             string         `json:"id"`
	DefinitionCode string         `json:"definition_code"`
	Area           string         `json:"area"`
	PageID         string         `json:"page_id"`
	Locale         string         `json:"locale"`
	Config         map[string]any `json:"config"`
	Position       int            `json:"position"`
	Span           int            `json:"span"`
	Hidden         bool           `json:"hidden"`
}

WidgetInstance links a widget definition to a specific area/page.

type WidgetInstanceFilter

type WidgetInstanceFilter struct {
	Area            string   `json:"area"`
	PageID          string   `json:"page_id"`
	Locale          string   `json:"locale"`
	FallbackLocales []string `json:"fallback_locales,omitempty"`
}

WidgetInstanceFilter narrows widget instance queries.

type WidgetService

type WidgetService interface {
	RegisterAreaDefinition(ctx context.Context, def WidgetAreaDefinition) error
	RegisterDefinition(ctx context.Context, def WidgetDefinition) error
	SyncDefinition(ctx context.Context, def WidgetDefinition) (*WidgetDefinitionSyncResult, error)
	DeleteDefinition(ctx context.Context, code string) error
	Areas() []WidgetAreaDefinition
	Definitions() []WidgetDefinition
	SaveInstance(ctx context.Context, instance WidgetInstance) (*WidgetInstance, error)
	DeleteInstance(ctx context.Context, id string) error
	ListInstances(ctx context.Context, filter WidgetInstanceFilter) ([]WidgetInstance, error)
}

WidgetService registers dashboard widget areas/definitions and instances.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL