How card management works in DeskHog
mainDeskHog uses a system of Card Definitions and Card Configurations to manage the UI.
- Card Definitions (
CardDefinition) represent the available types of cards (e.g., a PostHog Insight) that a user can choose to add. These are registered in theCardControllerand include afactoryfunction to create the UI component. - Card Configurations (
CardConfig) represent the active instances of cards currently displayed on the screen. These are stored in persistent memory as a JSON array.
When a user modifies their configuration via the Web UI or API, the CardController performs a reconciliation: it diffs the new configuration against the currently displayed cards, removes obsolete ones, creates new ones using their registered factory functions, and re-orders the CardNavigationStack to match the new order.
// Example of the relationship between a definition and a config
// A definition tells you WHAT can be added
struct CardDefinition {
CardType id;
String name;
bool allowMultiple;
bool needsConfigInput;
String configInputLabel;
String uiDescription;
std::function<lv_obj_t*(const String& configValue)> factory;
};
// A config tells you WHAT IS currently active
struct CardConfig {
CardType id;
String config; // e.g., insight ID, animation speed
int order;
};