feat(campaign-ui): review and link managed attachments

This commit is contained in:
2026-07-20 20:08:41 +02:00
parent fce6dd1138
commit 0a6064ec62
9 changed files with 921 additions and 150 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -39,7 +39,7 @@ export default function TemplateDataPage({ settings, campaignId }: {settings: Ap
const version = data.currentVersion;
const locked = isAuditLockedVersion(version, data.campaign?.current_version_id);
const { draft, setDraft, displayDraft, dirty, saveState, localError, patch, markDirty, saveDraft } = useCampaignDraftEditor({
const { draft, setDraft, displayDraft, dirty, saveState, localError, patch, markDirty, discardDraft, saveDraft } = useCampaignDraftEditor({
settings,
campaignId,
version,
@@ -121,6 +121,7 @@ export default function TemplateDataPage({ settings, campaignId }: {settings: Ap
const handle = window.setTimeout(() => {
void previewCampaignAttachments(settings, campaignId, version.id, {
include_unmatched: false,
include_unlinked_candidates: true,
campaign_json: campaignJsonForAttachmentPreview(displayDraft)
}).
then((response) => {
@@ -233,7 +234,7 @@ export default function TemplateDataPage({ settings, campaignId }: {settings: Ap
</div>
<div className="button-row compact-actions">
<Button disabled>i18n:govoplan-campaign.manage_templates.23688071</Button>
<Button onClick={reload} disabled={loading}>i18n:govoplan-campaign.reload.cce71553</Button>
<Button onClick={() => void discardDraft()} disabled={loading}>Discard</Button>
<Button variant="primary" onClick={() => saveDraft("manual")} disabled={!dirty || locked || !draft}>i18n:govoplan-campaign.save.efc007a3</Button>
</div>
</div>
@@ -399,45 +400,46 @@ draft: Record<string, unknown>)
: CampaignMessagePreviewAttachment[] {
if (loading) {
return [{
filename: i18nMessage("i18n:govoplan-campaign.resolving_attachment_patterns.87d7d21b"),
detail: i18nMessage("i18n:govoplan-campaign.managed_files_are_being_checked_for_this_recipie.489ecefd")
filename: "Resolving attachment patterns",
detail: "Managed files are being checked for this recipient preview."
}];
}
if (error) {
return [{ filename: i18nMessage("i18n:govoplan-campaign.attachment_preview_unavailable.62211756"), detail: error }];
return [{ filename: "Attachment preview unavailable", detail: error }];
}
return rules.flatMap((rule) => {
const zipProtection = zipProtectionForRule(rule, draft);
const detailParts = [
rule.source === "global" ? i18nMessage("i18n:govoplan-campaign.global.5f1184f7") : i18nMessage("i18n:govoplan-campaign.recipient.90343260"),
rule.source === "global" ? "Global" : "Recipient",
rule.label,
rule.required ? i18nMessage("i18n:govoplan-campaign.required.eed6bfb4") : i18nMessage("i18n:govoplan-campaign.optional.0c6c4102"),
rule.required ? "Required" : "Optional",
rule.pattern].
filter(Boolean);
const detail = detailParts.join(" · ");
const fallbackArchiveLabel = i18nMessage("i18n:govoplan-campaign.recipient_attachments_zip.79d436c7");
const fallbackArchiveLabel = "Recipient attachments ZIP";
if (rule.matches.length > 0) {
return rule.matches.map((match) => ({
filename: match.filename || match.display_path,
label: rule.label,
detail: i18nMessage("i18n:govoplan-campaign.value_value.a8618e4a", { value0: detail, value1: match.display_path ? ` · ${match.display_path}` : "" }),
detail: `${match.linked_to_campaign === false ? "Unlinked candidate" : "Linked"} · ${match.display_path ? `${detail} · ${match.display_path}` : detail}`,
contentType: match.content_type,
sizeBytes: match.size_bytes,
linkedToCampaign: match.linked_to_campaign !== false,
archiveGroup: rule.zip_included ? rule.zip_filename || "recipient-attachments.zip" : null,
archiveLabel: rule.zip_included ? rule.zip_filename || fallbackArchiveLabel : null,
protected: zipProtection.protected,
protectionNote: zipProtection.note
}));
}
const pattern = rule.pattern || i18nMessage("i18n:govoplan-campaign.attachment_pattern.3540c952");
const pattern = rule.pattern || "attachment pattern";
return [{
filename: i18nMessage("i18n:govoplan-campaign.no_file_matched_value", { value0: pattern }),
filename: `No file matched ${pattern}`,
label: rule.label,
detail: i18nMessage("i18n:govoplan-campaign.value_value.a8618e4a", { value0: detail, value1: rule.status !== "ok" ? ` · ${rule.status}` : "" }),
archiveGroup: rule.zip_included ? rule.zip_filename || "recipient-attachments.zip" : null,
archiveLabel: rule.zip_included ? rule.zip_filename || fallbackArchiveLabel : null,
protected: zipProtection.protected,
protectionNote: zipProtection.note
detail: rule.status !== "ok" ? `${detail} · ${rule.status}` : detail,
archiveGroup: null,
archiveLabel: null,
protected: false,
protectionNote: null
}];
});
}

View File

@@ -36,6 +36,7 @@ export type CampaignMessagePreviewOverlayProps = {
raw?: string | null;
rawLabel?: string;
navigation?: CampaignMessagePreviewNavigation;
actions?: ReactNode;
closeLabel?: string;
onClose: () => void;
};
@@ -53,6 +54,7 @@ export default function CampaignMessagePreviewOverlay({
raw,
rawLabel = "i18n:govoplan-campaign.raw_mime.82c612d4",
navigation,
actions,
closeLabel = "i18n:govoplan-campaign.close.bbfa773e",
onClose
}: CampaignMessagePreviewOverlayProps) {
@@ -131,7 +133,10 @@ export default function CampaignMessagePreviewOverlay({
</details>
}
</div>
<footer className="modal-footer"><Button variant="primary" onClick={onClose}>{closeLabel}</Button></footer>
<footer className="modal-footer">
{actions && <div className="button-row compact-actions">{actions}</div>}
<Button variant="primary" onClick={onClose}>{closeLabel}</Button>
</footer>
</div>
</div>);
@@ -146,4 +151,4 @@ function isEditableTarget(target: EventTarget | null): boolean {
export type MessagePreviewAttachment = CampaignMessagePreviewAttachment;
export type MessagePreviewMetaItem = CampaignMessagePreviewMetaItem;
export type MessagePreviewNavigation = CampaignMessagePreviewNavigation;
export type MessagePreviewOverlayProps = CampaignMessagePreviewOverlayProps;
export type MessagePreviewOverlayProps = CampaignMessagePreviewOverlayProps;

View File

@@ -0,0 +1,53 @@
export type AttachmentPreviewFileLike = {
id: string;
display_path: string;
filename: string;
linked_to_campaign?: boolean;
};
export type AttachmentPreviewLike<T extends AttachmentPreviewFileLike> = {
rules: Array<{matches: T[]}>;
linkable_files?: T[];
};
export function attachmentPreviewMatchedFiles<T extends AttachmentPreviewFileLike>(
preview: AttachmentPreviewLike<T> | null
): T[] {
if (!preview) return [];
const byId = new Map<string, T>();
for (const rule of preview.rules) {
for (const file of rule.matches) {
const key = file.id || file.display_path;
if (!key) continue;
const existing = byId.get(key);
if (existing) {
byId.set(key, {
...existing,
linked_to_campaign: existing.linked_to_campaign !== false || file.linked_to_campaign !== false
});
} else {
byId.set(key, file);
}
}
}
return [...byId.values()].sort((left, right) => {
const linkOrder = Number(left.linked_to_campaign === false) - Number(right.linked_to_campaign === false);
if (linkOrder !== 0) return linkOrder;
return (left.display_path || left.filename).localeCompare(right.display_path || right.filename);
});
}
export function attachmentPreviewLinkableFiles<T extends AttachmentPreviewFileLike>(
preview: AttachmentPreviewLike<T> | null
): T[] {
if (!preview) return [];
const source = preview.linkable_files && preview.linkable_files.length > 0
? preview.linkable_files
: attachmentPreviewMatchedFiles(preview).filter((file) => file.linked_to_campaign === false);
const byId = new Map<string, T>();
for (const file of source) {
const key = file.id || file.display_path;
if (key) byId.set(key, file);
}
return [...byId.values()];
}