Skip to content

Commit

Permalink
fix(projects): the home page should direct you to the projects page i…
Browse files Browse the repository at this point in the history
…f there are multiple projects with data (#2586)
  • Loading branch information
mikeldking authored Mar 14, 2024
1 parent 121f904 commit ced4e75
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/src/pages/home/homeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ export async function homeLoader(_args: LoaderFunctionArgs) {
if (data?.functionality.modelInferences) {
return redirect("/model");
} else if (data?.projects.edges?.length) {
// Detect if there is only a single project with data. If that's the case, redirect to that project
let numProjectsWithData = 0,
projectIdWithData = null;
for (const { project } of data.projects.edges) {
if (project.endTime != null) {
return redirect(`/projects/${project.id}`);
numProjectsWithData++;
projectIdWithData = project.id;
}
}
if (numProjectsWithData > 1) {
// There are multiple projects with data, redirect to projects
return redirect("/projects");
} else if (numProjectsWithData === 1 && projectIdWithData != null) {
// There is only one project with data, redirect to that project
return redirect(`/projects/${projectIdWithData}`);
}
// Fallback to the default project
const projectId = data?.projects.edges[0].project.id;
return redirect(`/projects/${projectId}`);
} else {
Expand Down

0 comments on commit ced4e75

Please sign in to comment.