Skip to content

Commit

Permalink
Merge pull request #171 from jadmsaadaot/SUBMIT-task#175-B
Browse files Browse the repository at this point in the history
Fix display of internal staff doc table
  • Loading branch information
jadmsaadaot authored Nov 19, 2024
2 parents 94479a0 + 602be47 commit 859889c
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 77 deletions.
7 changes: 1 addition & 6 deletions submit-api/src/submit_api/schemas/internal_staff_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class Meta: # pylint: disable=too-few-public-methods
type = fields.Enum(data_key="type", enum=InternalStaffDocumentType)
item_id = fields.Int(data_key="item_id")
created_date = fields.DateTime(data_key="created_date")
created_by = fields.Method('get_created_by')

@classmethod
def get_created_by(cls, obj):
"""Get created by."""
return obj.created_by_user.full_name if obj.created_by_user else None
created_by = fields.Str(data_key="created_by")


class PostInternalStaffDocument(Schema):
Expand Down
2 changes: 1 addition & 1 deletion submit-api/src/submit_api/schemas/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Meta: # pylint: disable=too-few-public-methods
def get_days_since_submission(self, obj):
"""Get days since submission."""
if obj.submitted_on:
return (datetime.now() - obj.submitted_on).days
return (datetime.now().date() - obj.submitted_on.date()).days
return None

def get_meta(self, obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from submit_api.exceptions import ResourceNotFoundError
from submit_api.models import Item
from submit_api.models.internal_staff_document import InternalStaffDocument as InternalStaffDocumentModel
from submit_api.utils.token_info import TokenInfo


class InternalStaffDocumentService:
Expand All @@ -34,6 +35,7 @@ def create_internal_staff_document(cls, submission_item_id, data):
url=data.get("url"),
type=data.get("type"),
item_id=submission_item_id,
created_by=TokenInfo.get_id(),
)
internal_staff_document.save()
return internal_staff_document
3 changes: 2 additions & 1 deletion submit-api/src/submit_api/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def allowedorigins():
allowedcors = []
if _allowedcors and ',' in _allowedcors:
for entry in re.split(',', _allowedcors):
allowedcors.append(entry)
if entry:
allowedcors.append(entry)
return allowedcors


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ProponentTableRow({ subPackage }: ProjectRowProps) {
<PackageStatusChipStack status={subPackage.status} />
</StyledProjectTableCell>
</StyledProjectTableRow>
<EmptyRow />
<EmptyRow colSpan={4} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function StaffTableRow({ submissionPackage }: ProjectRowProps) {
<PackageStatusChipStack status={status} />
</StyledProjectTableCell>
</StyledProjectTableRow>
<EmptyRow />
<EmptyRow colSpan={7} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const StyledProjectTableRow = styled(TableRow)(() => ({
"&:hover": {
backgroundColor: BCDesignTokens.surfaceColorMenusHover,
},
cursor: "pointer",
}));

export const StyledProjectTableCell = styled(TableCell)(() => ({
Expand Down
5 changes: 2 additions & 3 deletions submit-web/src/components/Submission/DocumentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function DocumentRow({ documentSubmission }: DocumentRowProps) {
};
return (
<TableRow>
<StyledTableCell colSpan={2}>
<StyledTableCell>
<Typography
variant="body1"
color="inherit"
Expand All @@ -46,8 +46,7 @@ export default function DocumentRow({ documentSubmission }: DocumentRowProps) {
</StyledTableCell>
<StyledTableCell align="right">{submitted_by || ""}</StyledTableCell>
<StyledTableCell align="right">{version}</StyledTableCell>
<StyledTableCell align="right"></StyledTableCell>
<StyledTableCell align="right"></StyledTableCell>
<StyledTableCell align="right" colSpan={2}></StyledTableCell>
</TableRow>
);
}
45 changes: 9 additions & 36 deletions submit-web/src/components/Submission/ItemsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ import {
Typography,
} from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import TableSortLabel from "@mui/material/TableSortLabel";
import { useState } from "react";
import { Order } from "../Shared/Table/utils";
import SwapVertIcon from "@mui/icons-material/SwapVert";
import SubmissionItemTableRow from "./SubmissionItemTableRow";
import {
SUBMISSION_ITEM_METHOD,
SubmissionItem,
} from "@/models/SubmissionItem";
import { SubmissionItemTableRow as SubmissionItemTableRowType } from "./types";
import { StyledTableHeadCell } from "../Shared/Table/common";
import { SUBMISSION_STATUS, SUBMISSION_TYPE } from "@/models/Submission";
import { usePackageTableStore } from "./packageTableStore";
Expand All @@ -31,15 +26,7 @@ export default function ItemsTable({
}: {
submissionItems: Array<SubmissionItem>;
}) {
const [order, setOrder] = useState<Order>("asc");
const [orderBy, setOrderBy] =
useState<keyof SubmissionItemTableRowType>("name");
const { userType } = useAccount();
const handleRequestSort = (property: keyof SubmissionItemTableRowType) => {
const isAsc = orderBy === property && order === "asc";
setOrder(isAsc ? "desc" : "asc");
setOrderBy(property);
};

const { isValidating } = usePackageTableStore();

Expand Down Expand Up @@ -71,33 +58,18 @@ export default function ItemsTable({
}}
>
<TableRow>
<StyledTableHeadCell colSpan={2}>
<TableSortLabel
active={orderBy === "name"}
direction={orderBy === "name" ? order : "asc"}
onClick={() => handleRequestSort("name")}
IconComponent={SwapVertIcon}
<StyledTableHeadCell>
<Typography
variant="body2"
sx={{
".MuiTableSortLabel-icon": {
color: `${BCDesignTokens.themeGray70} !important`,
"&:hover": {
color: "#EDEBE9 !important",
},
color: BCDesignTokens.themeGray70,
"&:hover": {
color: "#EDEBE9",
},
}}
>
<Typography
variant="body2"
sx={{
color: BCDesignTokens.themeGray70,
"&:hover": {
color: "#EDEBE9",
},
}}
>
Form/Document
</Typography>
</TableSortLabel>
Form/Document
</Typography>
</StyledTableHeadCell>
<StyledTableHeadCell align="right">Uploaded by</StyledTableHeadCell>
<StyledTableHeadCell align="right">Version</StyledTableHeadCell>
Expand All @@ -119,6 +91,7 @@ export default function ItemsTable({
<When condition={userType === USER_TYPE.STAFF}>
<InternalDocumentsRows
internalStaffDocuments={internalStaffDocuments}
numColumns={5}
/>
</When>
</TableBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DocumentRow from "../DocumentRow";
import { Unless, When } from "react-if";
import { SubmissionItemTableCell, SubmissionItemTableRowProps } from ".";
import { PackageTableRow } from ".";
import EmptyRow from "@/components/Projects/ProjectTable/EmptyRow";

export default function ProponentSubmissionItemTableRow({
item,
Expand All @@ -35,7 +36,7 @@ export default function ProponentSubmissionItemTableRow({
return (
<>
<PackageTableRow key={`row-${item.name}`} error={error}>
<SubmissionItemTableCell colSpan={2}>
<SubmissionItemTableCell>
<MuiLink
color="inherit"
sx={{
Expand All @@ -54,8 +55,7 @@ export default function ProponentSubmissionItemTableRow({
</Typography>
</MuiLink>
</SubmissionItemTableCell>
<SubmissionItemTableCell align="right"></SubmissionItemTableCell>
<SubmissionItemTableCell align="right"></SubmissionItemTableCell>
<SubmissionItemTableCell align="right" colSpan={2} />
<SubmissionItemTableCell align="right">
<When condition={SUBMISSION_STATUS.NEW_SUBMISSION.value !== status}>
<SubmissionStatusChip status={status} />
Expand Down Expand Up @@ -106,15 +106,7 @@ export default function ProponentSubmissionItemTableRow({
</TableCell>
</TableRow>
</When>
<TableRow key={`row-${name}-divider`}>
<TableCell
colSpan={5}
sx={{
py: BCDesignTokens.layoutPaddingXsmall,
border: 0,
}}
/>
</TableRow>
<EmptyRow colSpan={5} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function StaffSubmissionItemTableRow({
return (
<>
<PackageTableRow key={`row-${item.name}`} error={error}>
<SubmissionItemTableCell colSpan={2}>
<SubmissionItemTableCell>
<MuiLink
color="inherit"
sx={{
Expand All @@ -49,11 +49,7 @@ export default function StaffSubmissionItemTableRow({
</Typography>
</MuiLink>
</SubmissionItemTableCell>
<SubmissionItemTableCell align="right"></SubmissionItemTableCell>
<SubmissionItemTableCell align="right"></SubmissionItemTableCell>
<SubmissionItemTableCell align="center">
{/* TODO Add Staff Status' */}
</SubmissionItemTableCell>
<SubmissionItemTableCell align="right" colSpan={3} />
<SubmissionItemTableCell align="center">
<Typography
variant="body2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import { INTERNAL_STAFF_DOCUMENT_TYPE } from "@/models/SubmissionItem";

type RowProps = {
pendingDocument: UploadObject;
numColumns?: number;
};

export default function PendingRow({ pendingDocument }: RowProps) {
export default function PendingRow({
pendingDocument,
numColumns = 4,
}: RowProps) {
const {
file: { name },
} = pendingDocument;
Expand Down Expand Up @@ -73,6 +77,7 @@ export default function PendingRow({ pendingDocument }: RowProps) {
if (pendingDocument.pending) {
uploadObject();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pendingDocument.pending]);

return (
Expand All @@ -91,7 +96,7 @@ export default function PendingRow({ pendingDocument }: RowProps) {
<MuiLink>{name}</MuiLink>
</Typography>
</StyledTableCell>
<StyledTableCell align="left" colSpan={3}>
<StyledTableCell align="left" colSpan={numColumns - 1}>
<CircularProgress size={20} />
</StyledTableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { StyledTableCell } from "@/components/Shared/Table/common";

type RowProps = {
internalStaffDocument: InternalStaffDocument;
numColumns: number;
};

export default function Row({ internalStaffDocument }: RowProps) {
export default function Row({ internalStaffDocument, numColumns }: RowProps) {
const [pendingGetObject, setPendingGetObject] = useState(false);
const { name, url, created_by } = internalStaffDocument;
const { name, url } = internalStaffDocument;

const downloadDocument = async () => {
try {
Expand Down Expand Up @@ -40,8 +41,7 @@ export default function Row({ internalStaffDocument }: RowProps) {
<MuiLink onClick={downloadDocument}>{name}</MuiLink>
</Typography>
</StyledTableCell>
<StyledTableCell align="right">{created_by || ""}</StyledTableCell>
<StyledTableCell align="right" colSpan={2}></StyledTableCell>
<StyledTableCell align="right" colSpan={numColumns - 1}></StyledTableCell>
</TableRow>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import PendingRow from "./PendingRow";

type InternalDocumentsProps = {
internalStaffDocuments: Array<InternalStaffDocument>;
submissionItemId?: number;
numColumns?: number;
};
export default function Rows({
internalStaffDocuments,
numColumns = 4,
}: InternalDocumentsProps) {
const { uploadObjects: pendingDocuments } = useObjectUploadStore();

Expand Down Expand Up @@ -48,10 +49,17 @@ export default function Rows({
</Typography>
</MuiLink>
</SubmissionItemTableCell>
<SubmissionItemTableCell align="right" colSpan={3} />
<SubmissionItemTableCell
align="right"
colSpan={numColumns - 1}
></SubmissionItemTableCell>
</PackageTableRow>
{internalStaffDocuments.map((document) => (
<Row key={`doc-row-${document.id}`} internalStaffDocument={document} />
<Row
key={`doc-row-${document.id}`}
internalStaffDocument={document}
numColumns={5}
/>
))}
{filteredPendingDocuments.map((pendingDocument) => (
<PendingRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export default function Table({
</TableRow>
</TableHead>
<TableBody>
<Rows internalStaffDocuments={internalStaffDocuments} />
<Rows
internalStaffDocuments={internalStaffDocuments}
numColumns={4}
/>
</TableBody>
</MuiTable>
</TableContainer>
Expand Down

0 comments on commit 859889c

Please sign in to comment.