waveterm/frontend/app/view/preview
Copilot 705563ebe0
Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920)
`contextmenu.ts` eagerly instantiated its model at import time, which
triggered constructor side effects (`getApi()`) too early. This change
aligns ContextMenuModel with the `client-model.ts` singleton pattern so
initialization is explicit and deferred.

- **Singleton pattern migration (`frontend/app/store/contextmenu.ts`)**
- Replaced eager module-level instance creation with a class-based
singleton:
    - `private constructor()`
    - `static getInstance()`
- Removed `ContextMenuModelType` export and now export
`ContextMenuModel` class only.
- Constructor side effects (`onContextMenuClick` wiring) now run only on
first `getInstance()` call.

- **Usage updates (all context menu entry points)**
  - Updated all direct static-style calls:
    - `ContextMenuModel.showContextMenu(...)`
    - ⟶ `ContextMenuModel.getInstance().showContextMenu(...)`
- Applied across app/builder/preview/term/tab/widget context-menu
handlers to keep behavior consistent while deferring initialization.

- **Focused regression test**
  - Added `frontend/app/store/contextmenu.test.ts` to verify:
    - importing `contextmenu` does not initialize the API binding;
    - first `getInstance()` initializes once;
    - repeated `getInstance()` returns the same singleton instance.

```ts
// before
ContextMenuModel.showContextMenu(menu, e);

// after
ContextMenuModel.getInstance().showContextMenu(menu, e);
```

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2026-02-23 13:42:02 -08:00
..
csvview.scss Remove ellipsis mixin and delete mixins.scss (#2480) 2025-10-26 11:08:47 -07:00
csvview.tsx Big Paste Handler Cleanup (#2535) 2025-11-07 18:15:49 -08:00
directorypreview.scss Remove ellipsis mixin and delete mixins.scss (#2480) 2025-10-26 11:08:47 -07:00
entry-manager.tsx New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
preview-directory-utils.tsx Do not allow large/recursive file transfers (for now), remove s3 and wavefile fs implementations (#2808) 2026-01-28 14:28:31 -08:00
preview-directory.tsx Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920) 2026-02-23 13:42:02 -08:00
preview-edit.tsx upgrade monaco editor (remove monaco-editor/loader and monaco-editor/react) (#2743) 2026-01-05 16:34:36 -08:00
preview-error-overlay.tsx New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
preview-markdown.tsx Add manual refresh buttons to file preview (#2680) 2025-12-15 09:12:18 -08:00
preview-model.tsx Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920) 2026-02-23 13:42:02 -08:00
preview-streaming.tsx Do not allow large/recursive file transfers (for now), remove s3 and wavefile fs implementations (#2808) 2026-01-28 14:28:31 -08:00
preview.tsx Do not allow large/recursive file transfers (for now), remove s3 and wavefile fs implementations (#2808) 2026-01-28 14:28:31 -08:00