Feature: Labels
Relevant source files
The following files were used as context for generating this wiki page:
- api/src/controllers/project-label.controller.ts
- webapp/src/app/projects/components/labels-list/labels-list.component.ts
- webapp/src/app/projects/stores/project-label.state.ts
- api/test/project-label.e2e-spec.ts
- api/src/domain/http.ts
- webapp/src/app/projects/projects.module.ts
- webapp/src/app/projects/components/labels-list/labels-list.component.html
The Labels feature provides a way to categorize and organize translation terms and their corresponding translations within a project. Users can create custom labels with specific names and colors, apply them to one or more terms, and also apply them to individual translations. This allows for flexible workflows, such as marking terms as "needs review", "work in progress", or "approved".
Labels are managed on a per-project basis. When a label is applied to a term, it automatically propagates to all existing translations of that term. This ensures consistency across different locales. However, labels can also be managed independently on each translation, allowing for granular control over the translation status for each language.
Data Model
The core of the feature is the Label entity, which is associated with a project and can be linked to multiple terms and translations.
Label Entity
The Label entity stores the name and color of the label. It is uniquely identified by its id and is always associated with a single Project.
| Column | Type | Constraints | Description |
|---|---|---|---|
id | string (UUID) | Primary Key | Unique identifier for the label. |
value | string | Not Null, Length (1-255) | The text content of the label (e.g., "todo"). |
color | string | Not Null, Length (7), HEX Color | The HEX color code for the label's display (e.g., "#202020"). |
project | Project | Many-to-One | The project to which this label belongs. |
terms | Term[] | Many-to-Many | The terms that have this label. |
translations | Translation[] | Many-to-Many | The translations that have this label. |
Sources: api/src/controllers/project-label.controller.ts:13, api/src/domain/http.ts:182-188, 482-498
Entity Relationships
The diagram below illustrates the relationships between the Label entity and other key entities like Project, Term, and Translation.
This ER diagram shows that a Project can have many Labels. A Label can be applied to many Terms and many Translations, forming many-to-many relationships.
Sources: api/src/controllers/project-label.controller.ts:143-147, 217-221
Backend API
The backend functionality for labels is exposed through a REST API, handled by the ProjectLabelController. This controller manages all CRUD operations for labels and the logic for assigning and un-assigning them to terms and translations.
Sources: api/src/controllers/project-label.controller.ts
API Endpoints
The following table summarizes the available API endpoints for managing labels. Access to these endpoints requires authentication and specific project roles.
| Method | Path | Description | Required Role(s) |
|---|---|---|---|
GET | /api/v1/projects/:projectId/labels | List all labels for a project. | ViewLabel |
POST | /api/v1/projects/:projectId/labels | Create a new label for a project. | AddLabel |
PATCH | /api/v1/projects/:projectId/labels/:labelId | Update an existing label's value and/or color. | EditLabel |
DELETE | /api/v1/projects/:projectId/labels/:labelId | Delete a label from a project. | DeleteLabel |
POST | /api/v1/projects/:projectId/labels/:labelId/terms/:termId | Assign a label to a specific term. | EditLabel |
DELETE | /api/v1/projects/:projectId/labels/:labelId/terms/:termId | Remove a label from a specific term. | EditLabel |
POST | /api/v1/projects/:projectId/labels/:labelId/terms/:termId/translations/:localeCode | Assign a label to a specific translation. | EditLabel |
DELETE | /api/v1/projects/:projectId/labels/:labelId/terms/:termId/translations/:localeCode | Remove a label from a specific translation. | EditLabel |
Sources: api/src/controllers/project-label.controller.ts:25-257, api/test/project-label.e2e-spec.ts
Label Management Flow
This sequence diagram shows the process of creating a new label. The user's request is handled by the ProjectLabelController, which authorizes the action, creates a new Label entity, saves it to the database, and returns the created label data.
Label Propagation
A key behavior of the labels feature is propagation. When a label is applied to a term, the system automatically applies that same label to all existing translations associated with that term. This ensures that the status indicated by the label is reflected across all locales.
The following sequence diagram illustrates this propagation logic.
Frontend Implementation
The web application uses Angular and NGXS for state management to provide a reactive UI for managing labels.
Sources: webapp/src/app/projects/projects.module.ts:20, 42
Components
LabelsListComponent
This is the main component for viewing and managing labels within a project. It is responsible for:
- Displaying a list of all labels for the current project.
- Providing a UI to create new labels.
- Allowing users to edit or delete existing labels.
- Searching and filtering the list of labels.
The component interacts with the NGXS store to fetch data and dispatch actions for creating, updating, and deleting labels.
Sources: webapp/src/app/projects/components/labels-list/labels-list.component.ts, webapp/src/app/projects/components/labels-list/labels-list.component.html
State Management (NGXS)
Label-related state is managed in the ProjectLabelState. This includes the list of labels, loading status, and error messages.
Sources: webapp/src/app/projects/stores/project-label.state.ts
State Model
The ProjectLabelStateModel defines the shape of the state for project labels.
export interface ProjectLabelStateModel {
labels: Label[];
isLoading: boolean;
errorMessage: string | undefined;
}
Sources: webapp/src/app/projects/stores/project-label.state.ts:100-104
Actions
The state is modified by dispatching actions. The following actions are defined for managing labels:
| Action | Description | Payload |
|---|---|---|
GetProjectLabels | Fetches all labels for a given project. | projectId: string |
CreateProjectLabel | Creates a new label. | projectId: string, value: string, color: string |
UpdateProjectLabel | Updates an existing label. | projectId: string, labelId: string, value: string, color: string |
RemoveProjectLabel | Deletes a label. | projectId: string, labelId: string |
LabelTerm | Applies a label to a term. | projectId: string, label: Label, termId: string |
UnlabelTerm | Removes a label from a term. | projectId: string, label: Label, termId: string |
LabelTranslation | Applies a label to a translation. | projectId: string, label: Label, termId: string, localeCode: string |
UnlabelTranslation | Removes a label from a translation. | projectId: string, label: Label, termId: string, localeCode: string |
ClearMessages | Clears any error messages from the state. | - |
Sources: webapp/src/app/projects/stores/project-label.state.ts:11-98
Frontend Data Flow
The following diagram shows the data flow when a user creates a new label from the LabelsListComponent.
This flow demonstrates the unidirectional data flow pattern used in the frontend. The component dispatches an action, the state handler calls a service to perform the API request, and upon success, the state is updated, which automatically updates the component's view.
Sources: webapp/src/app/projects/components/labels-list/labels-list.component.ts:80-84, webapp/src/app/projects/stores/project-label.state.ts:153-166
Conclusion
The Labels feature is an integral part of project organization in Traduora. It provides a robust system for categorizing terms and translations through a well-defined data model, a comprehensive REST API, and a reactive frontend implementation. The automatic propagation of labels from terms to translations streamlines the workflow, while the ability to label individual translations offers fine-grained control, making it a powerful tool for managing the translation lifecycle.