Skip to content

Commit a64fcc7

Browse files
authored
Merge pull request #3943 from bobleer/bob/workspace-promotion-polish
fix(web-ui): polish promoted workspace reveal, persistence, and CLI peer reorder
2 parents b2d33ee + 7c50463 commit a64fcc7

18 files changed

Lines changed: 757 additions & 207 deletions

File tree

‎docs/interactive-capabilities/technical/tauri-command-map.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7963,7 +7963,7 @@
79637963
"rustPath": "reorder_opened_workspaces",
79647964
"sourceFile": "src/apps/desktop/src/api/commands.rs",
79657965
"signature": "fn reorder_opened_workspaces( state: State<'_, AppState>, request: ReorderOpenedWorkspacesRequest, ) -> Result<(), String>",
7966-
"remoteWorkspacePolicy": "LegacyUnaudited"
7966+
"remoteWorkspacePolicy": "WorkspaceAgnostic"
79677967
},
79687968
{
79697969
"id": "replace_mode_skill_selection",

‎src/apps/cli/src/peer_host/args.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ pub(crate) fn optional_bool(obj: &Value, camel: &str) -> Option<bool> {
3434
field(obj, camel, &snake).and_then(|v| v.as_bool())
3535
}
3636

37+
pub(crate) fn get_string_vec(obj: &Value, camel: &str) -> Result<Vec<String>, String> {
38+
let snake = camel_to_snake(camel);
39+
let items = field(obj, camel, &snake)
40+
.and_then(|v| v.as_array())
41+
.ok_or_else(|| format!("Missing or invalid '{camel}' field"))?;
42+
items
43+
.iter()
44+
.map(|item| {
45+
item.as_str()
46+
.map(str::to_string)
47+
.ok_or_else(|| format!("Invalid string entry in '{camel}'"))
48+
})
49+
.collect()
50+
}
51+
3752
fn camel_to_snake(camel: &str) -> String {
3853
let mut out = String::with_capacity(camel.len() + 4);
3954
for (i, ch) in camel.chars().enumerate() {
@@ -64,5 +79,14 @@ mod tests {
6479
optional_string(&camel, "workspacePath").as_deref(),
6580
Some("/a")
6681
);
82+
assert_eq!(
83+
get_string_vec(&json!({ "workspaceIds": ["b", "a"] }), "workspaceIds").unwrap(),
84+
vec!["b".to_string(), "a".to_string()]
85+
);
86+
assert_eq!(
87+
get_string_vec(&json!({ "workspace_ids": ["b", "a"] }), "workspaceIds").unwrap(),
88+
vec!["b".to_string(), "a".to_string()]
89+
);
90+
assert!(get_string_vec(&json!({ "workspaceIds": ["b", 1] }), "workspaceIds").is_err());
6791
}
6892
}

‎src/apps/cli/src/peer_host/commands/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub(crate) fn dispatch<'a>(
6363
Box::pin(workspace::get_current_workspace(state))
6464
}
6565
"set_active_workspace" => Box::pin(workspace::set_active_workspace(state, args)),
66+
"reorder_opened_workspaces" => Box::pin(workspace::reorder_opened_workspaces(state, args)),
6667
"open_workspace" => Box::pin(workspace::open_workspace(state, args)),
6768
"ssh_list_saved_connections" => Box::pin(workspace::ssh_list_saved_connections()),
6869
"open_remote_workspace" => Box::pin(workspace::open_remote_workspace(state, args)),
@@ -407,6 +408,7 @@ pub(crate) const HANDLED_COMMANDS: &[&str] = &[
407408
"reload_config",
408409
"remove_project_permission_grant",
409410
"rename_session",
411+
"reorder_opened_workspaces",
410412
"respond_permission",
411413
"respond_permission_batch",
412414
"restore_session",

‎src/apps/cli/src/peer_host/commands/workspace.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use openbitfun_core::service::workspace::{
88
use openbitfun_runtime_ports::SessionStoragePathRequest;
99
use serde_json::{json, Value};
1010

11-
use crate::peer_host::args::{get_string, optional_bool, optional_string, request_value};
11+
use crate::peer_host::args::{
12+
get_string, get_string_vec, optional_bool, optional_string, request_value,
13+
};
1214
use crate::peer_host::state::PeerHostState;
1315
use crate::peer_host::workspace_dto::{workspace_info_to_json, workspace_list_to_json};
1416

@@ -70,6 +72,19 @@ pub(crate) async fn set_active_workspace(
7072
Ok(workspace_info_to_json(&workspace))
7173
}
7274

75+
pub(crate) async fn reorder_opened_workspaces(
76+
state: &PeerHostState,
77+
args: &Value,
78+
) -> Result<Value, String> {
79+
let workspace_ids = get_string_vec(request_value(args), "workspaceIds")?;
80+
state
81+
.workspace_service
82+
.reorder_opened_workspaces(workspace_ids)
83+
.await
84+
.map_err(|error| format!("Failed to reorder opened workspaces: {error}"))?;
85+
Ok(Value::Null)
86+
}
87+
7388
pub(crate) async fn open_workspace(state: &PeerHostState, args: &Value) -> Result<Value, String> {
7489
let request = request_value(args);
7590
if let Some(id) = crate::peer_host::args::optional_string(request, "workspaceId") {

‎src/crates/contracts/product-domains/src/generated/remote-surface-registry.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schemaVersion": 1,
3-
"digest": "fnv1a64:ab13282fb7012e10",
3+
"digest": "fnv1a64:f165ae35a7d7a54c",
44
"retiredCommandPrefixes": [
55
{
66
"prefix": "lsp_",
@@ -6224,13 +6224,12 @@
62246224
{
62256225
"id": "reorder_opened_workspaces",
62266226
"surface": "tauri_command",
6227-
"remoteWorkspace": "LegacyUnaudited",
6227+
"remoteWorkspace": "WorkspaceAgnostic",
62286228
"peer": {
62296229
"kind": "proxied"
62306230
},
62316231
"cliPeer": {
6232-
"kind": "unsupported",
6233-
"reason": "the CLI peer host has no handler for this command"
6232+
"kind": "handled"
62346233
}
62356234
},
62366235
{

‎src/crates/contracts/product-domains/src/remote_surface/baseline.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ pub(super) const UNAUDITED_BASELINE: &[&str] = &[
172172
"reload_config",
173173
"reload_custom_agents",
174174
"reload_subagents",
175-
"reorder_opened_workspaces",
176175
"replace_mode_skill_selection",
177176
"report_ide_control_result",
178177
"reset_agent_profile_config",

‎src/crates/contracts/product-domains/src/remote_surface/table.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[
611611
op("remove_recent_workspace", Agnostic, Proxied, CLI_NOT_IMPLEMENTED),
612612
op("rename_file", Routed, Proxied, HANDLED),
613613
host_invoke_only("rename_session", Agnostic, Proxied, HANDLED),
614-
op("reorder_opened_workspaces", Unaudited, Proxied, CLI_NOT_IMPLEMENTED),
614+
op("reorder_opened_workspaces", Agnostic, Proxied, HANDLED),
615615
op("replace_mode_skill_selection", Unaudited, Proxied, CLI_NOT_IMPLEMENTED),
616616
op("report_ide_control_result", Unaudited, ControllerLocal, REFUSED),
617617
op("report_miniapp_web_result", Agnostic, ControllerLocal, REFUSED),

‎src/web-ui/src/app/components/NavPanel/MainNav.projectCreation.test.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import MainNav from './MainNav';
8484
import { useWorkspaceSessionViewStore } from './workspaceSessionView';
8585
import { useMiniAppNavigationStore } from '@/app/scenes/miniapps/miniAppNavigationStore';
8686
import { sidebarPreferences } from '@/app/navigation/sidebarPreferences';
87+
import { requestWorkspaceReveal, resetWorkspaceDisplayOrdersForTest } from '@/infrastructure/services/business/workspaceDisplayOrder';
8788

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

185+
it('switches flat session view to grouped when an explicit open requests revealing a project on the active device', () => {
186+
resetWorkspaceDisplayOrdersForTest();
187+
useWorkspaceSessionViewStore.getState().setGrouping('all');
188+
act(() => { requestWorkspaceReveal('peer-b', 'ws-other', true); });
189+
expect(useWorkspaceSessionViewStore.getState().grouping).toBe('all');
190+
191+
act(() => { requestWorkspaceReveal('local', 'ws-local', true); });
192+
expect(useWorkspaceSessionViewStore.getState().grouping).toBe('grouped');
193+
});
194+
184195
it.each(['sidebar', 'global'] as const)('%s opens the full source picker and adds a WSL folder', async entry => {
185196
if (entry === 'sidebar') {
186197
await act(async () => document.querySelector<HTMLButtonElement>('[data-testid="nav-workspace-add-btn"]')!.click());

‎src/web-ui/src/app/components/NavPanel/MainNav.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import { useSidebarNavigation } from '@/app/navigation/useSidebarNavigation';
5151
import PinnedNavigationItems from './components/PinnedNavigationItems';
5252
import { createProject, type ProjectDraft, type ProjectFolder } from '@/app/services/createProject';
5353
import { useWorkspaceSessionViewStore } from './workspaceSessionView';
54-
import { getActiveSurfaceScope } from '@/infrastructure/peer-device/deviceSurface';
54+
import { getActiveSurfaceId, getActiveSurfaceScope } from '@/infrastructure/peer-device/deviceSurface';
55+
import { subscribeWorkspaceReveal } from '@/infrastructure/services/business/workspaceDisplayOrder';
5556
import { useNurseryStore } from '@/app/scenes/profile/nurseryStore';
5657
import { RetainedMountBoundary } from '@/shared/presence';
5758
import { lazyWithRecovery } from '@/shared/utils/lazyWithRecovery';
@@ -195,6 +196,15 @@ const MainNav: React.FC = () => {
195196
return () => window.removeEventListener('nav:new-project', onNewProject);
196197
}, []);
197198

199+
// Explicitly opening or re-adding a project workspace from any entry point
200+
// switches out of the flat session list so the project header can be revealed.
201+
useEffect(() => subscribeWorkspaceReveal(request => {
202+
if (request.surfaceId !== getActiveSurfaceId()) return;
203+
if (useWorkspaceSessionViewStore.getState().grouping === 'all') {
204+
useWorkspaceSessionViewStore.getState().setGrouping('grouped');
205+
}
206+
}), []);
207+
198208
const peerDevice = usePeerDeviceModeOptional();
199209
const signedIn = useDeviceDirectory(state => state.localId !== null);
200210
const deviceSlots = useSidebarDevices(t('deviceOverview.thisDevice'));

‎src/web-ui/src/app/components/NavPanel/sections/devices/DeviceWorkspaceSections.test.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { beginDeviceOpen, endDeviceOpen } from '@/infrastructure/peer-device/dev
2828
import DeviceWorkspaceSections from './DeviceWorkspaceSections';
2929
import { useDeviceVisibilityPreferences } from '@/app/navigation/deviceVisibilityPreferences';
3030
import { activateSurface } from '@/infrastructure/peer-device/deviceSurface';
31+
import { requestWorkspaceReveal, resetWorkspaceDisplayOrdersForTest } from '@/infrastructure/services/business/workspaceDisplayOrder';
32+
import { useDeviceSectionDisclosure } from './useSidebarDevices';
3133

3234
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
3335

@@ -152,4 +154,17 @@ describe('DeviceWorkspaceSections hand-over', () => {
152154
act(() => useDeviceVisibilityPreferences.getState().setVisible('local', false));
153155
expect(host.children).toHaveLength(0);
154156
});
157+
158+
it('re-expands a collapsed current device section when a workspace open reveals a row on it', () => {
159+
resetWorkspaceDisplayOrdersForTest();
160+
useDeviceSectionDisclosure.setState({ expanded: {} });
161+
slots.value = [slot('local', true), slot('peer-b', false)];
162+
render();
163+
164+
act(() => host.querySelector<HTMLButtonElement>('[data-device-surface="local"] [data-testid="nav-device-section-toggle"]')!.click());
165+
expect(body('local')).toBeUndefined();
166+
167+
act(() => { requestWorkspaceReveal('local', 'ws-1', true); });
168+
expect(body('local')).toBe('live-list');
169+
});
155170
});

0 commit comments

Comments
 (0)