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
@@ -11,9 +11,6 @@ import {
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
Clipboard,
|
||||
Loader2,
|
||||
Plus,
|
||||
} from "lucide-react";
|
||||
@@ -24,20 +21,17 @@ import type {
|
||||
ChannelFeatureAction,
|
||||
ChannelPluginConnectFlowProps,
|
||||
} from "@/channel-plugins/types";
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import {
|
||||
type ChannelProviderPreset,
|
||||
type ChannelSetupPresentation,
|
||||
} from "@/channel-plugins/catalog";
|
||||
import {
|
||||
ChannelFieldGroups,
|
||||
channelRequirementErrors,
|
||||
channelServerValidationErrors,
|
||||
focusFirstChannelFieldError,
|
||||
} from "@/components/settings/channels/ChannelCredentialFields";
|
||||
import {
|
||||
CredentialForm,
|
||||
channelValuesForSubmit,
|
||||
defaultChannelFieldValues,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
@@ -49,11 +43,7 @@ import {
|
||||
channelToggleChecked,
|
||||
localizedChannelDisplayName,
|
||||
} from "@/components/settings/channels/ChannelIdentity";
|
||||
import {
|
||||
ChannelProviderPresets,
|
||||
ChannelSetupActions,
|
||||
} from "@/components/settings/channels/ChannelSetupParts";
|
||||
import { ChannelValidationProgress } from "@/components/settings/channels/ChannelValidationProgress";
|
||||
import { ChannelSetupSurfaceView } from "@/components/settings/channels/ChannelSetupSurfaceView";
|
||||
import { ChannelInstancesPanel } from "@/components/settings/channels/ChannelInstancesPanel";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -235,9 +225,6 @@ function ChannelSetupSurface({
|
||||
(field) => field.secret && configuredFields.has(field.key),
|
||||
);
|
||||
const availablePresets = feature.configured ? [] : setup.presets ?? [];
|
||||
const hasAdvanced = advancedFields.length > 0
|
||||
|| savedSecretFields.length > 0
|
||||
|| availablePresets.length > 0;
|
||||
const [fieldValues, setFieldValues] = useState<Record<string, string>>(() =>
|
||||
defaultChannelFieldValues(editableFields, feature.config_values),
|
||||
);
|
||||
@@ -507,230 +494,23 @@ function ChannelSetupSurface({
|
||||
}
|
||||
};
|
||||
|
||||
const inlineActions = mode === "credentials" && primaryFields.length === 1
|
||||
&& !advancedOpen && !setup.presets?.length && !setup.actions?.length;
|
||||
const credentialActions = mode === "credentials" ? (
|
||||
<div className="ms-auto flex min-h-10 flex-wrap items-center justify-end gap-x-3 gap-y-2 sm:min-h-9">
|
||||
{feature.setup?.verifies_connection ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="h-10 rounded-full px-3 text-[12px] font-semibold sm:h-9"
|
||||
onClick={() => void checkCurrentSettings()}
|
||||
disabled={actionPending}
|
||||
>
|
||||
{tx("settings.channels.checkConnection", "Check connection")}
|
||||
</Button>
|
||||
) : null}
|
||||
<ToggleButton checked={enabled} disabled={actionPending}
|
||||
label={tx("settings.channels.enable", "Enable")}
|
||||
onChange={(next) => void toggleEnabled(next)} />
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<form
|
||||
className="flex flex-col gap-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (mode === "credentials") void saveCredentialSettings();
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 pe-20">
|
||||
{header}
|
||||
<div className="ms-auto flex min-h-8 items-center gap-2">
|
||||
<span
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1.5 text-[11px] leading-4 text-muted-foreground",
|
||||
!autoSaving && autoSaveState !== "saved" && "sr-only",
|
||||
)}
|
||||
>
|
||||
{autoSaving ? (
|
||||
<>
|
||||
<Loader2 className="h-3 w-3 animate-spin" aria-hidden />
|
||||
{tx("settings.actions.saving", "Saving")}
|
||||
</>
|
||||
) : autoSaveState === "saved" ? (
|
||||
<>
|
||||
<Check className="h-3 w-3" aria-hidden />
|
||||
{tx("settings.channels.savedSettings", "Settings saved.")}
|
||||
</>
|
||||
) : null}
|
||||
</span>
|
||||
{hasAdvanced ? (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex min-h-8 items-center gap-1.5 rounded px-1 text-[12px] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-offset-2"
|
||||
aria-expanded={advancedOpen}
|
||||
aria-controls={advancedPanelId}
|
||||
onClick={() => setAdvancedOpen((current) => !current)}
|
||||
>
|
||||
{tx("settings.channels.advanced", "Advanced")}
|
||||
<ChevronDown className={cn(
|
||||
"h-3.5 w-3.5 transition-transform motion-reduce:transition-none",
|
||||
advancedOpen && "rotate-180",
|
||||
)} aria-hidden />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<ChannelRuntimeError message={feature.runtime_error} />
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<section className={cn("min-w-0", inlineActions ? "flex-[1_1_20rem]" : "w-full")}>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<div className="flex max-w-full flex-wrap justify-end gap-2">
|
||||
{mode === "webui" ? (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-2.5 py-1 text-[11.5px] font-medium text-emerald-700 dark:text-emerald-200">
|
||||
<Check className="h-3.5 w-3.5" aria-hidden />
|
||||
{tx("settings.channels.managedByWebui", "Managed by WebUI")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<ChannelSetupActions feature={feature} setup={setup} onNotice={setNotice} />
|
||||
|
||||
{mode === "connect" && ConnectFlow ? (
|
||||
<Suspense fallback={<ChannelPluginLoading compact />}>
|
||||
<ConnectFlow
|
||||
token={token}
|
||||
feature={feature}
|
||||
idleLabel={setup.primaryActionLabel ?? tx("settings.channels.connect", "Connect")}
|
||||
connectRequestId={connectRequestId}
|
||||
onFeaturesUpdate={onFeaturesUpdate}
|
||||
/>
|
||||
</Suspense>
|
||||
) : mode === "connect" ? (
|
||||
<>
|
||||
<div className="mt-3 flex flex-wrap justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="h-8 rounded-full bg-background/80 px-3 text-[12px] font-semibold settings-hover"
|
||||
onClick={() =>
|
||||
setNotice(
|
||||
tx(
|
||||
"settings.channels.connectPreview",
|
||||
"Run the command below in your terminal to connect.",
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{setup.primaryActionLabel ?? tx("settings.channels.connect", "Connect")}
|
||||
</Button>
|
||||
{setup.command ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="h-8 rounded-full px-3 text-[12px] font-semibold"
|
||||
onClick={copyCommand}
|
||||
>
|
||||
<Clipboard className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
{tx("settings.channels.copyCommand", "Copy command")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{setup.command ? (
|
||||
<code className="mt-3 block rounded-control border border-border/50 bg-muted/45 px-2.5 py-2 font-mono text-[11px] leading-5 text-foreground">
|
||||
{setup.command}
|
||||
</code>
|
||||
) : null}
|
||||
</>
|
||||
) : mode === "credentials" ? (
|
||||
<>
|
||||
{primaryFields.length ? (
|
||||
<ChannelFieldGroups
|
||||
fields={primaryFields}
|
||||
values={fieldValues}
|
||||
configuredFields={configuredFields}
|
||||
visibleSecrets={visibleSecrets}
|
||||
onChange={setFieldValue}
|
||||
onFieldBlur={saveSecretOnBlur}
|
||||
onToggleSecret={toggleSecret}
|
||||
errors={fieldErrors}
|
||||
clearedSecrets={clearedSecrets}
|
||||
onClearSecret={setSecretCleared}
|
||||
requirements={setup.requirements ?? []}
|
||||
sectionLabels={setup.sectionLabels}
|
||||
disabled={actionPending}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
{hasAdvanced ? (
|
||||
<div id={advancedPanelId} hidden={!advancedOpen} className="min-w-0 w-full space-y-3 text-[12px] leading-5 text-muted-foreground">
|
||||
{availablePresets.length ? (
|
||||
<ChannelProviderPresets
|
||||
presets={availablePresets}
|
||||
onApply={applyPreset}
|
||||
label={setup.presetLabel}
|
||||
disabled={actionPending}
|
||||
/>
|
||||
) : null}
|
||||
<div className="space-y-2">
|
||||
{savedSecretFields.filter((field) => !(fieldValues[field.key] ?? "").trim()).map((field) => (
|
||||
<div key={field.key} className="flex min-h-9 flex-wrap items-center justify-between gap-x-4 gap-y-1">
|
||||
<span>{field.label}</span>
|
||||
<button type="button" className="min-h-8 text-[12px] hover:text-foreground"
|
||||
onClick={() => setSecretCleared(field.key, !clearedSecrets.has(field.key))}>
|
||||
{clearedSecrets.has(field.key)
|
||||
? tx("settings.channels.keepSavedSecret", "Keep saved credential")
|
||||
: tx("settings.channels.removeSavedSecret", "Remove saved credential")}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{advancedFields.length ? (
|
||||
<div onBlur={() => void saveConnectionSettings()}>
|
||||
<CredentialForm
|
||||
fields={advancedFields}
|
||||
values={fieldValues}
|
||||
configuredFields={configuredFields}
|
||||
visibleSecrets={visibleSecrets}
|
||||
onChange={setFieldValue}
|
||||
onFieldBlur={saveSecretOnBlur}
|
||||
onToggleSecret={toggleSecret}
|
||||
errors={fieldErrors}
|
||||
clearedSecrets={clearedSecrets}
|
||||
onClearSecret={setSecretCleared}
|
||||
compact
|
||||
disabled={actionPending}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{credentialActions}
|
||||
</div>
|
||||
{mode === "credentials" && feature.setup?.verifies_connection
|
||||
&& (validation || validating) ? (
|
||||
<div>
|
||||
<ChannelValidationProgress
|
||||
validation={validation}
|
||||
validating={validating}
|
||||
feature={feature}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className={cn(
|
||||
"rounded-control bg-muted/55 px-3 py-2.5 text-[12px] leading-5 text-muted-foreground",
|
||||
!notice && "sr-only",
|
||||
)}
|
||||
>
|
||||
{notice ?? ""}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
return <ChannelSetupSurfaceView
|
||||
header={header} feature={feature} setup={setup}
|
||||
primaryFields={primaryFields} advancedFields={advancedFields} savedSecretFields={savedSecretFields}
|
||||
availablePresets={availablePresets} configuredFields={configuredFields}
|
||||
fieldValues={fieldValues} visibleSecrets={visibleSecrets} clearedSecrets={clearedSecrets} fieldErrors={fieldErrors}
|
||||
actionPending={actionPending} enabled={enabled} autoSaving={autoSaving} autoSaveState={autoSaveState}
|
||||
advancedOpen={advancedOpen} advancedPanelId={advancedPanelId} validation={validation} validating={validating} notice={notice}
|
||||
onAdvancedOpenChange={setAdvancedOpen} onChangeField={setFieldValue} onFieldBlur={saveSecretOnBlur}
|
||||
onToggleSecret={toggleSecret} onClearSecret={setSecretCleared} onApplyPreset={applyPreset}
|
||||
onSubmit={saveCredentialSettings} onCheckConnection={checkCurrentSettings} onToggleEnabled={toggleEnabled}
|
||||
onSaveConnectionSettings={saveConnectionSettings} onCopyCommand={copyCommand} onNotice={setNotice}
|
||||
connectFlow={mode === "connect" && ConnectFlow ? <Suspense fallback={<ChannelPluginLoading compact />}>
|
||||
<ConnectFlow token={token} feature={feature}
|
||||
idleLabel={setup.primaryActionLabel ?? tx("settings.channels.connect", "Connect")}
|
||||
connectRequestId={connectRequestId} onFeaturesUpdate={onFeaturesUpdate} />
|
||||
</Suspense> : undefined}
|
||||
/>;
|
||||
}
|
||||
|
||||
function ChannelPluginLoading({ compact = false }: { compact?: boolean }) {
|
||||
|
||||
Reference in new issue
Block a user