- export now accepts includeEnvironment and credentialIds query params - output is a YAML stream with comment-delimited environment, credential, and scenario sections - scenario entity includes credentials array with alias mappings - import accepts both old single-object and new array format, upserts envs/creds before linking - new ExportScenarioModal with env and per-credential checkboxes replaces direct download
103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { X, Upload } from 'lucide-react';
|
|
import { Modal, Button, UuidBadge } from '../../ui';
|
|
import type { Scenario, ScenarioCredential } from '../../api';
|
|
import styles from './ExportScenarioModal.module.css';
|
|
|
|
export interface ExportScenarioModalProps {
|
|
open: boolean;
|
|
scenario: Scenario | null;
|
|
scenarioCredentials: ScenarioCredential[];
|
|
environment: Pick<{ id: string; name: string }, 'id' | 'name'> | null;
|
|
includeEnvironment: boolean;
|
|
onIncludeEnvironmentChange: (v: boolean) => void;
|
|
includedCredentialIds: Set<string>;
|
|
onCredentialToggle: (id: string, checked: boolean) => void;
|
|
onClose: () => void;
|
|
onExport: () => void;
|
|
isExporting: boolean;
|
|
}
|
|
|
|
export function ExportScenarioModal({
|
|
open,
|
|
scenario,
|
|
scenarioCredentials,
|
|
environment,
|
|
includeEnvironment,
|
|
onIncludeEnvironmentChange,
|
|
includedCredentialIds,
|
|
onCredentialToggle,
|
|
onClose,
|
|
onExport,
|
|
isExporting,
|
|
}: ExportScenarioModalProps) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
title={t('scenarios.export_modal_title')}
|
|
onClose={() => !isExporting && onClose()}
|
|
footer={
|
|
<>
|
|
<Button variant="secondary" onClick={onClose} disabled={isExporting}>
|
|
<X size={14} />
|
|
{t('common.button_cancel')}
|
|
</Button>
|
|
<Button variant="primary" onClick={onExport} disabled={isExporting}>
|
|
<Upload size={14} />
|
|
{t('scenarios.action_export')}
|
|
</Button>
|
|
</>
|
|
}
|
|
>
|
|
{scenario && (
|
|
<div className={styles.exportModal}>
|
|
<div className={styles.scenarioMeta}>
|
|
<div className={styles.metaRow}>
|
|
<span className={styles.metaLabel}>{t('scenarios.field_name')}</span>
|
|
<span className={styles.metaValue}>{scenario.name}</span>
|
|
</div>
|
|
<div className={styles.metaRow}>
|
|
<span className={styles.metaLabel}>{t('scenarios.field_id')}</span>
|
|
<span className={styles.metaValue}>
|
|
<UuidBadge id={scenario.id} />
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{environment && (
|
|
<div className={styles.section}>
|
|
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_environment')}</h4>
|
|
<label className={styles.checkboxRow}>
|
|
<input
|
|
type="checkbox"
|
|
checked={includeEnvironment}
|
|
onChange={(e) => onIncludeEnvironmentChange(e.target.checked)}
|
|
/>
|
|
<span>{environment.name}</span>
|
|
</label>
|
|
</div>
|
|
)}
|
|
|
|
{scenarioCredentials.length > 0 && (
|
|
<div className={styles.section}>
|
|
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_credentials')}</h4>
|
|
{scenarioCredentials.map((sc) => (
|
|
<label key={sc.credentialId} className={styles.checkboxRow}>
|
|
<input
|
|
type="checkbox"
|
|
checked={includedCredentialIds.has(sc.credentialId)}
|
|
onChange={(e) => onCredentialToggle(sc.credentialId, e.target.checked)}
|
|
/>
|
|
<span>{sc.credential?.name ?? sc.alias}</span>
|
|
</label>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</Modal>
|
|
);
|
|
}
|