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

Refine submission table #2045

Merged
merged 3 commits into from
Jan 1, 2025
Merged
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
133 changes: 72 additions & 61 deletions src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import React, { useEffect, useState } from 'react';
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import { format } from 'date-fns';
import { Tooltip } from '@mui/material';
import { Loader2 } from 'lucide-react';

import AssetModules from '@/shared/AssetModules.js';
import { CustomSelect } from '@/components/common/Select.js';
import CoreModules from '@/shared/CoreModules.js';
import windowDimention from '@/hooks/WindowDimension';

import Button from '@/components/common/Button';
import { Modal } from '@/components/common/Modal';
import { CustomSelect } from '@/components/common/Select.js';
import CustomDatePicker from '@/components/common/CustomDatePicker';
import Table, { TableHeader } from '@/components/common/CustomTable';
import { SubmissionFormFieldsService, SubmissionTableService } from '@/api/SubmissionService';
import CoreModules from '@/shared/CoreModules.js';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/common/Dropdown';
import { SubmissionsTableSkeletonLoader } from '@/components/ProjectSubmissions/ProjectSubmissionsSkeletonLoader.js';
import { Loader2 } from 'lucide-react';
import { SubmissionActions } from '@/store/slices/SubmissionSlice';
import UpdateReviewStatusModal from '@/components/ProjectSubmissions/UpdateReviewStatusModal';
import { reviewStateData } from '@/constants/projectSubmissionsConstants';
import CustomDatePicker from '@/components/common/CustomDatePicker';
import { format } from 'date-fns';
import Button from '@/components/common/Button';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/common/Dropdown';

import { useAppSelector } from '@/types/reduxTypes';
import { task_state, task_event, entity_state } from '@/types/enums';
import { filterType } from '@/store/types/ISubmissions';
import { SubmissionActions } from '@/store/slices/SubmissionSlice';

import { CreateTaskEvent } from '@/api/TaskEvent';
import { ConvertXMLToJOSM, getDownloadProjectSubmission } from '@/api/task';
import { Modal } from '@/components/common/Modal';
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import { SubmissionFormFieldsService, SubmissionTableService } from '@/api/SubmissionService';

import filterParams from '@/utilfunctions/filterParams';
import UpdateReviewStatusModal from '@/components/ProjectSubmissions/UpdateReviewStatusModal';
import { useAppSelector } from '@/types/reduxTypes';
import { camelToFlat } from '@/utilfunctions/commonUtils';
import useDocumentTitle from '@/utilfunctions/useDocumentTitle';
import { CreateTaskEvent } from '@/api/TaskEvent';
import { filterType } from '@/store/types/ISubmissions';
import { task_state, task_event } from '@/types/enums';

const SubmissionsTable = ({ toggleView }) => {
useDocumentTitle('Submission Table');
Expand Down Expand Up @@ -79,27 +85,24 @@ const SubmissionsTable = ({ toggleView }) => {
setNumberOfFilters(count);
}, [filter]);

useEffect(() => {
let count = 0;
const filters = Object.keys(filter);
filters?.map((fltr) => {
if (filter[fltr]) {
count = count + 1;
const updatedSubmissionFormFields = submissionFormFields
//filter necessary fields only
?.filter(
(formField) =>
formField?.path.startsWith('/survey_questions') ||
['/start', '/end', '/username', '/task_id', '/status'].includes(formField?.path),
)
// convert path to dot notation & update name
?.map((formField) => {
if (formField.type !== 'structure') {
return {
...formField,
path: formField?.path.slice(1).replace(/\//g, '.'),
name: formField?.name.charAt(0).toUpperCase() + formField?.name.slice(1).replace(/_/g, ' '),
};
}
return null;
});
setNumberOfFilters(count);
}, [filter]);

const updatedSubmissionFormFields = submissionFormFields?.map((formField) => {
if (formField.type !== 'structure') {
return {
...formField,
path: formField?.path.slice(1).replace(/\//g, '.'),
name: formField?.name.charAt(0).toUpperCase() + formField?.name.slice(1).replace(/_/g, ' '),
};
}
return null;
});

useEffect(() => {
dispatch(
Expand Down Expand Up @@ -169,6 +172,8 @@ const SubmissionsTable = ({ toggleView }) => {
if (path === 'start' || path === 'end') {
// start & end date is static
value = `${value[item]?.split('T')[0]} ${value[item]?.split('T')[1]}`;
} else if (path === 'status') {
value = entity_state[value[item]].replaceAll('_', ' ');
} else if (
value &&
value[item] &&
Expand All @@ -185,7 +190,7 @@ const SubmissionsTable = ({ toggleView }) => {
value = value?.[item];
}
});
return value ? (typeof value === 'object' ? '-' : value) : '';
return value ? (typeof value === 'object' ? '-' : value) : '-';
}

const uploadToJOSM = () => {
Expand Down Expand Up @@ -247,7 +252,7 @@ const SubmissionsTable = ({ toggleView }) => {
</div>
}
open={!!josmEditorError}
onOpenChange={(value) => {
onOpenChange={() => {
dispatch(CoreModules.TaskActions.SetJosmEditorError(null));
}}
/>
Expand Down Expand Up @@ -446,14 +451,16 @@ const SubmissionsTable = ({ toggleView }) => {
dataField={field?.name}
headerClassName="codeHeader"
rowClassName="codeRow"
dataFormat={(row) => (
<div
className="fmtm-w-[7rem] fmtm-overflow-hidden fmtm-truncate"
title={getValueByPath(row, field?.path)}
>
<span className="fmtm-text-[15px]">{getValueByPath(row, field?.path)}</span>
</div>
)}
dataFormat={(row) => {
const value = getValueByPath(row, field?.path);
return (
<Tooltip arrow placement="bottom-start" title={value}>
<div className="fmtm-w-[7rem] fmtm-overflow-hidden fmtm-truncate">
<span className="fmtm-text-[15px]">{value}</span>
</div>
</Tooltip>
);
}}
/>
);
}
Expand All @@ -468,24 +475,28 @@ const SubmissionsTable = ({ toggleView }) => {
return (
<div className="fmtm-w-[5rem] fmtm-overflow-hidden fmtm-truncate fmtm-text-center">
<Link to={`/project-submissions/${projectId}/tasks/${taskUid}/submission/${row?.meta?.instanceID}`}>
<AssetModules.VisibilityOutlinedIcon className="fmtm-text-[#545454] hover:fmtm-text-primaryRed" />
<Tooltip arrow placement="bottom" title="Validate Submission">
<AssetModules.VisibilityOutlinedIcon className="fmtm-text-[#545454] hover:fmtm-text-primaryRed" />
</Tooltip>
</Link>
<span className="fmtm-text-primaryRed fmtm-border-[1px] fmtm-border-primaryRed fmtm-mx-1"></span>{' '}
<AssetModules.CheckOutlinedIcon
className="fmtm-text-[#545454] hover:fmtm-text-primaryRed"
onClick={() => {
dispatch(
SubmissionActions.SetUpdateReviewStatusModal({
toggleModalStatus: true,
instanceId: row?.meta?.instanceID,
taskId: row?.task_id,
projectId: projectId,
reviewState: row?.__system?.reviewState,
taskUid: taskUid,
}),
);
}}
/>
<Tooltip arrow placement="bottom" title="Update Review Status">
<AssetModules.CheckOutlinedIcon
className="fmtm-text-[#545454] hover:fmtm-text-primaryRed"
onClick={() => {
dispatch(
SubmissionActions.SetUpdateReviewStatusModal({
toggleModalStatus: true,
instanceId: row?.meta?.instanceID,
taskId: row?.task_id,
projectId: projectId,
reviewState: row?.__system?.reviewState,
taskUid: taskUid,
}),
);
}}
/>
</Tooltip>
</div>
);
}}
Expand Down
Loading