Skip to content

Commit 201b378

Browse files
authored
Merge pull request #37 from SubBoost/ryan/dev
Polish proxy group layout
2 parents 9d5900c + 0b199c7 commit 201b378

8 files changed

Lines changed: 81 additions & 14 deletions

packages/ui/src/product/converter/advanced-mode/sections/proxy-group-advanced-panel.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("ProxyGroupAdvancedPanel", () => {
122122
expect(html).toContain("DIRECT");
123123
expect(html).toContain("rules-content");
124124
expect(html).toContain("还没有分流规则");
125+
expect(html).toContain("max-h-52 space-y-1.5 overflow-y-auto pr-1 custom-scrollbar");
125126
expect(mocks.inputs.map((input) => input.value)).toEqual(["Source", "Japan"]);
126127

127128
mocks.inputs[0].onChange({ target: { value: "IEPL" } });
@@ -198,6 +199,55 @@ describe("ProxyGroupAdvancedPanel", () => {
198199
expect(html).toContain("暂无已启用的节点或代理组");
199200
});
200201

202+
it("previews enabled members for a disabled built-in proxy group", () => {
203+
mocks.store = {
204+
...mocks.store,
205+
enabledProxyGroups: [],
206+
customProxyGroups: [],
207+
proxyGroupAdvanced: {},
208+
};
209+
210+
const html = renderToStaticMarkup(
211+
React.createElement(ProxyGroupAdvancedPanel, {
212+
target: { kind: "module", id: "auto", name: "⚡ Auto" },
213+
advanced: {},
214+
onChange: vi.fn(),
215+
rulesCount: 0,
216+
rulesContent: null,
217+
}),
218+
);
219+
220+
expect(html).toContain("US Source");
221+
expect(html).toContain("Japan Source");
222+
expect(html).toContain("max-h-52 overflow-y-auto pr-1 custom-scrollbar flex flex-wrap gap-1.5");
223+
expect(html).not.toContain("暂无已启用的节点或代理组");
224+
});
225+
226+
it("previews enabled members for a disabled custom proxy group", () => {
227+
mocks.store = {
228+
...mocks.store,
229+
enabledProxyGroups: [],
230+
customProxyGroups: [
231+
{ id: "media", name: "Media", emoji: "", groupType: "select", enabled: false },
232+
],
233+
proxyGroupAdvanced: {},
234+
};
235+
236+
const html = renderToStaticMarkup(
237+
React.createElement(ProxyGroupAdvancedPanel, {
238+
target: { kind: "custom", id: "media", name: "Media" },
239+
advanced: {},
240+
onChange: vi.fn(),
241+
rulesCount: 0,
242+
rulesContent: null,
243+
}),
244+
);
245+
246+
expect(html).toContain("US Source");
247+
expect(html).toContain("Japan Source");
248+
expect(html).not.toContain("暂无已启用的节点或代理组");
249+
});
250+
201251
it("normalizes advanced member helpers without rendering the panel", () => {
202252
const nodes = [node("US Source")];
203253
const moduleNames = { auto: "Auto", select: "Select" };

packages/ui/src/product/converter/advanced-mode/sections/proxy-group-advanced-panel.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ export function ProxyGroupAdvancedPanel({
182182
() => customProxyGroups.filter((group) => group.enabled !== false),
183183
[customProxyGroups],
184184
);
185+
const previewEnabledProxyGroups = React.useMemo(() => {
186+
if (target.kind !== "module" || enabledProxyGroups.includes(target.id)) return enabledProxyGroups;
187+
return [...enabledProxyGroups, target.id];
188+
}, [enabledProxyGroups, target.id, target.kind]);
189+
const previewCustomProxyGroups = React.useMemo(() => {
190+
if (target.kind !== "custom") return customProxyGroups;
191+
return customProxyGroups.map((group) =>
192+
group.id === target.id && group.enabled === false ? { ...group, enabled: true } : group,
193+
);
194+
}, [customProxyGroups, target.id, target.kind]);
185195

186196
const activeNodes = React.useMemo(
187197
() => nodes.filter((node) => !isSubscriptionInfoNodeName(node.name)),
@@ -202,11 +212,11 @@ export function ProxyGroupAdvancedPanel({
202212
if (nodes.length === 0) return [];
203213
const generated = generateProxyGroups({
204214
nodes,
205-
enabledModules: enabledProxyGroups,
215+
enabledModules: previewEnabledProxyGroups,
206216
ruleProviderBaseUrl,
207217
testUrl,
208218
testInterval,
209-
customProxyGroups: activeCustomProxyGroups,
219+
customProxyGroups: previewCustomProxyGroups,
210220
customRuleSets,
211221
proxyGroupAdvanced,
212222
builtinRuleEdits,
@@ -215,11 +225,11 @@ export function ProxyGroupAdvancedPanel({
215225
return generated.find((group) => group.name === target.name)?.proxies ?? [];
216226
}, [
217227
nodes,
218-
enabledProxyGroups,
228+
previewEnabledProxyGroups,
219229
ruleProviderBaseUrl,
220230
testUrl,
221231
testInterval,
222-
activeCustomProxyGroups,
232+
previewCustomProxyGroups,
223233
customRuleSets,
224234
proxyGroupAdvanced,
225235
builtinRuleEdits,
@@ -325,7 +335,7 @@ export function ProxyGroupAdvancedPanel({
325335
<div className="grid gap-0 md:grid-cols-[1fr_1fr_1fr]">
326336
<div className="p-3">
327337
<div className={ADVANCED_PANEL_TITLE_CLASS}>导入源</div>
328-
<div className="space-y-1.5">
338+
<div className="max-h-52 space-y-1.5 overflow-y-auto pr-1 custom-scrollbar">
329339
{sourceOptions.length === 0 ? (
330340
<div className="text-[11px] text-white/35">暂无可匹配的导入源</div>
331341
) : (
@@ -453,7 +463,7 @@ export function ProxyGroupAdvancedPanel({
453463
{excludedMembers.length === 0 ? (
454464
<div className="text-[11px] text-white/35">暂无未启用的节点或代理组</div>
455465
) : (
456-
<div className="flex flex-wrap gap-1.5">
466+
<div className="max-h-52 overflow-y-auto pr-1 custom-scrollbar flex flex-wrap gap-1.5">
457467
{excludedMembers.map((member) => {
458468
return (
459469
<button

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-added-rule-sets.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ describe("ProxyGroupsAddedRuleSets", () => {
323323
expect(html).toContain(RULE_EDIT_PRIMARY_FIELD_CLASS);
324324
expect(html).toContain(RULE_EDIT_TRAILING_CONTROLS_CLASS);
325325
expect(html).toContain(RULE_EDIT_ACTIONS_CLASS);
326+
expect(html).toContain("proxy-group-rule-no-resolve-label");
326327
expect(mocks.captures.inputs).toHaveLength(0);
327328
expect(mocks.captures.selects).toHaveLength(1);
328329
expect(RULE_TARGET_SELECT_TRIGGER_CLASS).toContain("w-[120px]");

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-added-rule-sets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export function ProxyGroupsAddedRuleSets({
332332
)
333333
}
334334
/>
335-
<span className="text-[10px] text-white/50">
335+
<span className="proxy-group-rule-no-resolve-label text-[10px] text-white/50">
336336
no-resolve
337337
</span>
338338
</div>

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-categories.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ describe("ProxyGroupsCategories", () => {
263263
renderCategories({ 0: new Set(["core"]) });
264264

265265
expect(mocks.captures.inputs).toHaveLength(0);
266-
expect(renderCategories({ 0: new Set(["core"]) }).html).toContain("https://rules.example/base/");
266+
const html = renderCategories({ 0: new Set(["core"]) }).html;
267+
expect(html).toContain("https://rules.example/base/");
268+
expect(html).toContain("grid-cols-[minmax(0,1fr)_96px]");
269+
expect(html).not.toContain("md:grid-cols-[minmax(0,1fr)_96px]");
270+
expect(html).toContain("min-w-0 space-y-1");
271+
expect(html).toContain("h-9 w-full");
267272
expect(mocks.store.setRuleProviderBaseUrl).not.toHaveBeenCalled();
268273

269274
expect(mocks.captures.moduleCards).toHaveLength(1);

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-categories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ export function ProxyGroupsCategories() {
290290

291291
return (
292292
<>
293-
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_96px]">
294-
<div className="space-y-1">
293+
<div className="grid grid-cols-[minmax(0,1fr)_96px] gap-3">
294+
<div className="min-w-0 space-y-1">
295295
<div className={PROXY_GROUP_SECTION_LABEL_ROW_CLASS}>
296296
<label className={PROXY_GROUP_SECTION_LABEL_CLASS}>规则集 URL</label>
297297
</div>
@@ -302,11 +302,11 @@ export function ProxyGroupsCategories() {
302302
<span className="block truncate">{ruleProviderBaseUrl}</span>
303303
</div>
304304
</div>
305-
<div className="space-y-1">
305+
<div className="min-w-0 space-y-1">
306306
<div className={PROXY_GROUP_SECTION_LABEL_ROW_CLASS}>
307307
<label className="text-xs text-amber-300">高级模式</label>
308308
</div>
309-
<div className="flex h-9 items-center justify-center gap-1 rounded-md border border-white/10 bg-white/5 px-2">
309+
<div className="flex h-9 w-full items-center justify-center gap-1 rounded-md border border-white/10 bg-white/5 px-2">
310310
<span className="text-[10px] text-white/65">
311311
{proxyGroupAdvancedModeEnabled ? "已开启" : "未开启"}
312312
</span>

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-custom-rules.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe("ProxyGroupsCustomRules", () => {
242242
expect(html).toContain(RULE_HEADER_ROW_CLASS);
243243
expect(html).toContain(RULE_EDIT_PRIMARY_GROUP_CLASS);
244244
expect(html).toContain(RULE_EDIT_TRAILING_CONTROLS_CLASS);
245+
expect(html).toContain("proxy-group-rule-no-resolve-label");
245246
expect(RULE_EDIT_TRAILING_CONTROLS_CLASS).toContain(
246247
"proxy-group-custom-rule-editor-trailing",
247248
);

packages/ui/src/product/converter/advanced-mode/sections/proxy-groups-custom-rules.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export function ProxyGroupsCustomRules() {
296296
checked={newRuleNoResolve}
297297
onCheckedChange={setNewRuleNoResolve}
298298
/>
299-
<span className="text-[10px] text-white/50">no-resolve</span>
299+
<span className="proxy-group-rule-no-resolve-label text-[10px] text-white/50">no-resolve</span>
300300
</div>
301301
<Button
302302
type="button"
@@ -414,7 +414,7 @@ export function ProxyGroupsCustomRules() {
414414
)
415415
}
416416
/>
417-
<span className="text-[10px] text-white/50">
417+
<span className="proxy-group-rule-no-resolve-label text-[10px] text-white/50">
418418
no-resolve
419419
</span>
420420
</div>

0 commit comments

Comments
 (0)