Skip to content

Commit 7c43690

Browse files
jsonifyclaude
andauthored
feat: Template Browser Phase 3 - Usage Guidance & Context (#96) (#104)
* feat: Template Browser Phase 3 - Usage Guidance & Context (#96) Adds contextual guidance fields to help users understand when and how to use each template: **New Template Fields:** - when_to_use: Brief description of ideal usage scenarios - use_cases: Array of 2-4 specific example scenarios - prerequisites: Knowledge or setup requirements - related_templates: Template IDs for discovery and cross-linking - estimated_time: Time to complete the template **Changes:** - Updated Template interface in TemplateTypes.ts with new optional guidance fields - Added comprehensive guidance metadata to all 5 built-in templates in constants.ts - Enhanced Template Browser UI with collapsible guidance sections - Added CSS styling for guidance display (labels, lists, related templates, time badges) - JavaScript toggle function for expanding/collapsing guidance sections **Implementation Details:** - Guidance section displays only when at least one guidance field is present - Collapsible design with smooth toggle animation matching preview sections - Visual hierarchy with icons for each guidance type (📌 When to Use, 💡 Use Cases, ✅ Prerequisites, 🔗 Related Templates) - Time estimate badge displayed in toggle button header (⏱️) - Related templates shown as clickable tags for future navigation - Custom templates from JSON files can also include these guidance fields Fixes #96 * fix: Address security and code quality issues in Template Browser **Critical Security Fix:** - Fixed XSS vulnerability in onclick handlers by replacing all inline event handlers with event delegation - Replaced onclick="function('${templateId}')" pattern with data-command and data-* attributes - Implemented single master event listener using event.target.closest('[data-command]') - Template IDs and user-controllable data no longer executed as JavaScript code **Code Quality Improvements:** - Added validation warning for missing built-in template metadata - Optimized CSS transition from 'all' to specific properties (background, color, border-color) for better performance - Removed redundant justify-content CSS property (margin-left: auto already handles spacing) - Refactored toggleGuidance() to use DOM traversal with nextElementSibling - Refactored togglePreview() to accept button element and use classList.toggle with boolean - Simplified logic using classList.toggle(class, boolean) instead of manual add/remove **Event Delegation Changes:** - Replaced 18+ onclick handlers with data-command attributes - Added master click handler on document.body for all buttons - Added event listener for search input - Added modal overlay click handler with proper event target checking - All functions now receive elements/parameters directly instead of reconstructing IDs **Security Impact:** Previously, a malicious template file named `');alert(1);('.json` could have executed arbitrary JavaScript. Now all user data is safely stored in data attributes and never executed. Addresses code review feedback. --------- Co-authored-by: Claude <[email protected]>
1 parent 4ac6728 commit 7c43690

File tree

3 files changed

+397
-55
lines changed

3 files changed

+397
-55
lines changed

src/constants.ts

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,81 @@ So that [benefit].
8484
* Built-in template metadata for display in picker
8585
*/
8686
export const BUILT_IN_TEMPLATE_INFO = [
87-
{ label: 'Problem/Solution', value: 'problem-solution', description: 'Document bugs and troubleshooting' },
88-
{ label: 'Meeting', value: 'meeting', description: 'Organize meeting notes and action items' },
89-
{ label: 'Research', value: 'research', description: 'Structure your research and findings' },
90-
{ label: 'User Story', value: 'user-story', description: 'Agile user stories with tasks, criteria, and estimates' },
91-
{ label: 'Quick', value: 'quick', description: 'Simple dated note' }
87+
{
88+
label: 'Problem/Solution',
89+
value: 'problem-solution',
90+
description: 'Document bugs and troubleshooting',
91+
when_to_use: 'When debugging issues, documenting solutions to problems, or troubleshooting technical challenges that you want to reference later.',
92+
use_cases: [
93+
'Debugging a production bug and documenting the fix',
94+
'Troubleshooting a development environment issue',
95+
'Recording solutions to recurring technical problems',
96+
'Documenting workarounds for known issues'
97+
],
98+
prerequisites: ['Basic understanding of the problem domain', 'Ability to describe technical issues clearly'],
99+
related_templates: ['research', 'user-story'],
100+
estimated_time: '5-10 minutes'
101+
},
102+
{
103+
label: 'Meeting',
104+
value: 'meeting',
105+
description: 'Organize meeting notes and action items',
106+
when_to_use: 'Perfect for team meetings, client calls, one-on-ones, or any discussion where you need to track attendees, agenda items, and action items.',
107+
use_cases: [
108+
'Daily standup or sprint planning meetings',
109+
'Client requirement gathering sessions',
110+
'Team retrospectives and brainstorming',
111+
'One-on-one meetings with managers or teammates'
112+
],
113+
prerequisites: ['Meeting agenda or topics to discuss'],
114+
related_templates: ['user-story', 'research'],
115+
estimated_time: '2-3 minutes setup, ongoing during meeting'
116+
},
117+
{
118+
label: 'Research',
119+
value: 'research',
120+
description: 'Structure your research and findings',
121+
when_to_use: 'Ideal for investigating new technologies, gathering information on topics, or conducting structured research with clear questions and findings.',
122+
use_cases: [
123+
'Evaluating new libraries or frameworks for a project',
124+
'Researching solutions to architectural decisions',
125+
'Learning about new programming concepts or patterns',
126+
'Gathering competitive analysis or market research'
127+
],
128+
prerequisites: ['Clear research topic or question', 'Basic research methodology understanding'],
129+
related_templates: ['problem-solution'],
130+
estimated_time: '5-15 minutes setup, extended for research'
131+
},
132+
{
133+
label: 'User Story',
134+
value: 'user-story',
135+
description: 'Agile user stories with tasks, criteria, and estimates',
136+
when_to_use: 'Use when planning features in agile/scrum workflows, breaking down requirements into user-focused stories with clear acceptance criteria.',
137+
use_cases: [
138+
'Sprint planning and backlog grooming',
139+
'Feature requirement documentation',
140+
'Breaking down epics into implementable stories',
141+
'Tracking development tasks with clear success criteria'
142+
],
143+
prerequisites: ['Understanding of agile user story format', 'Knowledge of the feature or requirement'],
144+
related_templates: ['meeting', 'problem-solution'],
145+
estimated_time: '10-15 minutes'
146+
},
147+
{
148+
label: 'Quick',
149+
value: 'quick',
150+
description: 'Simple dated note',
151+
when_to_use: 'For rapid note-taking when you need minimal structure, such as jotting down ideas, temporary notes, or quick reminders.',
152+
use_cases: [
153+
'Capturing quick thoughts or ideas',
154+
'Temporary notes during phone calls',
155+
'Daily journal or stream-of-consciousness writing',
156+
'Scratch pad for calculations or brainstorming'
157+
],
158+
prerequisites: [],
159+
related_templates: ['meeting', 'research'],
160+
estimated_time: 'Under 1 minute'
161+
}
92162
];
93163

94164
/**

src/templates/TemplateTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export interface Template {
5757
created?: string;
5858
modified?: string;
5959
usage_count?: number;
60+
61+
// Usage guidance (Phase 3)
62+
when_to_use?: string; // Brief 1-2 sentence description of ideal usage scenarios
63+
use_cases?: string[]; // Array of 2-4 specific scenarios
64+
prerequisites?: string[]; // Knowledge or setup requirements
65+
related_templates?: string[]; // Template IDs for discovery and cross-linking
66+
estimated_time?: string; // Time to complete (e.g., "2-3 minutes")
6067
}
6168

6269
/**

0 commit comments

Comments
 (0)