# All files / src/components/admin/systemConfiguration utils.ts

0% Statements 0/40
0% Branches 0/22
0% Functions 0/5
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

     export const parseBoolConfig = (val: unknown) => {
      if (val === undefined || val === null) return true;
      const s = String(val).toLowerCase();
      return !['false', '0', 'off', 'no', 'none', ''].includes(s);
    };

    export const formatImportStage = (
      stage: string | null | undefined,
      t: (key: string, options?: Record<string, any>) => string
    ) => {
      if (!stage) {
        return t('systemConfiguration.dbToolsImportStageStarting', {});
      }
      const labels: Record<string, string> = {
        starting: t('systemConfiguration.dbToolsImportStageStarting', {}),
        importing: t('systemConfiguration.dbToolsImportStageImporting', {}),
        resetting_schema: t('systemConfiguration.dbToolsImportStageResetting', {}),
        restoring: t('systemConfiguration.dbToolsImportStageRestoring', {}),
        completed: t('systemConfiguration.dbToolsImportStageCompleted', {}),
        failed: t('systemConfiguration.dbToolsImportStageFailed', {})};
      if (labels[stage]) {
        return labels[stage];
      }
      return stage.replace(/_/g, ' ');
    };

    export const importStatusVariant = (status: string) => {
      switch (status) {
        case 'running':
          return 'secondary';
        case 'failed':
          return 'destructive';
        case 'completed':
          return 'default';
        default:
          return 'outline';
      }
    };

    export const formatImportTime = (timestamp?: number | null) => {
      if (!timestamp) return '-';
      return new Date(timestamp * 1000).toLocaleString();
    };

    export const formatImportDuration = (start?: number | null, end?: number | null) => {
      if (!start) return '-';
      const endTime = end ?? Math.floor(Date.now() / 1000);
      const duration = Math.max(0, endTime - start);
      const hours = Math.floor(duration / 3600);
      const minutes = Math.floor((duration % 3600) / 60);
      const seconds = duration % 60;
      if (hours > 0) {
        return `${hours}h ${minutes}m ${seconds}s`;
      }
      if (minutes > 0) {
        return `${minutes}m ${seconds}s`;
      }
      return `${seconds}s`;
    };