Use shared policy path help

This commit is contained in:
2026-07-10 18:40:50 +02:00
parent caaace14f3
commit 30fd6e7e5f

View File

@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState, type ReactNode } from "react";
import { ConnectionTree, FieldLabel, LoadingFrame, MailServerSettingsPanel, PolicyLockedHint, PolicyRow, PolicySourcePath, PolicyTable, ToggleSwitch, hasMailImapSettings, mailImapSettingsPayload, mailServerSecurityOptions, mailSmtpSettingsPayload, mailTextOrNull, mailTransportCredentialsPayload, mergeDeltaRows, normalizeMailServerSecurity, useDeltaWatermarks, type ConnectionTreeColumn, type MailServerConnectionTestResult, type MailServerCredentialSettings, type MailServerFolderLookupResult, type MailServerImapSettings, type MailServerSmtpSettings, type PolicySourcePathItem } from "@govoplan/core-webui";
import { ConnectionTree, FieldLabel, LoadingFrame, MailServerSettingsPanel, PolicyLockedHint, PolicyPathHelp, PolicyRow, PolicySourcePath, PolicyTable, ToggleSwitch, hasMailImapSettings, mailImapSettingsPayload, mailServerSecurityOptions, mailSmtpSettingsPayload, mailTextOrNull, mailTransportCredentialsPayload, mergeDeltaRows, normalizeMailServerSecurity, normalizePolicySourcePathItems, useDeltaWatermarks, type ConnectionTreeColumn, type MailServerConnectionTestResult, type MailServerCredentialSettings, type MailServerFolderLookupResult, type MailServerImapSettings, type MailServerSmtpSettings, type NormalizedPolicySourcePathItem, type PolicySourcePathItem } from "@govoplan/core-webui";
import { Pencil, Plus, Trash2 } from "lucide-react";
import type { ApiSettings } from "../../types";
import {
@@ -1280,28 +1280,15 @@ function policyHelp(description: string): ReactNode {
return <span>{description}</span>;
}
type PolicySourceItem = {
label: string;
policy?: MailProfilePolicy | Record<string, unknown> | null;
};
function mailBooleanPolicyPathHelp(key: "allow_user_profiles" | "allow_group_profiles" | "allow_campaign_profiles", sources: PolicySourcePathItem[]): ReactNode {
return <PolicyPathHelp lines={mailBooleanPolicyPathLines(key, normalizePolicySourceItems(sources))} />;
return <PolicyPathHelp lines={mailBooleanPolicyPathLines(key, normalizePolicySourcePathItems(sources))} />;
}
function mailCredentialPolicyPathHelp(protocol: "smtp_credentials" | "imap_credentials", sources: PolicySourcePathItem[]): ReactNode {
return <PolicyPathHelp lines={mailCredentialPolicyPathLines(protocol, normalizePolicySourceItems(sources))} />;
return <PolicyPathHelp lines={mailCredentialPolicyPathLines(protocol, normalizePolicySourcePathItems(sources))} />;
}
function PolicyPathHelp({ lines }: {lines: string[];}) {
return (
<span className="policy-path-help">
{lines.map((line, index) => <span className="policy-path-help-line" key={`${line}-${index}`}>{line}</span>)}
</span>);
}
function mailBooleanPolicyPathLines(key: "allow_user_profiles" | "allow_group_profiles" | "allow_campaign_profiles", items: PolicySourceItem[]): string[] {
function mailBooleanPolicyPathLines(key: "allow_user_profiles" | "allow_group_profiles" | "allow_campaign_profiles", items: NormalizedPolicySourcePathItem[]): string[] {
if (items.length === 0) return ["i18n:govoplan-mail.system_allow.ed6744b1"];
const lines: string[] = [];
for (const [index, item] of items.entries()) {
@@ -1316,7 +1303,7 @@ function mailBooleanPolicyPathLines(key: "allow_user_profiles" | "allow_group_pr
return lines;
}
function mailCredentialPolicyPathLines(protocol: "smtp_credentials" | "imap_credentials", items: PolicySourceItem[]): string[] {
function mailCredentialPolicyPathLines(protocol: "smtp_credentials" | "imap_credentials", items: NormalizedPolicySourcePathItem[]): string[] {
if (items.length === 0) return ["i18n:govoplan-mail.system_profile_inherited.f4b8b5ce"];
const lines: string[] = [];
for (const [index, item] of items.entries()) {
@@ -1331,14 +1318,7 @@ function mailCredentialPolicyPathLines(protocol: "smtp_credentials" | "imap_cred
return lines;
}
function normalizePolicySourceItems(items: PolicySourcePathItem[]): PolicySourceItem[] {
return items.map((item) => {
if (typeof item === "string") return { label: item };
return { label: item.label, policy: item.policy };
}).filter((item) => item.label.trim());
}
function policySourceRecord(item: PolicySourceItem): Record<string, unknown> {
function policySourceRecord(item: NormalizedPolicySourcePathItem): Record<string, unknown> {
return asRecord(item.policy);
}