Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed when to show data table #1081

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/containers/admin/data-upload-error/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ const DataUploadError: React.FC<DataUploadErrorProps> = ({ task }) => {
>
<div className="flex w-full space-x-6 items-center">
<div className="space-y-1.5 flex-1">
{task?.status === 'processing' && (
<>
<h3>Upload in progress</h3>
<p className="text-gray-500">
There is a uploading task in progress created at{' '}
{format(new Date(task.createdAt), 'MMM d, yyyy HH:mm z')}.
</p>
</>
)}

{task?.status === 'completed' && task?.errors.length === 0 && (
<>
<h3>Upload completed</h3>
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const useLasTask = () => {
},
);

return { ...tasks, data: tasks?.data?.data?.[0] };
return { ...tasks, data: tasks?.data?.data?.[0] } as UseQueryResult<TaskAPIResponse>;
};

export function useTask(
Expand Down
7 changes: 3 additions & 4 deletions client/src/pages/data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react';
import Head from 'next/head';

import { useSourcingLocations } from 'hooks/sourcing-locations';
Expand All @@ -19,7 +20,7 @@ const AdminDataPage: React.FC = () => {
// Getting last task to check if there is a processing task
const { data: lastTask } = useLasTask();

const thereIsData = data?.meta?.totalItems > 0;
const thereIsData = useMemo(() => data?.meta?.totalItems > 0, [data?.meta?.totalItems]);

return (
<AdminLayout
Expand All @@ -45,9 +46,7 @@ const AdminDataPage: React.FC = () => {
)}

{/* Content when empty, or upload is processing or failed */}
{isFetched && (lastTask?.status === 'processing' || !thereIsData) && (
<AdminDataUploader task={lastTask} />
)}
{isFetched && !thereIsData && <AdminDataUploader task={lastTask} />}

{/* Content when data and upload is completed */}
{isFetched && thereIsData && <AdminDataTable task={lastTask} />}
Expand Down
Loading