fix(metric): add translation support for 'all tasks' title

- Add T.PM.ALL_TASKS_TITLE translation key
- Use translation pipe in metric.component.html
- Add type safety check for TODAY_TAG context
- Update tests to expect translation keys
This commit is contained in:
Johannes Millan 2026-01-16 14:21:14 +01:00
parent 30f541f6c7
commit ca377b93a2
5 changed files with 11 additions and 8 deletions

View file

@ -6,7 +6,7 @@
>
<div class="metrics-header">
<h1 class="mat-h1">
{{ metricsTitle() }}
{{ metricsTitle() | translate }}
</h1>
<share-button
[payload]="sharePayload()"

View file

@ -169,12 +169,12 @@ describe('MetricComponent', () => {
});
describe('metricsTitle computed', () => {
it('should return "Metrics (all tasks)" when viewing TODAY_TAG', () => {
it('should return PM.ALL_TASKS_TITLE when viewing TODAY_TAG', () => {
activeWorkContext$.next(
createMockWorkContext(TODAY_TAG.id, WorkContextType.TAG, 'Today'),
);
expect(component.metricsTitle()).toBe('Metrics (all tasks)');
expect(component.metricsTitle()).toBe(T.PM.ALL_TASKS_TITLE);
});
it('should return T.PM.TITLE when viewing a regular project', () => {
@ -287,7 +287,7 @@ describe('MetricComponent', () => {
createMockWorkContext(TODAY_TAG.id, WorkContextType.TAG, 'Today'),
);
expect(component.simpleMetrics()?.nrOfAllTasks).toBe(100);
expect(component.metricsTitle()).toBe('Metrics (all tasks)');
expect(component.metricsTitle()).toBe(T.PM.ALL_TASKS_TITLE);
});
it('should switch from AllTasksMetrics to ProjectMetrics when changing context', () => {
@ -302,7 +302,7 @@ describe('MetricComponent', () => {
createMockWorkContext(TODAY_TAG.id, WorkContextType.TAG, 'Today'),
);
expect(component.simpleMetrics()?.nrOfAllTasks).toBe(100);
expect(component.metricsTitle()).toBe('Metrics (all tasks)');
expect(component.metricsTitle()).toBe(T.PM.ALL_TASKS_TITLE);
// Switch to a project
activeWorkContext$.next(

View file

@ -7,6 +7,7 @@ import { T } from '../../t.const';
import { ProjectMetricsService } from './project-metrics.service';
import { AllTasksMetricsService } from './all-tasks-metrics.service';
import { WorkContextService } from '../work-context/work-context.service';
import { WorkContextType } from '../work-context/work-context.model';
import { LazyChartComponent } from './lazy-chart/lazy-chart.component';
import { DecimalPipe } from '@angular/common';
import { MsToStringPipe } from '../../ui/duration/ms-to-string.pipe';
@ -51,14 +52,14 @@ export class MetricComponent {
*/
private _isShowingAllTasks = computed(() => {
const context = this.activeWorkContext();
return context?.id === TODAY_TAG.id;
return context?.type === WorkContextType.TAG && context.id === TODAY_TAG.id;
});
/**
* Dynamic title that changes based on context
*/
metricsTitle = computed(() => {
return this._isShowingAllTasks() ? 'Metrics (all tasks)' : this.T.PM.TITLE;
return this._isShowingAllTasks() ? this.T.PM.ALL_TASKS_TITLE : this.T.PM.TITLE;
});
simpleClickCounterData = toSignal(this.metricService.getSimpleClickCounterMetrics$());

View file

@ -2188,6 +2188,7 @@ const T = {
},
PM: {
TITLE: 'PM.TITLE',
ALL_TASKS_TITLE: 'PM.ALL_TASKS_TITLE',
},
PS: {
GLOBAL_SETTINGS: 'PS.GLOBAL_SETTINGS',

View file

@ -2172,7 +2172,8 @@
"VALIDATION_FAILED": "Validation failed"
},
"PM": {
"TITLE": "Project Metrics"
"TITLE": "Project Metrics",
"ALL_TASKS_TITLE": "Metrics (all tasks)"
},
"PS": {
"GLOBAL_SETTINGS": "Global Settings",