Dyn 9702 template files support#89
Conversation
- Enhance CustomDropdown component to support divider and header option types - Add template options to Sidebar "New" dropdown with visual grouping - Add template data structure in home.ts assets - Update dropdown styling for divider and header elements - Add TypeScript types for dropdown option kinds (item/divider/header) - Update package dependencies
- Add Templates section above Recent section on home page - Implement templates data loading from home.ts (dev) and backend (prod) - Add independent grid/list view toggle for Templates section - Add templatesPageViewMode setting for view preference persistence - Map template data structure (date -> DateModified) for component compatibility - Add receiveTemplatesDataFromDotNet window function for backend integration - Add "Templates" translation key to locale files - Reuse existing GraphGridItem and GraphTable components for templates display
…down - Add newWorkspaceWithTemplate utility function - Implement listener pattern for template data sharing between Sidebar and PageRecent - Map hardcoded dropdown options to real template files from backend - Update TypeScript types for listener pattern
- Add TemplatesContext to manage template state centrally - Update Sidebar and PageRecent to use useTemplates() hook - Remove duplicate global handlers to prevent race conditions - Aligns with existing React patterns
Update template matching logic to use new filenames: - Template 1: matches 'Create a Graph.dyn' (was Template_00_) - Template 2: matches 'Import & Export Workflow.dyn' (was Template_01_)
Drop down menu on side panel removed, will be added back later - Remove Template 1 and Template 2 options from Sidebar dropdown - Remove newWorkspaceWithTemplate function from utility.ts - Remove divider/header support from CustomDropdown component - Remove template data from home.ts assets - Update type definitions to remove template-related types
TemplatesContext requires templates export in development mode
Fix module path in TemplatesContext.tsx and restore package-lock.json metadata.
Display Recent files section above Templates section on the home page. Visual reordering only, there is no functional changes to either section
Add info icon with tooltip to the Templates section title that appears when hovering over the Template heading Changes: - Add tooltip component to Templates title in PageRecent.tsx - Add tooltip text to locale file (en.json) - Extend Tooltip component to support right-side positioning with arrow - Update tooltip styling for wider layout to fit space inbetween - Position tooltip to the right of the title with left-pointing arrow
- Add QuestionMarkIcon import to PageRecent component - Tooltip now appears when hover over the icon instead of the header - Text updated
| const TemplatesContext = createContext<any[]>([]); | ||
|
|
||
| // Provider component that wraps the app components | ||
| export const TemplatesProvider = ({ children }) => { |
There was a problem hiding this comment.
[Bug 5 — Untyped prop] children is untyped. Should be { children: React.ReactNode }.
There was a problem hiding this comment.
TemplatesProvider has now an explicit TemplatesProviderProps type with children: ReactNode
| }; | ||
|
|
||
| // Handles mouse click over each template row | ||
| const handleTemplateRowClick = (row: Row) => { |
There was a problem hiding this comment.
[Bug 1 — Duplicate handler] handleTemplateRowClick is byte-for-byte identical to handleRowClick. Delete this and pass handleRowClick directly to both GraphTable instances.
There was a problem hiding this comment.
I removed the duplicate handleTemplateRowClick and now template table rows reuse the existing handleRowClick
| // Map templates to match Graph structure for table view (templates use 'date' instead of 'DateModified') | ||
| const templatesForTable = templates.map(template => ({ | ||
| ...template, | ||
| DateModified: template.date || template.DateModified || '', |
There was a problem hiding this comment.
[Bug 2 — Split normalization] The date → DateModified mapping is done twice: here in templatesForTable, and again inline at line 225 for the grid view (DateModified={template.date || template.DateModified || ''}). This normalization should happen once in TemplatesContext so all consumers get a consistent shape. Consumers should not need to know whether the field is called date or DateModified.
There was a problem hiding this comment.
I moved the date to DateModified normalization into TemplatesContext, so consumers now receive a consistent template shape. PageRecent no longer maps templates for the table view or handles the inline date || DateModified fallback in the grid view.
| updateSettings({ templatesPageViewMode: templatesViewMode }); | ||
|
|
||
| // Send settings to Dynamo to save | ||
| saveHomePageSettings({ ...settings, templatesPageViewMode: templatesViewMode }); |
There was a problem hiding this comment.
[Bug 3 — Stale closure] saveHomePageSettings closes over settings, but settings is excluded from deps via the eslint-disable below. If settings changes independently (e.g. a sidebar width update), this call sends stale data. Either add settings to the deps array, or thread only the changed key into the save call rather than spreading the whole settings object.
There was a problem hiding this comment.
Both view-mode save effects now create a merged settings object and pass the same payload to updateSettings and saveHomePageSettings
| Thumbnail: img | ||
| } | ||
| ]; | ||
|
|
There was a problem hiding this comment.
[Minor 9 — Missing newline at EOF] File ends without a trailing newline. Add one.
| left: 50%; | ||
| max-width: 300px; | ||
| transform: translateX(-50%); | ||
| max-width: 500px; /* Increased width to make it wider */ |
There was a problem hiding this comment.
[Minor 10 — Global tooltip width change] max-width changed from 300px → 500px for all .tooltip-box elements. This silently widens every tooltip in the app, not just the templates one. If the wider width is only needed for the templates tooltip, scope it with a modifier class (e.g. .tooltip-box.wide) rather than changing the global default.
There was a problem hiding this comment.
I changed back the default tooltip width to 300px and added a scoped template-info-tooltip class so only the Templates info tooltip uses the wider 500px width
| // "rootDirs": ["./src"], /* Allow multiple folders to be treated as one when resolving modules. */ | ||
| "typeRoots": ["./types", "./node_modules/@types"], /* Specify multiple folders that act like './node_modules/@types'. */ | ||
| "types": ["react", "node", "jest"], /* Specify type package names to be included without being referenced in a source file. */ | ||
| // "typeRoots": ["./types", "./node_modules/@types"], /* Specify multiple folders that act like './node_modules/@types'. */ |
There was a problem hiding this comment.
[Minor 11 — typeRoots commented out] The custom ./types directory is no longer listed as a typeRoot. Verify that the global declarations in types/index.d.ts (including the newly added receiveTemplatesDataFromDotNet) are still resolved by running tsc --noEmit before merge.
|
@Chloepeg - added some comments from Claude, please let me know if any are too out there |
|
Claude comments: [ |
jasonstratton
left a comment
There was a problem hiding this comment.
I think John caught most of it.
I wanted to point out that clicking a template just opens the template file directly, but the Jira issue specified "new from template".
The other is that there are no additional tests for the additions to PageRecent.tsx or the new file TemplatesContext.tsx
| updateSettings({ templatesPageViewMode: templatesViewMode }); | ||
|
|
||
| // Send settings to Dynamo to save | ||
| saveHomePageSettings({ ...settings, templatesPageViewMode: templatesViewMode }); |
| import { createContext, useContext, useState, useEffect } from 'react'; | ||
|
|
||
| // Create the context | ||
| const TemplatesContext = createContext<any[]>([]); |
There was a problem hiding this comment.
TemplatesContext is untyped as well.
There was a problem hiding this comment.
TemplatesContext now uses explicit TemplateInput and Template types instead of any[]
| setIsDisabled(true); | ||
|
|
||
| const contextData = row.original.ContextData; | ||
| openFile(contextData); |
There was a problem hiding this comment.
I may be confused here, bhen clicking on the template, it should be creating a copy of the template and opening it (or something like that)? And not opening the template file directly?
There was a problem hiding this comment.
DynamoHome only passes the selected row path to the host via openFile. The paired Dynamo branch (DynamoDS/Dynamo#17107) detects when that path belongs to TemplateFiles and opens it as a template/new editable workspace.
PageRecent cleanup: Removed duplicate handleTemplateRowClick. Removed inline template normalization. Uses new TemplatesSection. Both view-mode save effects now use one merged settings payload. New Templates component: Added src/components/Recent/TemplatesSection.tsx. Added empty co-located TemplatesSection.module.css for repo convention. TemplatesContext: Replaced any[] with TemplateInput / Template types. Typed children. Normalizes template data once in the context. Tooltip/CSS: Added optional tooltipClassName. Restored global tooltip width to 300px. Scoped Templates tooltip width to 500px. Removed unused arrow-right tooltip CSS. Localization: Added title.text.templates and recent.templates.tooltip across all locale files. Renamed old tooltip.text.templates usage to recent.templates.tooltip. Types: Updated Graph shape to use DateModified. Added optional Author / Description. Added tooltipClassName to Tooltip.
Purpose
This PR addresses DYN-9702 https://jira.autodesk.com/browse/DYN-9702 The changes in the code aim to add Templates support to the Dynamo Home UI, allowing users to view and open template files directly from the Home page.
This PR works with : DynamoDS/Dynamo#17107
Changes :
Declarations
Check these if you believe they are true
Release Notes
Added template file support to Dynamo Home. The Home page now shows a Templates section with grid and list views. Added a Templates info tooltip
Reviewers
@zeusongit
@DynamoDS/eidos
FYIs
@dnenov
@johnpierson
@jnealb