Skip to content

Commit 8b6260e

Browse files
author
Jimmy
committed
Keep Compute discoverable in Personal space with community prompt
Signed-off-by: Jimmy <1fe240cd1a8cf775f6f3060f115e5a303181f3abf28ad4cb0c2515f4a02b36a8@meshllm.communities.buzz.xyz>
1 parent 2e93d79 commit 8b6260e

8 files changed

Lines changed: 208 additions & 122 deletions

File tree

‎src/app/Settings.test.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ it("keeps grouped cards available without a selected community", () => {
100100
const { cards } = registry([
101101
card("hosted", "Hosted communities", "Communities"),
102102
card("groups", "Personal groups"),
103+
{ ...card("compute", "Compute"), showInPersonalSpace: true },
103104
]);
104105
const noCommunityState = { ...communityState, selected: null };
105106
render(
@@ -125,6 +126,8 @@ it("keeps grouped cards available without a selected community", () => {
125126
screen.getByRole("button", { name: "Hosted communities" }),
126127
).toBeVisible();
127128
expect(screen.queryByRole("button", { name: "Personal groups" })).toBeNull();
129+
fireEvent.click(screen.getByRole("button", { name: "Compute" }));
130+
expect(screen.getByText("Compute body")).toBeVisible();
128131
});
129132

130133
it("shows administration only within a selected community", () => {

‎src/app/Settings.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ export function Settings({
109109
() => contributed.filter((card) => !card.group && !card.section),
110110
[contributed],
111111
);
112+
const personalCards = useMemo(
113+
() =>
114+
communityCards
115+
.filter((card) => card.showInPersonalSpace)
116+
.map((card) => ({
117+
id: card.key,
118+
label: card.title,
119+
icon: card.icon ?? ChatCircleIcon,
120+
})),
121+
[communityCards],
122+
);
112123
const administrationCards = useMemo(
113124
() => contributed.filter((card) => card.section === "administration"),
114125
[contributed],
@@ -147,7 +158,7 @@ export function Settings({
147158
icon: card.icon ?? UsersIcon,
148159
}))
149160
: []),
150-
...(!selectedCommunity ? personalProfile : []),
161+
...(!selectedCommunity ? [...personalProfile, ...personalCards] : []),
151162
...contributedGroups.flatMap((group) =>
152163
group.cards.map((card) => ({
153164
id: card.key,
@@ -161,6 +172,7 @@ export function Settings({
161172
: []),
162173
],
163174
[
175+
personalCards,
164176
administrationCards,
165177
communitySections,
166178
contributedGroups,
@@ -267,7 +279,9 @@ export function Settings({
267279
))}
268280
<NavigationSection label="App">
269281
{[
270-
...(!selectedCommunity ? personalProfile : []),
282+
...(!selectedCommunity
283+
? [...personalProfile, ...personalCards]
284+
: []),
271285
...appSettingsSections,
272286
].map(({ id, label, icon: Icon }) => (
273287
<NavigationItem

‎src/app/SettingsSidebar.test.tsx‎

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -100,65 +100,75 @@ it.each([null, "primary"])(
100100
},
101101
);
102102

103-
it("uses a contributed icon and preserves the chat fallback", () => {
104-
const client = {
105-
selected: "primary",
106-
memberships: [{ id: "primary", name: "Primary" }],
107-
};
108-
const connection = { scope: "icon-test" };
109-
const entries = [
110-
{
111-
id: "compute",
112-
key: "mesh/compute",
113-
pluginId: "mesh",
114-
revision: "one",
115-
title: "Compute",
116-
component: () => null,
117-
icon: CpuIcon,
118-
},
119-
{
120-
id: "other",
121-
key: "other/card",
122-
pluginId: "other",
123-
revision: "one",
124-
title: "Other",
125-
component: () => null,
126-
},
127-
];
128-
render(
129-
<SettingsSidebar
130-
communities={
131-
{
132-
snapshot: () => client,
133-
subscribe: () => () => {},
134-
relay: { snapshot: () => connection, subscribe: () => () => {} },
135-
} as unknown as Communities
136-
}
137-
cards={
138-
{
139-
snapshot: () => entries,
140-
subscribe: () => () => {},
141-
} as unknown as SettingsCards
142-
}
143-
onBack={() => {}}
144-
onSection={() => {}}
145-
/>,
146-
);
147-
const reference = render(
148-
<>
149-
<CpuIcon data-testid="cpu-reference" />
150-
<ChatCircleIcon data-testid="chat-reference" />
151-
</>,
152-
);
153-
expect(
154-
screen.getByRole("button", { name: "Compute" }).querySelector("svg")
155-
?.innerHTML,
156-
).toBe(reference.getByTestId("cpu-reference").innerHTML);
157-
expect(
158-
screen.getByRole("button", { name: "Other" }).querySelector("svg")
159-
?.innerHTML,
160-
).toBe(reference.getByTestId("chat-reference").innerHTML);
161-
expect(
162-
screen.getByRole("button", { name: "Compute" }).closest("section"),
163-
).toHaveTextContent("Primary");
164-
});
103+
it.each(["primary", null])(
104+
"uses contributed icons and personal opt-in with selection %s",
105+
(selected) => {
106+
const client = {
107+
selected,
108+
memberships: [{ id: "primary", name: "Primary" }],
109+
};
110+
const connection = { scope: "icon-test" };
111+
const entries = [
112+
{
113+
id: "compute",
114+
key: "mesh/compute",
115+
pluginId: "mesh",
116+
revision: "one",
117+
title: "Compute",
118+
component: () => null,
119+
icon: CpuIcon,
120+
showInPersonalSpace: true,
121+
},
122+
{
123+
id: "other",
124+
key: "other/card",
125+
pluginId: "other",
126+
revision: "one",
127+
title: "Other",
128+
component: () => null,
129+
},
130+
];
131+
render(
132+
<SettingsSidebar
133+
communities={
134+
{
135+
snapshot: () => client,
136+
subscribe: () => () => {},
137+
relay: { snapshot: () => connection, subscribe: () => () => {} },
138+
} as unknown as Communities
139+
}
140+
cards={
141+
{
142+
snapshot: () => entries,
143+
subscribe: () => () => {},
144+
} as unknown as SettingsCards
145+
}
146+
onBack={() => {}}
147+
onSection={() => {}}
148+
/>,
149+
);
150+
const reference = render(
151+
<>
152+
<CpuIcon data-testid="cpu-reference" />
153+
<ChatCircleIcon data-testid="chat-reference" />
154+
</>,
155+
);
156+
expect(
157+
screen.getByRole("button", { name: "Compute" }).querySelector("svg")
158+
?.innerHTML,
159+
).toBe(reference.getByTestId("cpu-reference").innerHTML);
160+
if (selected) {
161+
expect(
162+
screen.getByRole("button", { name: "Other" }).querySelector("svg")
163+
?.innerHTML,
164+
).toBe(reference.getByTestId("chat-reference").innerHTML);
165+
} else {
166+
expect(
167+
screen.queryByRole("button", { name: "Other" }),
168+
).not.toBeInTheDocument();
169+
}
170+
expect(
171+
screen.getByRole("button", { name: "Compute" }).closest("section"),
172+
).toHaveTextContent(selected ? "Primary" : "App");
173+
},
174+
);

‎src/app/SettingsSidebar.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ export function SettingsSidebar({
129129
<SettingsGroup label="App">
130130
{!selectedCommunity &&
131131
section({ id: "profile", label: "Profile", icon: UserIcon })}
132+
{!selectedCommunity &&
133+
contributed
134+
.filter(
135+
(card) =>
136+
!card.group && !card.section && card.showInPersonalSpace,
137+
)
138+
.map((card) =>
139+
section({
140+
id: card.key,
141+
label: card.title,
142+
icon: card.icon ?? ChatCircleIcon,
143+
}),
144+
)}
132145
{appSettingsSections.map(section)}
133146
</SettingsGroup>
134147
{developerMode && (

‎src/bundled/mesh-compute/index.test.tsx‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,26 @@ it("revokes a pending selection on disposal and never starts it", async () => {
3333
scope: "https://fixture.example:viewer",
3434
};
3535
let dispose!: () => void;
36-
let Component!: React.ComponentType;
36+
let Component!: React.ComponentType<{
37+
community?: { id: string; name: string };
38+
}>;
3739
const ctx = {
3840
relay: { snapshot: () => snapshot, subscribe: () => () => {} },
3941
effect: (setup: () => () => void) => {
4042
dispose = setup();
4143
},
4244
settingsCards: {
43-
register: (card: { component: React.ComponentType }) => {
45+
register: (card: {
46+
component: React.ComponentType<{
47+
community?: { id: string; name: string };
48+
}>;
49+
}) => {
4450
Component = card.component;
4551
},
4652
},
4753
} as unknown as Parameters<PluginModule["apply"]>[0];
4854
apply(ctx);
49-
render(<Component />);
55+
render(<Component community={{ id: "primary", name: "Primary" }} />);
5056
await waitFor(() =>
5157
expect(native.invoke).toHaveBeenCalledWith("mesh_compute_select", {
5258
community: "https://fixture.example",
@@ -95,7 +101,9 @@ it("preserves the running lease through reconnect and revokes on identity change
95101
};
96102
const listeners = new Set<() => void>();
97103
let dispose!: () => void;
98-
let Component!: React.ComponentType;
104+
let Component!: React.ComponentType<{
105+
community?: { id: string; name: string };
106+
}>;
99107
const ctx = {
100108
relay: {
101109
snapshot: () => snapshot,
@@ -108,13 +116,17 @@ it("preserves the running lease through reconnect and revokes on identity change
108116
dispose = setup();
109117
},
110118
settingsCards: {
111-
register: (card: { component: React.ComponentType }) => {
119+
register: (card: {
120+
component: React.ComponentType<{
121+
community?: { id: string; name: string };
122+
}>;
123+
}) => {
112124
Component = card.component;
113125
},
114126
},
115127
} as unknown as Parameters<PluginModule["apply"]>[0];
116128
apply(ctx);
117-
render(<Component />);
129+
render(<Component community={{ id: "primary", name: "Primary" }} />);
118130
await waitFor(() =>
119131
expect(
120132
screen.getByRole("button", { name: "Connect to community compute" }),
@@ -196,20 +208,26 @@ it("renders Running without claiming connectivity, stops by lease, and separates
196208
viewer: "viewer",
197209
scope: "https://fixture.example:viewer",
198210
};
199-
let Component!: React.ComponentType;
211+
let Component!: React.ComponentType<{
212+
community?: { id: string; name: string };
213+
}>;
200214
let dispose!: () => void;
201215
apply({
202216
relay: { snapshot: () => snapshot, subscribe: () => () => {} },
203217
effect: (setup: () => () => void) => {
204218
dispose = setup();
205219
},
206220
settingsCards: {
207-
register: (card: { component: React.ComponentType }) => {
221+
register: (card: {
222+
component: React.ComponentType<{
223+
community?: { id: string; name: string };
224+
}>;
225+
}) => {
208226
Component = card.component;
209227
},
210228
},
211229
} as unknown as Parameters<PluginModule["apply"]>[0]);
212-
render(<Component />);
230+
render(<Component community={{ id: "primary", name: "Primary" }} />);
213231
await screen.findByText("Running");
214232
expect(screen.queryByText("Connected")).not.toBeInTheDocument();
215233
expect(screen.getByRole("button", { name: "Disconnect" })).toBeEnabled();
@@ -242,22 +260,28 @@ it("polls transient states serially, stops at Running, and cancels on unmount",
242260
viewer: "viewer",
243261
scope: "https://fixture.example:viewer",
244262
};
245-
let Component!: React.ComponentType;
263+
let Component!: React.ComponentType<{
264+
community?: { id: string; name: string };
265+
}>;
246266
let dispose!: () => void;
247267
apply({
248268
relay: { snapshot: () => snapshot, subscribe: () => () => {} },
249269
effect: (setup: () => () => void) => {
250270
dispose = setup();
251271
},
252272
settingsCards: {
253-
register: (page: { component: React.ComponentType }) => {
273+
register: (page: {
274+
component: React.ComponentType<{
275+
community?: { id: string; name: string };
276+
}>;
277+
}) => {
254278
Component = page.component;
255279
},
256280
},
257281
} as unknown as Parameters<PluginModule["apply"]>[0]);
258282
try {
259283
await act(async () => {
260-
render(<Component />);
284+
render(<Component community={{ id: "primary", name: "Primary" }} />);
261285
});
262286
expect(screen.getByRole("status")).toHaveTextContent("Starting…");
263287
await act(async () => {

‎src/bundled/mesh-compute/index.tsx‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export const apply: PluginModule["apply"] = (ctx) => {
7272
lease = undefined;
7373
});
7474

75-
function CommunityComputePage() {
75+
function CommunityComputePage({
76+
community,
77+
}: {
78+
community?: { id: string; name: string };
79+
}) {
7680
const snapshot = useSyncExternalStore(
7781
ctx.relay.subscribe,
7882
ctx.relay.snapshot,
@@ -166,20 +170,23 @@ export const apply: PluginModule["apply"] = (ctx) => {
166170
starting={phase === "starting"}
167171
disabled={
168172
busy ||
173+
(!community && !enabled) ||
169174
!isTauri() ||
170175
!status?.available ||
171176
!phase ||
172177
phase === "stopping" ||
173178
(!enabled && snapshot.status !== "ready")
174179
}
175180
status={
176-
!isTauri()
177-
? "Open Buzz desktop to use shared compute."
178-
: phase
179-
? phaseLabels[phase]
180-
: status?.available === false
181-
? "Unavailable"
182-
: "Checking status…"
181+
!community
182+
? "Select a community to use shared compute."
183+
: !isTauri()
184+
? "Open Buzz desktop to use shared compute."
185+
: phase
186+
? phaseLabels[phase]
187+
: status?.available === false
188+
? "Unavailable"
189+
: "Checking status…"
183190
}
184191
error={error ?? status?.lifecycle?.reason ?? status?.reason}
185192
refreshDisabled={busy || !isTauri()}
@@ -192,6 +199,7 @@ export const apply: PluginModule["apply"] = (ctx) => {
192199
id: "mesh",
193200
title: "Compute",
194201
icon: CpuIcon,
202+
showInPersonalSpace: true,
195203
component: CommunityComputePage,
196204
});
197205
};

0 commit comments

Comments
 (0)