feat(channels): add inherited global compaction notice policy
This commit is contained in:
1 parent
7644d845b4
commit
ab6d5f1d3c
35 files changed
+287
-37
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import i18n from "i18next";
|
||||
import { useMemo, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -80,7 +81,9 @@ export function channelSetup(
|
||||
const choiceLabels = setupMessages?.fields?.[
|
||||
channelFieldMessageKey(feature.name, field.key)
|
||||
]?.choices ?? {};
|
||||
const choices = field.kind === "bool" ? ["true", "false"] : field.choices;
|
||||
const choices = field.kind === "bool"
|
||||
? (field.inheritable ? ["", "true", "false"] : ["true", "false"])
|
||||
: field.choices;
|
||||
return {
|
||||
...copy,
|
||||
key: field.key,
|
||||
@@ -95,7 +98,9 @@ export function channelSetup(
|
||||
field.kind === "enum" || field.kind === "bool"
|
||||
? choices.map((choice) => ({
|
||||
value: choice,
|
||||
label: choiceLabels[choice] ?? fieldLabel(choice),
|
||||
label: choiceLabels[choice] ?? (choice === ""
|
||||
? i18n.t("settings.values.default", { lng: locale, ns: "common" })
|
||||
: fieldLabel(choice)),
|
||||
}))
|
||||
: undefined,
|
||||
};
|
||||
|
||||
@@ -1018,6 +1018,7 @@ export interface ChannelSetupContractField {
|
||||
choices: string[];
|
||||
required: boolean;
|
||||
default_value?: string;
|
||||
inheritable?: boolean;
|
||||
}
|
||||
|
||||
export interface ChannelSetupContract {
|
||||
|
||||
@@ -4,7 +4,9 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
CredentialForm,
|
||||
channelValuesForSubmit,
|
||||
defaultChannelFieldValues,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
import { channelSetup } from "@/components/settings/channels/ChannelIdentity";
|
||||
import type { ChannelConfigField } from "@/components/settings/channels/catalog";
|
||||
|
||||
const fields: ChannelConfigField[] = [
|
||||
@@ -24,6 +26,34 @@ const fields: ChannelConfigField[] = [
|
||||
];
|
||||
|
||||
describe("CredentialForm", () => {
|
||||
it("preserves inherited notices and lets an explicit override return to the default", () => {
|
||||
const key = "channels.qq.showCompactionNotices";
|
||||
const setup = channelSetup({
|
||||
name: "qq", display_name: "QQ", type: "channel", enabled: false,
|
||||
installed: true, ready: false, status: "not_enabled",
|
||||
install_supported: true, requires_restart: false,
|
||||
setup: { fields: [{
|
||||
key, field: "showCompactionNotices", kind: "bool", choices: [],
|
||||
required: false, inheritable: true,
|
||||
}] },
|
||||
});
|
||||
const noticeFields = setup.fields!;
|
||||
expect(defaultChannelFieldValues(noticeFields)).toEqual({ [key]: "" });
|
||||
expect(channelValuesForSubmit(noticeFields, {}, new Set())).toEqual({});
|
||||
expect(defaultChannelFieldValues(noticeFields, { [key]: "false" })).toEqual({ [key]: "false" });
|
||||
expect(channelValuesForSubmit(noticeFields, { [key]: "true" }, new Set([key])))
|
||||
.toEqual({ [key]: "true" });
|
||||
expect(channelValuesForSubmit(noticeFields, { [key]: "" }, new Set([key])))
|
||||
.toEqual({ [key]: "" });
|
||||
|
||||
const onChange = vi.fn();
|
||||
render(<CredentialForm fields={noticeFields} values={{ [key]: "false" }}
|
||||
visibleSecrets={{}} onChange={onChange} onToggleSecret={vi.fn()} />);
|
||||
expect(screen.getByRole("radio", { name: "Off" })).toBeChecked();
|
||||
fireEvent.click(screen.getByRole("radio", { name: "Default" }));
|
||||
expect(onChange).toHaveBeenCalledWith(key, "");
|
||||
});
|
||||
|
||||
it("uses native radio semantics for option fields", () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -24,6 +24,32 @@ function feature(overrides: Partial<NanobotFeatureInfo>): NanobotFeatureInfo {
|
||||
}
|
||||
|
||||
describe("channelSetup", () => {
|
||||
it("offers a localized inherited option without changing ordinary booleans", () => {
|
||||
const setup = channelSetup(feature({ setup: { fields: [
|
||||
{
|
||||
key: "channels.plugin-chat.showCompactionNotices",
|
||||
field: "showCompactionNotices",
|
||||
kind: "bool",
|
||||
choices: [],
|
||||
required: false,
|
||||
inheritable: true,
|
||||
},
|
||||
{
|
||||
key: "channels.plugin-chat.sendProgress",
|
||||
field: "sendProgress",
|
||||
kind: "bool",
|
||||
choices: [],
|
||||
required: false,
|
||||
},
|
||||
] } }), "zh-CN");
|
||||
expect(setup.fields?.[0]?.options).toEqual([
|
||||
{ value: "", label: "默认" },
|
||||
{ value: "true", label: "True" },
|
||||
{ value: "false", label: "False" },
|
||||
]);
|
||||
expect(setup.fields?.[1]?.options?.map((option) => option.value)).toEqual(["true", "false"]);
|
||||
});
|
||||
|
||||
it("builds editable fields for a plugin-owned backend contract", () => {
|
||||
const setup = channelSetup(feature({
|
||||
setup: {
|
||||
|
||||
Reference in new issue
Block a user