48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { useState } from 'react';
|
|
import { Button } from '@/components/ui/Button';
|
|
import { SaveSourceFindingDialog } from '@/features/research/components/SaveFindingDialog';
|
|
import type { FindingDraftSource } from '@/features/research/services/findingSources';
|
|
|
|
export function SourceFindingAction({
|
|
source,
|
|
unavailable,
|
|
disabled,
|
|
onDirtyChange,
|
|
}: {
|
|
source: FindingDraftSource | null;
|
|
unavailable: string;
|
|
disabled?: boolean;
|
|
onDirtyChange: (dirty: boolean) => void;
|
|
}) {
|
|
const [snapshot, setSnapshot] = useState<FindingDraftSource | null>(null);
|
|
const eligible = source?.runs.some(run => run.metrics.length);
|
|
return (
|
|
<div className="space-y-2">
|
|
<Button
|
|
variant="outline"
|
|
disabled={disabled || !eligible}
|
|
onClick={() => {
|
|
if (source && eligible) {
|
|
setSnapshot(structuredClone(source));
|
|
}
|
|
}}
|
|
>
|
|
Save research finding
|
|
</Button>
|
|
{!eligible && (
|
|
<p className="text-sm">
|
|
{source
|
|
? 'No completed, comparable measurements are available to cite yet.'
|
|
: unavailable}
|
|
</p>
|
|
)}
|
|
{snapshot && (
|
|
<SaveSourceFindingDialog
|
|
source={snapshot}
|
|
onClose={() => setSnapshot(null)}
|
|
onDirtyChange={onDirtyChange}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|