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
This commit is contained in:
1 parent
db804ef94a
commit
30e43aec82
109 files changed
+7874
-3459
No files matched your search
@@ -1,14 +1,6 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
channelTranslator,
|
||||
} from "@/channel-plugins/i18n";
|
||||
import type { ChannelPluginPanelProps } from "@/channel-plugins/types";
|
||||
import { ChannelInstancesPanel } from "@/components/settings/channels/ChannelInstancesPanel";
|
||||
import type {
|
||||
NanobotChannelInstanceInfo,
|
||||
NanobotFeatureInfo,
|
||||
} from "@/lib/types";
|
||||
import { FeishuAssistantsPanelView } from "./FeishuAssistantsPanelView";
|
||||
import { FeishuConnectFlow } from "./FeishuConnectFlow";
|
||||
|
||||
export function FeishuAssistantsPanel({
|
||||
@@ -17,60 +9,17 @@ export function FeishuAssistantsPanel({
|
||||
showBrandLogos,
|
||||
onFeaturesUpdate,
|
||||
}: ChannelPluginPanelProps) {
|
||||
const { t } = useTranslation();
|
||||
const tx = channelTranslator(t, "feishu");
|
||||
const instances = feature.instances?.length
|
||||
? feature.instances
|
||||
: [defaultFeishuInstance(feature)];
|
||||
|
||||
return (
|
||||
<ChannelInstancesPanel
|
||||
feature={feature}
|
||||
showBrandLogos={showBrandLogos}
|
||||
instances={instances}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
customization={{
|
||||
toggleAriaLabel: (instance) => tx("custom.toggleAssistant", "{{name}} assistant", {
|
||||
name: instanceDisplayName(instance),
|
||||
}),
|
||||
configuredLabel: tx("custom.configured", "Connected"),
|
||||
needsSetupLabel: tx("custom.needsSetup", "Needs authorization"),
|
||||
renderInstanceSummary: () => null,
|
||||
renderInstanceAction: (instance) => instance.configured ? null : (
|
||||
<FeishuConnectFlow
|
||||
key={instance.id}
|
||||
token={token}
|
||||
instanceId={instance.id}
|
||||
mode="replace"
|
||||
idleLabel={t("settings.channels.connect", { defaultValue: "Connect" })}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
/>
|
||||
),
|
||||
footer: instances.some((instance) => instance.configured) ? (
|
||||
<FeishuConnectFlow
|
||||
key={instances.map((instance) => instance.id).join(",")}
|
||||
token={token}
|
||||
mode="create"
|
||||
idleLabel={tx("custom.addAssistant", "Add another assistant")}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
/>
|
||||
) : null,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function defaultFeishuInstance(feature: NanobotFeatureInfo): NanobotChannelInstanceInfo {
|
||||
return {
|
||||
id: "default",
|
||||
name: "nanobot",
|
||||
enabled: feature.enabled,
|
||||
configured: Boolean(feature.configured),
|
||||
config_values: feature.config_values ?? {},
|
||||
configured_fields: feature.configured_fields ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
function instanceDisplayName(instance: NanobotChannelInstanceInfo): string {
|
||||
return instance.display_name?.trim() || instance.name.trim() || instance.id;
|
||||
return <ChannelInstancesPanel
|
||||
feature={feature}
|
||||
showBrandLogos={showBrandLogos}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
renderView={(props) => <FeishuAssistantsPanelView
|
||||
{...props}
|
||||
renderConnectFlow={(options) => <FeishuConnectFlow
|
||||
{...options}
|
||||
token={token}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
/>}
|
||||
/>}
|
||||
/>;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Fragment, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { channelTranslator } from "@/channel-plugins/i18n";
|
||||
import { ChannelInstancesPanelView, type ChannelInstancesPanelViewProps } from "@/components/settings/channels/ChannelInstancesPanelView";
|
||||
import type { NanobotChannelInstanceInfo, NanobotFeatureInfo } from "@/lib/types";
|
||||
|
||||
export type FeishuConnectOptions = {
|
||||
instanceId?: string;
|
||||
mode: "replace" | "create";
|
||||
idleLabel: string;
|
||||
};
|
||||
|
||||
export type FeishuAssistantsPanelViewProps = Omit<ChannelInstancesPanelViewProps, "customization"> & {
|
||||
renderConnectFlow: (options: FeishuConnectOptions) => ReactNode;
|
||||
};
|
||||
|
||||
export function FeishuAssistantsPanelView({
|
||||
feature,
|
||||
showBrandLogos,
|
||||
instances: providedInstances,
|
||||
onToggleInstance,
|
||||
onSaveInstance,
|
||||
renderConnectFlow,
|
||||
}: FeishuAssistantsPanelViewProps) {
|
||||
const { t } = useTranslation();
|
||||
const tx = channelTranslator(t, "feishu");
|
||||
const instances = providedInstances ?? (feature.instances?.length
|
||||
? feature.instances
|
||||
: [defaultFeishuInstance(feature)]);
|
||||
|
||||
return <ChannelInstancesPanelView
|
||||
feature={feature}
|
||||
showBrandLogos={showBrandLogos}
|
||||
instances={instances}
|
||||
onToggleInstance={onToggleInstance}
|
||||
onSaveInstance={onSaveInstance}
|
||||
customization={{
|
||||
toggleAriaLabel: (instance) => tx("custom.toggleAssistant", "{{name}} assistant", {
|
||||
name: instanceDisplayName(instance),
|
||||
}),
|
||||
configuredLabel: tx("custom.configured", "Connected"),
|
||||
needsSetupLabel: tx("custom.needsSetup", "Needs authorization"),
|
||||
renderInstanceSummary: () => null,
|
||||
renderInstanceAction: (instance) => instance.configured ? null : (
|
||||
<Fragment key={instance.id}>{renderConnectFlow({
|
||||
instanceId: instance.id,
|
||||
mode: "replace",
|
||||
idleLabel: t("settings.channels.connect", { defaultValue: "Connect" }),
|
||||
})}</Fragment>
|
||||
),
|
||||
footer: instances.some((instance) => instance.configured) ? (
|
||||
<Fragment key={instances.map((instance) => instance.id).join(",")}>{renderConnectFlow({
|
||||
mode: "create",
|
||||
idleLabel: tx("custom.addAssistant", "Add another assistant"),
|
||||
})}</Fragment>
|
||||
) : null,
|
||||
}}
|
||||
/>;
|
||||
}
|
||||
|
||||
function defaultFeishuInstance(feature: NanobotFeatureInfo): NanobotChannelInstanceInfo {
|
||||
return {
|
||||
id: "default",
|
||||
name: "nanobot",
|
||||
enabled: feature.enabled,
|
||||
configured: Boolean(feature.configured),
|
||||
config_values: feature.config_values ?? {},
|
||||
configured_fields: feature.configured_fields ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
function instanceDisplayName(instance: NanobotChannelInstanceInfo): string {
|
||||
return instance.display_name?.trim() || instance.name.trim() || instance.id;
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { channelTranslator } from "@/channel-plugins/i18n";
|
||||
import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow";
|
||||
import type { NanobotFeaturesPayload } from "@/lib/types";
|
||||
|
||||
import { FeishuConnectFlowView, useFeishuConnectLabels } from "./FeishuConnectFlowView";
|
||||
|
||||
export function FeishuConnectFlow({
|
||||
token,
|
||||
instanceId = "default",
|
||||
@@ -19,8 +18,7 @@ export function FeishuConnectFlow({
|
||||
connectRequestId?: number;
|
||||
onFeaturesUpdate: (payload: NanobotFeaturesPayload) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = channelTranslator(t, "feishu");
|
||||
const labels = useFeishuConnectLabels();
|
||||
return (
|
||||
<ChannelQrConnectFlow
|
||||
token={token}
|
||||
@@ -29,20 +27,8 @@ export function FeishuConnectFlow({
|
||||
idleLabel={idleLabel}
|
||||
connectRequestId={connectRequestId}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
labels={{
|
||||
qrAlt: tx("custom.qrAlt", "Feishu connection QR code"),
|
||||
scanTitle: tx("custom.scanTitle", "Scan with Feishu"),
|
||||
scanDescription: tx(
|
||||
"custom.scanDescription",
|
||||
"Use Feishu or Lark on your phone to scan this code. nanobot will finish setup automatically after authorization.",
|
||||
),
|
||||
waiting: tx("custom.waiting", "Waiting for authorization..."),
|
||||
connected: tx("custom.connected", "Feishu is connected."),
|
||||
stopped: tx("custom.stopped", "Connection stopped."),
|
||||
connecting: tx("custom.connecting", "Connecting..."),
|
||||
scanAgain: t("settings.channels.scanAgain", { defaultValue: "Scan again" }),
|
||||
connect: t("settings.channels.connect", { defaultValue: "Connect" }),
|
||||
}}
|
||||
labels={labels}
|
||||
renderView={(props) => <FeishuConnectFlowView {...props} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { channelTranslator } from "@/channel-plugins/i18n";
|
||||
import { ChannelQrConnectFlowView, type ChannelQrConnectFlowViewProps, type ChannelQrConnectLabels } from "@/components/settings/channels/ChannelQrConnectFlowView";
|
||||
|
||||
export type FeishuConnectFlowViewProps = Omit<ChannelQrConnectFlowViewProps, "labels">;
|
||||
|
||||
export function useFeishuConnectLabels(): ChannelQrConnectLabels {
|
||||
const { t } = useTranslation();
|
||||
const tx = channelTranslator(t, "feishu");
|
||||
return {
|
||||
qrAlt: tx("custom.qrAlt", "Feishu connection QR code"),
|
||||
scanTitle: tx("custom.scanTitle", "Scan with Feishu"),
|
||||
scanDescription: tx(
|
||||
"custom.scanDescription",
|
||||
"Use Feishu or Lark on your phone to scan this code. nanobot will finish setup automatically after authorization.",
|
||||
),
|
||||
waiting: tx("custom.waiting", "Waiting for authorization..."),
|
||||
connected: tx("custom.connected", "Feishu is connected."),
|
||||
stopped: tx("custom.stopped", "Connection stopped."),
|
||||
connecting: tx("custom.connecting", "Connecting..."),
|
||||
scanAgain: t("settings.channels.scanAgain", { defaultValue: "Scan again" }),
|
||||
connect: t("settings.channels.connect", { defaultValue: "Connect" }),
|
||||
};
|
||||
}
|
||||
|
||||
export function FeishuConnectFlowView(props: FeishuConnectFlowViewProps) {
|
||||
const labels = useFeishuConnectLabels();
|
||||
return <ChannelQrConnectFlowView {...props} labels={labels} />;
|
||||
}
|
||||
Reference in new issue
Block a user