CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lightdash--common

Shared TypeScript library for the Lightdash platform containing common types, utilities, and business logic for analytics workflows

Overall
score

72%

Evaluation72%

1.09x

Agent success when using this tile

Overview
Eval results
Files

feature-flags.mddocs/api/types/

Feature Flags

Feature flag definitions for controlling experimental and optional features in Lightdash.

Capabilities

Feature Flags Enum

Enumeration of all available feature flags in the system.

enum FeatureFlags {
  /** Show user groups functionality */
  UserGroupsEnabled = 'user-groups-enabled',

  /** Send local timezone to the warehouse session */
  EnableUserTimezones = 'enable-user-timezones',

  /** Enable dashboard comments */
  DashboardComments = 'dashboard-comments-enabled',

  /** Enable scheduler task that replaces custom metrics after project compile */
  ReplaceCustomMetricsOnCompile = 'replace-custom-metrics-on-compile',

  /**
   * Enable the dynamic calculation of series color, when not manually set on the chart config.
   * This aims to make the colors more consistent, depending on the groups.
   */
  CalculateSeriesColor = 'calculate-series-color',

  /** Enable the ability to write back custom bin dimensions to dbt */
  WriteBackCustomBinDimensions = 'write-back-custom-bin-dimensions',

  /** Enable the ability to show the warehouse execution time and total time in the chart tile */
  ShowExecutionTime = 'show-execution-time',

  /** Enable the ability to create custom visualizations with AI */
  AiCustomViz = 'ai-custom-viz',

  /** Enable BigQuery SSO authentication */
  BigquerySSO = 'bigquery-sso',

  /** Use workers for async query execution */
  WorkerQueryExecution = 'worker-query-execution',

  /** Enable SQL pivot results conversion to PivotData format */
  UseSqlPivotResults = 'use-sql-pivot-results',

  /** Enable map chart type visualization */
  Maps = 'maps',

  /** Enable the unused content dashboard showing least viewed charts and dashboards */
  UnusedContentDashboard = 'unused-content-dashboard',

  /** Enable period-over-period comparisons option */
  PeriodOverPeriod = 'pop',

  /** Dark mode */
  DarkMode = 'dark-mode'
}

Feature Flag Type

Type for representing a feature flag with its enabled status.

interface FeatureFlag {
  id: string;
  enabled: boolean;
}

Feature Flag Type Guard

Type guard for checking if a string is a valid feature flag.

/**
 * Check if a value is a valid FeatureFlags enum value
 * @param value - String value to check
 * @returns True if value is a valid feature flag
 */
function isFeatureFlags(value: string): value is FeatureFlags;

Usage Examples

Checking Feature Flags

import { FeatureFlags, type FeatureFlag } from '@lightdash/common';

// Check if dark mode is enabled
function isDarkModeEnabled(flags: FeatureFlag[]): boolean {
  const darkModeFlag = flags.find(flag => flag.id === FeatureFlags.DarkMode);
  return darkModeFlag?.enabled ?? false;
}

// Check multiple feature flags
function getEnabledFeatures(flags: FeatureFlag[]): string[] {
  return flags
    .filter(flag => flag.enabled)
    .map(flag => flag.id);
}

Conditional Feature Rendering

import { FeatureFlags, isFeatureFlags } from '@lightdash/common';

function shouldShowFeature(featureFlagId: string, enabledFlags: FeatureFlag[]): boolean {
  // Validate the feature flag exists
  if (!isFeatureFlags(featureFlagId)) {
    console.warn(`Unknown feature flag: ${featureFlagId}`);
    return false;
  }

  const flag = enabledFlags.find(f => f.id === featureFlagId);
  return flag?.enabled ?? false;
}

// Usage example
const showMaps = shouldShowFeature(FeatureFlags.Maps, userFeatureFlags);
const showAiViz = shouldShowFeature(FeatureFlags.AiCustomViz, userFeatureFlags);

Feature Flag Configuration

import { FeatureFlags, type FeatureFlag } from '@lightdash/common';

// Create a feature flag configuration
const defaultFlags: FeatureFlag[] = [
  { id: FeatureFlags.EnableUserTimezones, enabled: true },
  { id: FeatureFlags.DashboardComments, enabled: true },
  { id: FeatureFlags.DarkMode, enabled: false },
  { id: FeatureFlags.AiCustomViz, enabled: false },
  { id: FeatureFlags.Maps, enabled: false }
];

// Helper to check if experimental features are enabled
function hasExperimentalFeatures(flags: FeatureFlag[]): boolean {
  const experimentalFlags = [
    FeatureFlags.AiCustomViz,
    FeatureFlags.Maps,
    FeatureFlags.CalculateSeriesColor
  ];

  return flags.some(flag =>
    experimentalFlags.includes(flag.id as FeatureFlags) && flag.enabled
  );
}

Feature Flag Categories

User Experience

  • EnableUserTimezones - Timezone support for queries
  • DarkMode - Dark theme support

Collaboration

  • DashboardComments - Dashboard commenting functionality
  • UserGroupsEnabled - User groups and permissions

Analytics & Visualizations

  • Maps - Geographic map visualizations
  • AiCustomViz - AI-powered custom visualizations
  • CalculateSeriesColor - Dynamic series color calculation
  • PeriodOverPeriod - Period comparison analysis

Performance & Infrastructure

  • WorkerQueryExecution - Async query execution with workers
  • UseSqlPivotResults - SQL-based pivot results
  • ShowExecutionTime - Query execution time display

Data Warehouse Integration

  • BigquerySSO - BigQuery SSO authentication
  • WriteBackCustomBinDimensions - Write custom bins to dbt

Content Management

  • UnusedContentDashboard - Content usage analytics
  • ReplaceCustomMetricsOnCompile - Auto-update custom metrics

Install with Tessl CLI

npx tessl i tessl/npm-lightdash--common

docs

api

index.md

tile.json