feat: update SearchForm to use project display names
Add Project interface with name and displayName fields to support project aliases. Update SWR hook to type projects as Project[]. Display project.displayName in dropdown while using project.name as the option value for API compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
// app/download/SearchForm.tsx
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
@@ -13,6 +12,11 @@ const fetcher = async (url: string) => {
|
|||||||
return res.json();
|
return res.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface Project {
|
||||||
|
name: string;
|
||||||
|
displayName: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface SearchFormProps {
|
interface SearchFormProps {
|
||||||
onSearch: (project: string, version: string, commitId: string) => void;
|
onSearch: (project: string, version: string, commitId: string) => void;
|
||||||
}
|
}
|
||||||
@@ -23,13 +27,13 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
|||||||
const [commitId, setCommitId] = useState('');
|
const [commitId, setCommitId] = useState('');
|
||||||
|
|
||||||
// 获取项目列表
|
// 获取项目列表
|
||||||
const { data: projects, isLoading: loadingProjects } = useSWR(
|
const { data: projects, isLoading: loadingProjects } = useSWR<Project[]>(
|
||||||
'/api/projects',
|
'/api/projects',
|
||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取版本列表
|
// 获取版本列表
|
||||||
const { data: versions, isLoading: loadingVersions } = useSWR(
|
const { data: versions, isLoading: loadingVersions } = useSWR<string[]>(
|
||||||
selectedProject ? `/api/versions?project=${selectedProject}` : null,
|
selectedProject ? `/api/versions?project=${selectedProject}` : null,
|
||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
@@ -61,9 +65,9 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
|||||||
{loadingProjects ? (
|
{loadingProjects ? (
|
||||||
<option disabled>加载中...</option>
|
<option disabled>加载中...</option>
|
||||||
) : (
|
) : (
|
||||||
projects?.map((project: string) => (
|
projects?.map((project) => (
|
||||||
<option key={project} value={project}>
|
<option key={project.name} value={project.name}>
|
||||||
{project}
|
{project.displayName}
|
||||||
</option>
|
</option>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
@@ -86,7 +90,7 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
|||||||
{loadingVersions ? (
|
{loadingVersions ? (
|
||||||
<option disabled>加载中...</option>
|
<option disabled>加载中...</option>
|
||||||
) : (
|
) : (
|
||||||
versions?.map((version: string) => (
|
versions?.map((version) => (
|
||||||
<option key={version} value={version}>
|
<option key={version} value={version}>
|
||||||
{formatVersion(version)}
|
{formatVersion(version)}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user