constant.ts

Overview

The constant.ts file serves as a centralized module for defining and exporting constant values related to route keys and their corresponding display names within the "Knowledge" domain of the application. It provides mappings between enumeration keys and human-readable route labels, enabling consistent usage of route identifiers and labels across the system. Additionally, it re-exports constants from another module to consolidate related constants in one place. This file is foundational for routing and navigation components that utilize these keys for rendering UI elements or managing application state.


Detailed Documentation

1. routeMap

export const routeMap = {
  [KnowledgeRouteKey.Dataset]: 'Dataset',
  [KnowledgeRouteKey.Testing]: 'Retrieval testing',
  [KnowledgeRouteKey.Configuration]: 'Configuration',
};
import { routeMap } from './constant';
import { KnowledgeRouteKey } from '@/constants/knowledge';

const routeLabel = routeMap[KnowledgeRouteKey.Dataset]; // "Dataset"

2. KnowledgeDatasetRouteKey (enum)

export enum KnowledgeDatasetRouteKey {
  Chunk = 'chunk',
  File = 'file',
}
import { KnowledgeDatasetRouteKey } from './constant';

const currentRoute = KnowledgeDatasetRouteKey.File; // "file"

3. datasetRouteMap

export const datasetRouteMap = {
  [KnowledgeDatasetRouteKey.Chunk]: 'Chunk',
  [KnowledgeDatasetRouteKey.File]: 'File Upload',
};
import { datasetRouteMap, KnowledgeDatasetRouteKey } from './constant';

const label = datasetRouteMap[KnowledgeDatasetRouteKey.File]; // "File Upload"

4. Re-exporting from @/constants/knowledge

export * from '@/constants/knowledge';

5. TagRenameId

export const TagRenameId = 'tagRename';
import { TagRenameId } from './constant';

function onRenameEvent(eventId: string) {
  if (eventId === TagRenameId) {
    // handle tag rename logic
  }
}

Implementation Details & Algorithms

This file is primarily declarative and does not contain algorithms or computational logic. Its role is to define clear mappings and identifiers that facilitate consistent referencing of routes and tags in the application. The use of enums and mapping objects promotes type safety and maintainability.


Interaction with Other Parts of the System


Visual Diagram: Structure of constant.ts

classDiagram
    class constant_ts {
        <<module>>
        +routeMap: Record<KnowledgeRouteKey, string>
        +KnowledgeDatasetRouteKey : enum
        +datasetRouteMap: Record<KnowledgeDatasetRouteKey, string>
        +TagRenameId: string
        +* (re-export from '@/constants/knowledge')
    }

    class KnowledgeDatasetRouteKey {
        <<enum>>
        +Chunk: string
        +File: string
    }

    constant_ts --> KnowledgeDatasetRouteKey : defines
    constant_ts --> "Record<KnowledgeRouteKey, string>" : routeMap
    constant_ts --> "Record<KnowledgeDatasetRouteKey, string>" : datasetRouteMap

Summary

The constant.ts file is a utility module that centralizes route-related constants and mappings within the Knowledge domain of the application. It enhances maintainability by providing clear, typed identifiers and labels for routes and dataset sub-routes. Its straightforward design supports consistent UI rendering and routing logic, while also consolidating exports for easier access to related constants.