Auto-fill Contribute form from active graph metadata#392
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the UX of the Contribute modal by auto-populating the form’s Study Name, Study Path, and Author Name from the currently active graph/editor state, reducing repetitive manual entry.
Changes:
- Initialize
study,path, andauthstate from the active graph metadata / uploaded directory name. - Add an effect that re-applies these defaults when the Contribute modal is opened.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| useEffect(() => { | ||
| if (superState.contributeModal) { | ||
| const activeGraph = superState.graphs[superState.curGraphIndex] ?? {}; | ||
| setStudy(activeGraph.projectName ?? ''); | ||
| setPath(superState.uploadedDirName ?? ''); | ||
| setAuth(activeGraph.authorName ?? ''); | ||
| } | ||
| }, [superState.contributeModal]); |
There was a problem hiding this comment.
useEffect reads superState.graphs, superState.curGraphIndex, and superState.uploadedDirName but only lists superState.contributeModal in the dependency array. This can lead to stale values being captured (and will typically trigger react-hooks/exhaustive-deps warnings under the current ESLint setup). Consider including the referenced values in the dependency list and gating the setters so they only run on the closed→open transition (e.g., via a useRef tracking previous open state) to avoid overwriting user edits while the modal remains open.
| const activeGraph = superState.graphs[superState.curGraphIndex] ?? {}; | ||
| setStudy(activeGraph.projectName ?? ''); | ||
| setPath(superState.uploadedDirName ?? ''); | ||
| setAuth(activeGraph.authorName ?? ''); |
There was a problem hiding this comment.
On modal open you reset study/path/auth, but other form state (title, desc, branch, and possibly showAdvanceOptions) is not reset anywhere. Since this modal component is mounted persistently, those values will carry over between opens, which is inconsistent with the new “auto-fill defaults on open” behavior. Consider resetting the remaining fields when the modal opens (or when closing) to avoid stale values being shown on subsequent contributions.
| setAuth(activeGraph.authorName ?? ''); | |
| setAuth(activeGraph.authorName ?? ''); | |
| setTitle(''); | |
| setDesc(''); | |
| setBranch(''); | |
| setShowAdvanceOptions(false); |
|
Hi @pradeeban , please have a look! |
The Contribute form previously required users to manually type their Study Name, Study Path, and Author Name every time even though the editor already stores all three values in state.
So, this is just a small improvement to store them in the contribute form by default (can be changed later when actually contributing).