MCPcopy
hub / github.com/wavetermdev/waveterm / WorkspaceSwitcherItem

Function WorkspaceSwitcherItem

frontend/app/tab/workspaceswitcher.tsx:157–262  ·  view source on GitHub ↗
({
    entryAtom,
    onDeleteWorkspace,
}: {
    entryAtom: PrimitiveAtom<WorkspaceListEntry>;
    onDeleteWorkspace: (workspaceId: string) => void;
})

Source from the content-addressed store, hash-verified

155});
156
157const WorkspaceSwitcherItem = ({
158 entryAtom,
159 onDeleteWorkspace,
160}: {
161 entryAtom: PrimitiveAtom<WorkspaceListEntry>;
162 onDeleteWorkspace: (workspaceId: string) => void;
163}) => {
164 const env = useWaveEnv<WorkspaceSwitcherEnv>();
165 const activeWorkspace = useAtomValueSafe(env.atoms.workspace);
166 const [workspaceEntry, setWorkspaceEntry] = useAtom(entryAtom);
167 const [editingWorkspace, setEditingWorkspace] = useAtom(editingWorkspaceAtom);
168
169 const workspace = workspaceEntry.workspace;
170 const isCurrentWorkspace = activeWorkspace.oid === workspace.oid;
171
172 const setWorkspace = useCallback((newWorkspace: Workspace) => {
173 setWorkspaceEntry({ ...workspaceEntry, workspace: newWorkspace });
174 if (newWorkspace.name != "") {
175 fireAndForget(() =>
176 env.services.workspace.UpdateWorkspace(
177 workspace.oid,
178 newWorkspace.name,
179 newWorkspace.icon,
180 newWorkspace.color,
181 false
182 )
183 );
184 }
185 }, []);
186
187 const isActive = !!workspaceEntry.windowId;
188 const editIconDecl: IconButtonDecl = {
189 elemtype: "iconbutton",
190 className: "edit",
191 icon: "pencil",
192 title: "Edit workspace",
193 click: (e) => {
194 e.stopPropagation();
195 if (editingWorkspace === workspace.oid) {
196 setEditingWorkspace(null);
197 } else {
198 setEditingWorkspace(workspace.oid);
199 }
200 },
201 };
202 const windowIconDecl: IconButtonDecl = {
203 elemtype: "iconbutton",
204 className: "window",
205 noAction: true,
206 icon: isCurrentWorkspace ? "check" : "window",
207 title: isCurrentWorkspace ? "This is your current workspace" : "This workspace is open",
208 };
209
210 const isEditing = editingWorkspace === workspace.oid;
211
212 return (
213 <ExpandableMenuItemGroup
214 key={workspace.oid}

Callers

nothing calls this directly

Calls 6

useWaveEnvFunction · 0.90
useAtomValueSafeFunction · 0.90
fireAndForgetFunction · 0.90
makeIconClassFunction · 0.90
switchWorkspaceMethod · 0.80
UpdateWorkspaceMethod · 0.45

Tested by

no test coverage detected