mirror of
https://github.com/callumalpass/tasknotes.git
synced 2026-07-22 12:50:26 +00:00
Merge pull request #600 from callumalpass:bug/custom-property-display
Fix custom property duplication and total tracked time visibility
This commit is contained in:
commit
9626afa52f
3 changed files with 33 additions and 39 deletions
|
|
@ -54,7 +54,7 @@ export function renderAppearanceTab(container: HTMLElement, plugin: TaskNotesPlu
|
|||
plugin.settings.userFields.forEach(field => {
|
||||
if (field.displayName && field.key) {
|
||||
propertyGroups.user.push({
|
||||
key: field.key,
|
||||
key: `user:${field.id}`,
|
||||
label: field.displayName
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ const PROPERTY_RENDERERS: Record<string, PropertyRenderer> = {
|
|||
}
|
||||
},
|
||||
'totalTrackedTime': (element, value, _, plugin) => {
|
||||
if (typeof value === 'number') {
|
||||
if (typeof value === 'number' && value > 0) {
|
||||
element.textContent = `${plugin.formatTime(value)} tracked`;
|
||||
}
|
||||
},
|
||||
|
|
@ -1108,24 +1108,6 @@ export function createTaskCard(task: TaskInfo, plugin: TaskNotesPlugin, visibleP
|
|||
}
|
||||
}
|
||||
|
||||
// Legacy: Add time spent information if timeEstimate or totalTrackedTime properties are not explicitly configured
|
||||
const timeSpent = calculateTotalTimeSpent(task.timeEntries || []);
|
||||
const hasTimeEstimate = propertiesToShow.includes('timeEstimate');
|
||||
const hasTotalTrackedTime = propertiesToShow.includes('totalTrackedTime');
|
||||
if (!hasTimeEstimate && !hasTotalTrackedTime && (task.timeEstimate || timeSpent > 0)) {
|
||||
const timeInfo: string[] = [];
|
||||
if (timeSpent > 0) {
|
||||
timeInfo.push(`${plugin.formatTime(timeSpent)} spent`);
|
||||
}
|
||||
if (task.timeEstimate) {
|
||||
timeInfo.push(`${plugin.formatTime(task.timeEstimate)} estimated`);
|
||||
}
|
||||
const timeSpan = metadataLine.createEl('span', {
|
||||
cls: 'task-card__metadata-property task-card__metadata-property--time'
|
||||
});
|
||||
timeSpan.textContent = timeInfo.join(', ');
|
||||
metadataElements.push(timeSpan);
|
||||
}
|
||||
|
||||
// Add separators between metadata elements
|
||||
addMetadataSeparators(metadataLine, metadataElements);
|
||||
|
|
@ -1620,24 +1602,6 @@ export function updateTaskCard(element: HTMLElement, task: TaskInfo, plugin: Tas
|
|||
}
|
||||
}
|
||||
|
||||
// Legacy: Add time spent information if timeEstimate or totalTrackedTime properties are not explicitly configured
|
||||
const timeSpent = calculateTotalTimeSpent(task.timeEntries || []);
|
||||
const hasTimeEstimate = propertiesToShow.includes('timeEstimate');
|
||||
const hasTotalTrackedTime = propertiesToShow.includes('totalTrackedTime');
|
||||
if (!hasTimeEstimate && !hasTotalTrackedTime && (task.timeEstimate || timeSpent > 0)) {
|
||||
const timeInfo: string[] = [];
|
||||
if (timeSpent > 0) {
|
||||
timeInfo.push(`${plugin.formatTime(timeSpent)} spent`);
|
||||
}
|
||||
if (task.timeEstimate) {
|
||||
timeInfo.push(`${plugin.formatTime(task.timeEstimate)} estimated`);
|
||||
}
|
||||
const timeSpan = metadataLine.createEl('span', {
|
||||
cls: 'task-card__metadata-property task-card__metadata-property--time'
|
||||
});
|
||||
timeSpan.textContent = timeInfo.join(', ');
|
||||
metadataElements.push(timeSpan);
|
||||
}
|
||||
|
||||
// Add separators between metadata elements
|
||||
addMetadataSeparators(metadataLine, metadataElements);
|
||||
|
|
|
|||
|
|
@ -332,8 +332,38 @@ describe('TaskCard Component', () => {
|
|||
expect(metadataLine?.textContent).toContain('Due:');
|
||||
expect(metadataLine?.textContent).toContain('Scheduled:');
|
||||
expect(metadataLine?.textContent).toContain('@work, @urgent');
|
||||
expect(metadataLine?.textContent).toContain('30m spent');
|
||||
// Time tracking info should only show when explicitly configured as visible properties
|
||||
expect(metadataLine?.textContent).not.toContain('30m spent');
|
||||
expect(metadataLine?.textContent).not.toContain('60m estimated');
|
||||
});
|
||||
|
||||
it('should show time tracking properties when explicitly enabled', () => {
|
||||
const task = TaskFactory.createTask({
|
||||
timeEstimate: 60,
|
||||
timeEntries: [{ startTime: '2025-01-15T10:00:00Z', endTime: '2025-01-15T10:30:00Z' }],
|
||||
totalTrackedTime: 30
|
||||
});
|
||||
|
||||
// Test with timeEstimate and totalTrackedTime properties explicitly enabled
|
||||
const visibleProperties = ['timeEstimate', 'totalTrackedTime'];
|
||||
const card = createTaskCard(task, mockPlugin, visibleProperties);
|
||||
const metadataLine = card.querySelector('.task-card__metadata');
|
||||
|
||||
expect(metadataLine?.textContent).toContain('60m estimated');
|
||||
expect(metadataLine?.textContent).toContain('30m tracked');
|
||||
});
|
||||
|
||||
it('should not show totalTrackedTime when value is 0', () => {
|
||||
const task = TaskFactory.createTask({
|
||||
totalTrackedTime: 0
|
||||
});
|
||||
|
||||
// Enable totalTrackedTime property but value is 0
|
||||
const visibleProperties = ['totalTrackedTime'];
|
||||
const card = createTaskCard(task, mockPlugin, visibleProperties);
|
||||
const metadataLine = card.querySelector('.task-card__metadata');
|
||||
|
||||
expect(metadataLine?.textContent).not.toContain('tracked');
|
||||
});
|
||||
|
||||
it('should create clickable project links for wikilink projects', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue