Skip to content

Commit

Permalink
fix: submission detail of each task's submission (#1324)
Browse files Browse the repository at this point in the history
* feat: submission detail of each task

* fix: updated submission detail endpoint and params

---------

Co-authored-by: sujanadh <[email protected]>
  • Loading branch information
Sujanadh and sujanadh authored Mar 5, 2024
1 parent 026c089 commit 3e82720
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
25 changes: 25 additions & 0 deletions src/backend/app/submissions/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,3 +820,28 @@ async def get_submission_by_task(
count = data.get("@odata.count", 0)

return submissions, count


async def get_submission_detail(
project: db_models.DbProject,
task_id: int,
submission_id: str,
db: Session,
):
"""Get the details of a submission.
Args:
project: The project object representing the project.
task_id: The ID of the task associated with the submission.
submission_id: The ID of the submission.
db: The database session.
Returns:
The details of the submission as a JSON object.
"""
odk_credentials = await project_deps.get_odk_credentials(db, project.id)
odk_form = get_odk_form(odk_credentials)
xform = f"{project.project_name_prefix}_task_{task_id}"
submission = odk_form.getSubmissions(project.odkid, xform, submission_id)

return json.loads(submission)
7 changes: 7 additions & 0 deletions src/backend/app/submissions/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ async def task_submissions(
project: db_models.DbProject = Depends(project_deps.get_project_by_id),
page: int = Query(1, ge=1),
limit: int = Query(13, le=100),
submission_id: Optional[str] = None,
submitted_by: Optional[str] = None,
review_state: Optional[str] = None,
submitted_date: Optional[str] = Query(
Expand Down Expand Up @@ -463,4 +464,10 @@ async def task_submissions(
results=data,
pagination=submission_schemas.PaginationInfo(**pagination.model_dump()),
)
if submission_id:
submission_detail = await submission_crud.get_submission_detail(
project, task_id, submission_id, db
)
response = submission_detail.get("value", [])[0]

return response
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ const SubmissionsTable = ({ toggleView }) => {
const [paginationPage, setPaginationPage] = useState<number>(1);
const [submittedBy, setSubmittedBy] = useState<string | null>(null);

const encodedTaskId = environment.encode(3468);

useEffect(() => {
let count = 0;
const filters = Object.keys(filter);
Expand Down Expand Up @@ -436,7 +434,7 @@ const SubmissionsTable = ({ toggleView }) => {
<AssetModules.VisibilityOutlinedIcon
className="fmtm-text-[#545454] hover:fmtm-text-primaryRed"
onClick={() => {
navigate(`/project/${encodedId}/tasks/${encodedTaskId}/submission/${row?.meta?.instanceID}`);
navigate(`/project/${encodedId}/tasks/${row?.phonenumber}/submission/${row?.meta?.instanceID}`);
}}
/>{' '}
<span className="fmtm-text-primaryRed fmtm-border-[1px] fmtm-border-primaryRed fmtm-mx-1"></span>{' '}
Expand Down
7 changes: 3 additions & 4 deletions src/frontend/src/views/SubmissionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const SubmissionDetails = () => {
const params = CoreModules.useParams();
const encodedProjectId = params.projectId;
const decodedProjectId = environment.decode(encodedProjectId);
const encodedTaskId = params.taskId;
const decodedTaskId = environment.decode(encodedTaskId);
const taskId = params.taskId;
const paramsInstanceId = params.instanceId;

const submissionDetails = useAppSelector((state) => state.submission.submissionDetails);
Expand All @@ -20,10 +19,10 @@ const SubmissionDetails = () => {
SubmissionService(
`${
import.meta.env.VITE_API_URL
}/central/submission?project_id=${decodedProjectId}&xmlFormId=${decodedTaskId}&submission_id=${paramsInstanceId}`,
}/submission/task_submissions/${decodedProjectId}?task_id=${taskId}&submission_id=${paramsInstanceId}`,
),
);
}, []);
}, [decodedProjectId, taskId, paramsInstanceId]);

function removeNullValues(obj) {
const newObj = {};
Expand Down

0 comments on commit 3e82720

Please sign in to comment.