feat(export): add removeId option to ExportDialog

Add configurable removeId checkbox (default: true) for controlling whether to include id field in exported API code. Persists to localStorage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
xiongxiao
2026-03-19 01:14:13 +08:00
committed by cnb
parent e19b1811d8
commit fa527192c9

View File

@@ -15,6 +15,7 @@ type CreateOptions = {
removeViewItem?: boolean; removeViewItem?: boolean;
before?: string; before?: string;
after?: string; after?: string;
removeId?: boolean;
} }
export const ExportDialog = () => { export const ExportDialog = () => {
const { showExportDialog, setShowExportDialog, exportRoutes } = useStudioStore( const { showExportDialog, setShowExportDialog, exportRoutes } = useStudioStore(
@@ -45,6 +46,12 @@ export const ExportDialog = () => {
} }
return false; return false;
}); });
const [removeId, setRemoveId] = useState(() => {
if (typeof window !== 'undefined') {
return localStorage.getItem('exportRemoveId') !== 'false';
}
return true;
});
// 保存配置到 localStorage // 保存配置到 localStorage
useEffect(() => { useEffect(() => {
@@ -59,6 +66,10 @@ export const ExportDialog = () => {
localStorage.setItem('exportRemoveViewItem', String(removeViewItem)); localStorage.setItem('exportRemoveViewItem', String(removeViewItem));
}, [removeViewItem]); }, [removeViewItem]);
useEffect(() => {
localStorage.setItem('exportRemoveId', String(removeId));
}, [removeId]);
const code = useMemo(() => { const code = useMemo(() => {
if (!exportRoutes) return ''; if (!exportRoutes) return '';
let routeInfo = exportRoutes.map(route => pick(route, ['path', 'key', 'id', 'description', 'metadata'])); let routeInfo = exportRoutes.map(route => pick(route, ['path', 'key', 'id', 'description', 'metadata']));
@@ -66,10 +77,11 @@ export const ExportDialog = () => {
before, before,
after, after,
removeViewItem, removeViewItem,
removeId,
}; };
const query = createQueryByRoutes(cloneDeep(routeInfo as any), options); const query = createQueryByRoutes(cloneDeep(routeInfo as any), options);
return query; return query;
}, [exportRoutes, before, after, removeViewItem]); }, [exportRoutes, before, after, removeViewItem, removeId]);
const handleCopy = async () => { const handleCopy = async () => {
try { try {
@@ -91,7 +103,7 @@ export const ExportDialog = () => {
<div className="flex gap-4 w-full overflow-hidden"> <div className="flex gap-4 w-full overflow-hidden">
<div className="w-90 shrink-0 space-y-4"> <div className="w-90 shrink-0 space-y-4">
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="before">Before (import)</Label> <Label htmlFor="before"> (import)</Label>
<Textarea <Textarea
id="before" id="before"
value={before} value={before}
@@ -101,7 +113,7 @@ export const ExportDialog = () => {
/> />
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="after">After (export)</Label> <Label htmlFor="after"> (export)</Label>
<Textarea <Textarea
id="after" id="after"
value={after} value={after}
@@ -119,7 +131,18 @@ export const ExportDialog = () => {
setRemoveViewItem(value); setRemoveViewItem(value);
}} }}
/> />
<Label htmlFor="removeViewItem">Remove View Item</Label> <Label htmlFor="removeViewItem"></Label>
</div>
<div className="flex items-center gap-2">
<Checkbox
id="removeId"
checked={removeId}
onCheckedChange={(checked) => {
const value = checked === true;
setRemoveId(value);
}}
/>
<Label htmlFor="removeId"> ID</Label>
</div> </div>
</div> </div>
<div className="flex-1 p-4 border border-gray-300 rounded-md bg-gray-50"> <div className="flex-1 p-4 border border-gray-300 rounded-md bg-gray-50">