Files
nanobot/webui/src/components/settings/channels/ChannelInstancesPanel.tsx
T
chengyongru 30e43aec82 refactor(webui): separate presentation views and expand component gallery (#6179)
* refactor(webui): organize shared components with an internal gallery

* refactor(webui): decouple views and expand component gallery

* fix(docker): include channel sources in WebUI build

* refactor(webui): cover all channel interfaces in gallery

* docs(webui): remove manual paragraph wrapping
2026-10-14 00:11:00 +08:00

55 lines
1.8 KiB
TypeScript

import type { ReactNode } from "react";
import {
configureChannel,
disableNanobotFeature,
enableNanobotFeature,
} from "@/lib/api";
import type { NanobotChannelInstanceInfo, NanobotFeatureInfo, NanobotFeaturesPayload } from "@/lib/types";
import { useClient } from "@/providers/ClientProvider";
import {
ChannelInstancesPanelView,
type ChannelInstancesPanelCustomization,
type ChannelInstancesPanelViewProps,
} from "./ChannelInstancesPanelView";
export type { ChannelInstancesPanelCustomization } from "./ChannelInstancesPanelView";
export function ChannelInstancesPanel({
feature,
showBrandLogos,
instances,
onFeaturesUpdate,
customization,
renderView,
}: {
feature: NanobotFeatureInfo;
showBrandLogos: boolean;
instances?: NanobotChannelInstanceInfo[];
onFeaturesUpdate: (payload: NanobotFeaturesPayload) => void;
customization?: ChannelInstancesPanelCustomization;
renderView?: (props: ChannelInstancesPanelViewProps) => ReactNode;
}) {
const { client } = useClient();
const viewProps: ChannelInstancesPanelViewProps = {
feature,
showBrandLogos,
instances,
customization,
onToggleInstance: async (instance, checked) => {
const payload = checked
? await enableNanobotFeature(client, feature.name, { instanceId: instance.id })
: await disableNanobotFeature(client, feature.name, { instanceId: instance.id });
onFeaturesUpdate(payload);
},
onSaveInstance: async (instance, values) => {
const payload = await configureChannel(client, feature.name, values, {
enable: instance.enabled,
instanceId: instance.id,
});
if (payload.nanobot_features) onFeaturesUpdate(payload.nanobot_features);
},
};
return renderView ? renderView(viewProps) : <ChannelInstancesPanelView {...viewProps} />;
}