Skip to content

Commit

Permalink
Merge branch 'develop' into bug/e2e-minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-jameson authored Nov 15, 2024
2 parents b845440 + 5500be8 commit ec166d1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 54 deletions.
31 changes: 29 additions & 2 deletions tdrs-backend/tdpservice/data_files/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework import serializers
from tdpservice.parsers.models import ParserError
from tdpservice.data_files.errors import ImmutabilityError
from tdpservice.data_files.models import DataFile
from tdpservice.data_files.models import DataFile, ReparseFileMeta
from tdpservice.data_files.validators import (
validate_file_extension,
validate_file_infection,
Expand All @@ -12,8 +12,26 @@
from tdpservice.stts.models import STT
from tdpservice.users.models import User
from tdpservice.parsers.serializers import DataFileSummarySerializer


logger = logging.getLogger(__name__)


class ReparseFileMetaSerializer(serializers.ModelSerializer):
"""Serializer for ReparseFileMeta class."""

class Meta:
"""Meta class."""

model = ReparseFileMeta
fields = [
'finished',
'success',
'started_at',
'finished_at',
]


class DataFileSerializer(serializers.ModelSerializer):
"""Serializer for Data files."""

Expand All @@ -23,6 +41,7 @@ class DataFileSerializer(serializers.ModelSerializer):
ssp = serializers.BooleanField(write_only=True)
has_error = serializers.SerializerMethodField()
summary = DataFileSummarySerializer(many=False, read_only=True)
latest_reparse_file_meta = serializers.SerializerMethodField()

class Meta:
"""Metadata."""
Expand All @@ -46,7 +65,8 @@ class Meta:
's3_location',
's3_versioning_id',
'has_error',
'summary'
'summary',
'latest_reparse_file_meta',
]

read_only_fields = ("version",)
Expand All @@ -56,6 +76,13 @@ def get_has_error(self, obj):
parser_errors = ParserError.objects.filter(file=obj.id)
return len(parser_errors) > 0

def get_latest_reparse_file_meta(self, instance):
"""Return related reparse_file_metas, ordered by finished_at decending."""
reparse_file_metas = instance.reparse_file_metas.all().order_by('-finished_at')
if reparse_file_metas.count() > 0:
return ReparseFileMetaSerializer(reparse_file_metas.first(), many=False, read_only=True).data
return None

def create(self, validated_data):
"""Create a new entry with a new version number."""
ssp = validated_data.pop('ssp')
Expand Down
1 change: 1 addition & 0 deletions tdrs-backend/tdpservice/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import logging.handlers
import os
from django.utils.dateparse import parse_datetime
from distutils.util import strtobool
from os.path import join
from typing import Any, Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { useDispatch } from 'react-redux'
import {
SubmissionSummaryStatusIcon,
formatDate,
hasReparsed,
getReprocessedDate,
downloadFile,
downloadErrorReport,
getErrorReportStatus,
} from './helpers'

const MonthSubRow = ({ data }) =>
Expand All @@ -24,17 +26,13 @@ const MonthSubRow = ({ data }) =>

const CaseAggregatesRow = ({ file }) => {
const dispatch = useDispatch()
const errorFileName = `${file.year}-${file.quarter}-${file.section}`

return (
<>
<tr>
<th scope="rowgroup" rowSpan={3}>
{formatDate(file.createdAt)}
</th>

<th scope="rowgroup" rowSpan={3}>
{file.submittedBy}
{formatDate(file.createdAt) + ' by ' + file.submittedBy}
{hasReparsed(file) && <></>}
</th>

<th scope="rowgroup" rowSpan={3}>
Expand Down Expand Up @@ -64,22 +62,7 @@ const CaseAggregatesRow = ({ file }) => {
</th>

<th scope="rowgroup" rowSpan={3}>
{file.summary &&
file.summary.status &&
file.summary.status !== 'Pending' ? (
file.hasError > 0 ? (
<button
className="section-download"
onClick={() => downloadErrorReport(file, errorFileName)}
>
{errorFileName}.xlsx
</button>
) : (
'No Errors'
)
) : (
'Pending'
)}
{getErrorReportStatus(file)}
</th>
</tr>
<tr>
Expand All @@ -99,9 +82,6 @@ export const CaseAggregatesTable = ({ files }) => (
<th scope="col" rowSpan={2}>
Submitted On
</th>
<th scope="col" rowSpan={2}>
Submitted By
</th>
<th scope="col" rowSpan={2}>
File Name
</th>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { useDispatch, useSelector } from 'react-redux'
import { fileUploadSections } from '../../reducers/reports'
import Paginator from '../Paginator'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { useDispatch } from 'react-redux'
import {
SubmissionSummaryStatusIcon,
formatDate,
hasReparsed,
getReprocessedDate,
downloadFile,
downloadErrorReport,
getErrorReportStatus,
} from './helpers'

const MonthSubRow = ({ data }) =>
Expand All @@ -22,17 +24,13 @@ const MonthSubRow = ({ data }) =>

const TotalAggregatesRow = ({ file }) => {
const dispatch = useDispatch()
const errorFileName = `${file.year}-${file.quarter}-${file.section}`

return (
<>
<tr>
<th scope="rowgroup" rowSpan={3}>
{formatDate(file.createdAt)}
</th>

<th scope="rowgroup" rowSpan={3}>
{file.submittedBy}
{formatDate(file.createdAt) + ' by ' + file.submittedBy}
{hasReparsed(file) && <></>}
</th>

<th scope="rowgroup" rowSpan={3}>
Expand All @@ -58,22 +56,7 @@ const TotalAggregatesRow = ({ file }) => {
</th>

<th scope="rowgroup" rowSpan={3}>
{file.summary &&
file.summary.status &&
file.summary.status !== 'Pending' ? (
file.hasError > 0 ? (
<button
className="section-download"
onClick={() => downloadErrorReport(file, errorFileName)}
>
{errorFileName}.xlsx
</button>
) : (
'No Errors'
)
) : (
'Pending'
)}
{getErrorReportStatus(file)}
</th>
</tr>
<tr>
Expand All @@ -93,9 +76,6 @@ export const TotalAggregatesTable = ({ files }) => (
<th scope="col" rowSpan={2}>
Submitted On
</th>
<th scope="col" rowSpan={2}>
Submitted By
</th>
<th scope="col" rowSpan={2}>
File Name
</th>
Expand Down
30 changes: 30 additions & 0 deletions tdrs-frontend/src/components/SubmissionHistory/helpers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ export const downloadErrorReport = async (file, reportName) => {
console.log(error)
}
}
export const hasReparsed = (f) =>
f.latest_reparse_file_meta &&
f.latest_reparse_file_meta.finished_at &&
f.latest_reparse_file_meta.finished_at !== null

export const getReprocessedDate = (f) => f.latest_reparse_file_meta.finished_at

export const getErrorReportStatus = (file) => {
if (
file.summary &&
file.summary.status &&
file.summary.status !== 'Pending'
) {
const errorFileName = `${file.year}-${file.quarter}-${file.section}`
if (file.hasError) {
return (
<button
className="section-download"
onClick={() => downloadErrorReport(file, errorFileName)}
>
{errorFileName}.xlsx
</button>
)
} else {
return 'No Errors'
}
} else {
return 'Pending'
}
}

export const SubmissionSummaryStatusIcon = ({ status }) => {
let icon = null
Expand Down
1 change: 1 addition & 0 deletions tdrs-frontend/src/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const serializeApiDataFile = (dataFile) => ({
submittedBy: dataFile.submitted_by,
hasError: dataFile.has_error,
summary: dataFile.summary,
latest_reparse_file_meta: dataFile.latest_reparse_file_meta,
})

const initialState = {
Expand Down

0 comments on commit ec166d1

Please sign in to comment.