Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7963,7 +7963,7 @@
"rustPath": "reorder_opened_workspaces",
"sourceFile": "src/apps/desktop/src/api/commands.rs",
"signature": "fn reorder_opened_workspaces( state: State<'_, AppState>, request: ReorderOpenedWorkspacesRequest, ) -> Result<(), String>",
"remoteWorkspacePolicy": "LegacyUnaudited"
"remoteWorkspacePolicy": "WorkspaceAgnostic"
},
{
"id": "replace_mode_skill_selection",
Expand Down
24 changes: 24 additions & 0 deletions src/apps/cli/src/peer_host/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ pub(crate) fn optional_bool(obj: &Value, camel: &str) -> Option<bool> {
field(obj, camel, &snake).and_then(|v| v.as_bool())
}

pub(crate) fn get_string_vec(obj: &Value, camel: &str) -> Result<Vec<String>, String> {
let snake = camel_to_snake(camel);
let items = field(obj, camel, &snake)
.and_then(|v| v.as_array())
.ok_or_else(|| format!("Missing or invalid '{camel}' field"))?;
items
.iter()
.map(|item| {
item.as_str()
.map(str::to_string)
.ok_or_else(|| format!("Invalid string entry in '{camel}'"))
})
.collect()
}

fn camel_to_snake(camel: &str) -> String {
let mut out = String::with_capacity(camel.len() + 4);
for (i, ch) in camel.chars().enumerate() {
Expand Down Expand Up @@ -64,5 +79,14 @@ mod tests {
optional_string(&camel, "workspacePath").as_deref(),
Some("/a")
);
assert_eq!(
get_string_vec(&json!({ "workspaceIds": ["b", "a"] }), "workspaceIds").unwrap(),
vec!["b".to_string(), "a".to_string()]
);
assert_eq!(
get_string_vec(&json!({ "workspace_ids": ["b", "a"] }), "workspaceIds").unwrap(),
vec!["b".to_string(), "a".to_string()]
);
assert!(get_string_vec(&json!({ "workspaceIds": ["b", 1] }), "workspaceIds").is_err());
}
}
2 changes: 2 additions & 0 deletions src/apps/cli/src/peer_host/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub(crate) fn dispatch<'a>(
Box::pin(workspace::get_current_workspace(state))
}
"set_active_workspace" => Box::pin(workspace::set_active_workspace(state, args)),
"reorder_opened_workspaces" => Box::pin(workspace::reorder_opened_workspaces(state, args)),
"open_workspace" => Box::pin(workspace::open_workspace(state, args)),
"ssh_list_saved_connections" => Box::pin(workspace::ssh_list_saved_connections()),
"open_remote_workspace" => Box::pin(workspace::open_remote_workspace(state, args)),
Expand Down Expand Up @@ -407,6 +408,7 @@ pub(crate) const HANDLED_COMMANDS: &[&str] = &[
"reload_config",
"remove_project_permission_grant",
"rename_session",
"reorder_opened_workspaces",
"respond_permission",
"respond_permission_batch",
"restore_session",
Expand Down
17 changes: 16 additions & 1 deletion src/apps/cli/src/peer_host/commands/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use openbitfun_core::service::workspace::{
use openbitfun_runtime_ports::SessionStoragePathRequest;
use serde_json::{json, Value};

use crate::peer_host::args::{get_string, optional_bool, optional_string, request_value};
use crate::peer_host::args::{
get_string, get_string_vec, optional_bool, optional_string, request_value,
};
use crate::peer_host::state::PeerHostState;
use crate::peer_host::workspace_dto::{workspace_info_to_json, workspace_list_to_json};

Expand Down Expand Up @@ -70,6 +72,19 @@ pub(crate) async fn set_active_workspace(
Ok(workspace_info_to_json(&workspace))
}

pub(crate) async fn reorder_opened_workspaces(
state: &PeerHostState,
args: &Value,
) -> Result<Value, String> {
let workspace_ids = get_string_vec(request_value(args), "workspaceIds")?;
state
.workspace_service
.reorder_opened_workspaces(workspace_ids)
.await
.map_err(|error| format!("Failed to reorder opened workspaces: {error}"))?;
Ok(Value::Null)
}

pub(crate) async fn open_workspace(state: &PeerHostState, args: &Value) -> Result<Value, String> {
let request = request_value(args);
if let Some(id) = crate::peer_host::args::optional_string(request, "workspaceId") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"digest": "fnv1a64:ab13282fb7012e10",
"digest": "fnv1a64:f165ae35a7d7a54c",
"retiredCommandPrefixes": [
{
"prefix": "lsp_",
Expand Down Expand Up @@ -6224,13 +6224,12 @@
{
"id": "reorder_opened_workspaces",
"surface": "tauri_command",
"remoteWorkspace": "LegacyUnaudited",
"remoteWorkspace": "WorkspaceAgnostic",
"peer": {
"kind": "proxied"
},
"cliPeer": {
"kind": "unsupported",
"reason": "the CLI peer host has no handler for this command"
"kind": "handled"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub(super) const UNAUDITED_BASELINE: &[&str] = &[
"reload_config",
"reload_custom_agents",
"reload_subagents",
"reorder_opened_workspaces",
"replace_mode_skill_selection",
"report_ide_control_result",
"reset_agent_profile_config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[
op("remove_recent_workspace", Agnostic, Proxied, CLI_NOT_IMPLEMENTED),
op("rename_file", Routed, Proxied, HANDLED),
host_invoke_only("rename_session", Agnostic, Proxied, HANDLED),
op("reorder_opened_workspaces", Unaudited, Proxied, CLI_NOT_IMPLEMENTED),
op("reorder_opened_workspaces", Agnostic, Proxied, HANDLED),
op("replace_mode_skill_selection", Unaudited, Proxied, CLI_NOT_IMPLEMENTED),
op("report_ide_control_result", Unaudited, ControllerLocal, REFUSED),
op("report_miniapp_web_result", Agnostic, ControllerLocal, REFUSED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import MainNav from './MainNav';
import { useWorkspaceSessionViewStore } from './workspaceSessionView';
import { useMiniAppNavigationStore } from '@/app/scenes/miniapps/miniAppNavigationStore';
import { sidebarPreferences } from '@/app/navigation/sidebarPreferences';
import { requestWorkspaceReveal, resetWorkspaceDisplayOrdersForTest } from '@/infrastructure/services/business/workspaceDisplayOrder';

describe('project creation entry points', () => {
let root: Root;
Expand Down Expand Up @@ -181,6 +182,16 @@ describe('project creation entry points', () => {
expect(useWorkspaceSessionViewStore.getState().grouping).toBe(succeeded ? 'grouped' : 'all');
});

it('switches flat session view to grouped when an explicit open requests revealing a project on the active device', () => {
resetWorkspaceDisplayOrdersForTest();
useWorkspaceSessionViewStore.getState().setGrouping('all');
act(() => { requestWorkspaceReveal('peer-b', 'ws-other', true); });
expect(useWorkspaceSessionViewStore.getState().grouping).toBe('all');

act(() => { requestWorkspaceReveal('local', 'ws-local', true); });
expect(useWorkspaceSessionViewStore.getState().grouping).toBe('grouped');
});

it.each(['sidebar', 'global'] as const)('%s opens the full source picker and adds a WSL folder', async entry => {
if (entry === 'sidebar') {
await act(async () => document.querySelector<HTMLButtonElement>('[data-testid="nav-workspace-add-btn"]')!.click());
Expand Down
12 changes: 11 additions & 1 deletion src/web-ui/src/app/components/NavPanel/MainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ import { useSidebarNavigation } from '@/app/navigation/useSidebarNavigation';
import PinnedNavigationItems from './components/PinnedNavigationItems';
import { createProject, type ProjectDraft, type ProjectFolder } from '@/app/services/createProject';
import { useWorkspaceSessionViewStore } from './workspaceSessionView';
import { getActiveSurfaceScope } from '@/infrastructure/peer-device/deviceSurface';
import { getActiveSurfaceId, getActiveSurfaceScope } from '@/infrastructure/peer-device/deviceSurface';
import { subscribeWorkspaceReveal } from '@/infrastructure/services/business/workspaceDisplayOrder';
import { useNurseryStore } from '@/app/scenes/profile/nurseryStore';
import { RetainedMountBoundary } from '@/shared/presence';
import { lazyWithRecovery } from '@/shared/utils/lazyWithRecovery';
Expand Down Expand Up @@ -195,6 +196,15 @@ const MainNav: React.FC = () => {
return () => window.removeEventListener('nav:new-project', onNewProject);
}, []);

// Explicitly opening or re-adding a project workspace from any entry point
// switches out of the flat session list so the project header can be revealed.
useEffect(() => subscribeWorkspaceReveal(request => {
if (request.surfaceId !== getActiveSurfaceId()) return;
if (useWorkspaceSessionViewStore.getState().grouping === 'all') {
useWorkspaceSessionViewStore.getState().setGrouping('grouped');
}
}), []);

const peerDevice = usePeerDeviceModeOptional();
const signedIn = useDeviceDirectory(state => state.localId !== null);
const deviceSlots = useSidebarDevices(t('deviceOverview.thisDevice'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { beginDeviceOpen, endDeviceOpen } from '@/infrastructure/peer-device/dev
import DeviceWorkspaceSections from './DeviceWorkspaceSections';
import { useDeviceVisibilityPreferences } from '@/app/navigation/deviceVisibilityPreferences';
import { activateSurface } from '@/infrastructure/peer-device/deviceSurface';
import { requestWorkspaceReveal, resetWorkspaceDisplayOrdersForTest } from '@/infrastructure/services/business/workspaceDisplayOrder';
import { useDeviceSectionDisclosure } from './useSidebarDevices';

globalThis.IS_REACT_ACT_ENVIRONMENT = true;

Expand Down Expand Up @@ -152,4 +154,17 @@ describe('DeviceWorkspaceSections hand-over', () => {
act(() => useDeviceVisibilityPreferences.getState().setVisible('local', false));
expect(host.children).toHaveLength(0);
});

it('re-expands a collapsed current device section when a workspace open reveals a row on it', () => {
resetWorkspaceDisplayOrdersForTest();
useDeviceSectionDisclosure.setState({ expanded: {} });
slots.value = [slot('local', true), slot('peer-b', false)];
render();

act(() => host.querySelector<HTMLButtonElement>('[data-device-surface="local"] [data-testid="nav-device-section-toggle"]')!.click());
expect(body('local')).toBeUndefined();

act(() => { requestWorkspaceReveal('local', 'ws-1', true); });
expect(body('local')).toBe('live-list');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import WorkspaceListSection from '../workspaces/WorkspaceListSection';
import DeviceCatalogSection from './DeviceCatalogSection';
import { useDeviceOpenIntent } from '@/infrastructure/peer-device/deviceOpenIntent';
import { useWorkspaceContext } from '@/infrastructure/contexts/WorkspaceContext';
import { subscribeWorkspaceReveal } from '@/infrastructure/services/business/workspaceDisplayOrder';
import { workspaceManager } from '@/infrastructure/services/business/workspaceManager';
import { installBackgroundSurfaceSeeding } from '@/flow_chat/services/backgroundSurfaceSeeding';
import { useDeviceVisibilityPreferences } from '@/app/navigation/deviceVisibilityPreferences';
Expand Down Expand Up @@ -209,6 +210,12 @@ const DeviceWorkspaceSections: React.FC<DeviceWorkspaceSectionsProps> = ({ scrol
setExpanded(activeSurfaceId, true);
}
}, [activeSurfaceId, setExpanded]);
useEffect(() => subscribeWorkspaceReveal(request => {
if (request.surfaceId !== getActiveSurfaceId()) return;
if (useDeviceSectionDisclosure.getState().expanded[request.surfaceId] === false) {
setExpanded(request.surfaceId, true);
}
}), [setExpanded]);

const containerRef = useRef<HTMLDivElement>(null);
useSwitchLayoutHold(containerRef, scrollRootRef);
Expand Down
Loading
Loading