Skip to content

Commit

Permalink
fix duplicate result display on canvas and page flow checkings
Browse files Browse the repository at this point in the history
  • Loading branch information
imda-amdlahir committed Feb 26, 2025
1 parent 1e128c9 commit 341a4d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,37 @@ function SelectedTestResults({ results }: SelectedTestResultProps) {
const [isExpanded, setIsExpanded] = useState(true);

return (
<div className="flex max-w-[200px] justify-start items-start pl-2">
<div className="flex max-w-[200px] flex-col items-start justify-start gap-2 pl-2">
<button
onClick={() => setIsExpanded(!isExpanded)}
className="flex items-center gap-1 text-gray-700 hover:text-gray-500"
>
{isExpanded ? <RiArrowDownSLine className="h-4 w-4" /> : <div className="flex items-center gap-1"><RiArrowRightSLine className="h-4 w-4" /><span className="text-[0.7rem] text-gray-500">Click to expand selected results</span></div>}
className="flex items-center gap-1 text-gray-700 hover:text-gray-500">
{isExpanded ? (
<RiArrowDownSLine className="h-4 w-4" />
) : (
<div className="flex items-center gap-1">
<RiArrowRightSLine className="h-4 w-4" />
<span className="text-[0.7rem] text-gray-500">
Click to expand selected results
</span>
</div>
)}
</button>
{isExpanded ? results.map(result => (
<div className="flex flex-col max-w-[200px] pl-2" key={`${result.gid}-${result.cid}-${result.created_at}`}>
<span className="text-[0.75rem] font-medium text-gray-900 break-words">
{result.name}
</span>
<span className="text-[0.7rem] text-gray-500">
{new Date(result.created_at).toLocaleString()}
</span>
</div>
)) : null}
{isExpanded
? results.map((result) => (
<div
className="flex max-w-[200px] flex-col pl-2"
key={`${result.gid}-${result.cid}-${result.created_at}`}>
<span className="break-words text-[0.75rem] font-medium text-gray-900">
{result.name}
</span>
<span className="text-[0.7rem] text-gray-500">
{new Date(result.created_at).toLocaleString()}
</span>
</div>
))
: null}
</div>
);
}

export { SelectedTestResults };
export { SelectedTestResults };
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ function TestResultsDrawer(props: TestResultsDrawerProps) {
{selectedTestResults.length > 0 ? (
<SelectedTestResults results={selectedTestResults} />
) : null}
{selectedTestResults.length > 0 ? (
<SelectedTestResults results={selectedTestResults} />
) : null}
</div>
<DrawerContent className="sm:max-w-lg">
<DrawerHeader>
Expand Down
2 changes: 1 addition & 1 deletion aiverify-portal/app/canvas/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function CanvasPage(props: UrlSearchParams) {
const { flow, projectId, testResultIds } = searchParams;
const result = await fetchProjects({ ids: [projectId] });

if (!projectId || !flow || 'message' in result) {
if (!projectId || flow == undefined || 'message' in result) {
notFound();
}

Expand Down
8 changes: 5 additions & 3 deletions aiverify-portal/app/project/actions/createProject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use server';
import { redirect } from 'next/navigation';
import { ZodError, z } from 'zod';
import { ErrorWithMessage } from '@/app/errorTypes';
import type { ProjectFormValues } from '@/app/project/types';
import { FormState, ProjectInfo } from '@/app/types';
import { UserFlows } from '@/app/userFlowsEnum';
import { processResponse } from '@/lib/utils/fetchRequestHelpers';
import { formatZodSchemaErrors } from '@/lib/utils/formatZodSchemaErrors';

Expand All @@ -14,7 +14,7 @@ const projectFormSchema = z.object({
company: z.string(),
});

const endpoint = 'http://localhost:4000/projects';
const endpoint = `${process.env.APIGW_HOST}/projects`;

export async function createProject(
prevState: FormState<ProjectFormValues>,
Expand Down Expand Up @@ -56,5 +56,7 @@ export async function createProject(
};
}

redirect(`/templates?projectId=${result.data.id}`);
redirect(
`/templates?flow=${UserFlows.NewProject}&projectId=${result.data.id}`
);
}
9 changes: 7 additions & 2 deletions aiverify-portal/app/templates/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ type UrlSearchParams = {
export default async function TemplatesPage(props: UrlSearchParams) {
const params = await props.searchParams;
const { projectId, flow } = params;
if (projectId == undefined) {
if (flow == undefined) {
console.log('flow id is required');
notFound();
}

const result = await fetchProjects({ ids: [projectId] });
if (flow == UserFlows.NewProject && projectId == undefined) {
notFound();
}

const result = await fetchProjects({ ids: [projectId as string] });
if ('message' in result) {
notFound();
}
Expand Down

0 comments on commit 341a4d4

Please sign in to comment.