Skip to content

Commit

Permalink
Merge remote-tracking branch 'bcgov/develop' into SUBMIT-11
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot committed Nov 1, 2024
2 parents 9998f00 + f6094f0 commit f9f8271
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 105 deletions.
2 changes: 1 addition & 1 deletion submit-api/src/submit_api/models/queries/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_projects_by_account_id(cls, account_id: int, search_options: AccountProj
).join(AccountProject.project)

# Apply search filters if provided
if search_options:
if search_options and any(bool(search_option) for search_option in search_options.__dict__.values()):
query = cls.filter_by_search_criteria(query, search_options)

return query.all()
Expand Down
17 changes: 17 additions & 0 deletions submit-api/src/submit_api/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def get(account_id):
projects = ProjectService.get_projects_by_account_id(account_id, search_options)
return AccountProjectSchema(many=True).dump(projects), HTTPStatus.OK

@staticmethod
@ApiHelper.swagger_decorators(API, endpoint_description="Add projects in bulk")
@API.expect(project_add_list)
@API.response(
code=HTTPStatus.CREATED, model=project_list_model, description="Added projects"
)
@API.response(HTTPStatus.BAD_REQUEST, "Bad Request")
@auth.require
@cors.crossdomain(origin="*")
def post(account_id):
"""Add projects in bulk."""
projects_data = AddProjectSchema().load(API.payload)
added_projects = ProjectService.bulk_add_projects(
account_id, projects_data.get("project_ids")
)
return ProjectSchema(many=True).dump(added_projects), HTTPStatus.CREATED


@cors_preflight("GET, OPTIONS, POST")
@API.route("/proponents/<int:proponent_id>", methods=["POST", "GET", "OPTIONS"])
Expand Down
87 changes: 87 additions & 0 deletions submit-web/src/components/DocumentUpload/DocumentTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
Box,
Table,
TableBody,
TableContainer,
TableHead,
TableRow,
Typography,
} from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import { StyledTableHeadCell } from "../Shared/Table/common";
import { Submission } from "@/models/Submission";
import DocumentTableRow, {
StyledHeadTableCell,
DocumentHeadTableRow,
} from "./DocumentTableRow";
import { Document } from "@/store/documentUploadStore";
import PendingDocumentRow from "./PendingDocumentRow";

export default function DocumentTable({
header,
documents,
pendingDocuments,
}: {
header: string;
documents: Array<Submission>;
pendingDocuments: Array<Document>;
}) {
return (
<TableContainer component={Box} sx={{ height: "100%" }}>
<Table sx={{ tableLayout: "fixed" }}>
<TableHead
sx={{
".MuiTableCell-root": {
p: BCDesignTokens.layoutPaddingXsmall,
},
}}
>
<TableRow>
<StyledTableHeadCell colSpan={2}>
<Typography
variant="body2"
sx={{
color: BCDesignTokens.themeGray70,
"&:hover": {
color: "#EDEBE9",
},
}}
>
Form/Document
</Typography>
</StyledTableHeadCell>
<StyledTableHeadCell align="right">Uploaded by</StyledTableHeadCell>
<StyledTableHeadCell align="right">Version</StyledTableHeadCell>
<StyledTableHeadCell align="center">Actions</StyledTableHeadCell>
</TableRow>
</TableHead>
<TableBody>
<DocumentHeadTableRow>
<StyledHeadTableCell colSpan={5}>
<Typography
variant="h6"
color="inherit"
fontWeight={900}
sx={{ mx: 0.5 }}
>
{header}
</Typography>
</StyledHeadTableCell>
</DocumentHeadTableRow>
{documents?.map((document) => (
<DocumentTableRow
key={`custom-row-${document.name}`}
documentItem={document}
/>
))}
{pendingDocuments?.map((document) => (
<PendingDocumentRow
key={`pending-row-${document.file.name}`}
documentItem={document}
/>
))}
</TableBody>
</Table>
</TableContainer>
);
}
167 changes: 167 additions & 0 deletions submit-web/src/components/DocumentUpload/DocumentTableRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import React, { useState } from "react";
import {
Link as MuiLink,
styled,
TableCell,
TableRow,
TableRowProps,
Typography,
} from "@mui/material";
import { BCDesignTokens } from "epic.theme";
import { downloadObject } from "@/hooks/api/useObjectStorage";
import { notify } from "../Shared/Snackbar/snackbarStore";

export const StyledHeadTableCell = styled(TableCell)<{ error?: boolean }>(
({ error }) => ({
borderTop: error
? `1px solid ${BCDesignTokens.supportBorderColorDanger}`
: `1px solid ${BCDesignTokens.themeBlue20}`,
borderBottom: error
? `1px solid ${BCDesignTokens.supportBorderColorDanger}`
: `1px solid ${BCDesignTokens.themeBlue20}`,
padding: `${BCDesignTokens.layoutPaddingXsmall} !important`,
"&:first-of-type": {
borderLeft: error
? `1px solid ${BCDesignTokens.supportBorderColorDanger}`
: `1px solid ${BCDesignTokens.themeBlue20}`,
borderTopLeftRadius: 5,
borderBottomLeftRadius: 5,
},
"&:last-of-type": {
borderRight: error
? `1px solid ${BCDesignTokens.supportBorderColorDanger}`
: `1px solid ${BCDesignTokens.themeBlue20}`,
borderTopRightRadius: 5,
borderBottomRightRadius: 5,
},
})
);

export const DocumentHeadTableRow = styled(TableRow)<{ error?: boolean }>(
({ error }) => ({
backgroundColor: error
? BCDesignTokens.supportSurfaceColorDanger
: BCDesignTokens.themeBlue10,
"&:hover": {
backgroundColor: BCDesignTokens.themeBlue40,
},
})
);

export const DocumentTableCell = styled(TableCell)(() => ({
borderTop: `1px solid ${BCDesignTokens.themeBlue20}`,
borderBottom: `1px solid ${BCDesignTokens.themeBlue20}`,
padding: `${BCDesignTokens.layoutPaddingXsmall} !important`,
"&:first-of-type": {
borderLeft: `1px solid ${BCDesignTokens.themeBlue20}`,
borderTopLeftRadius: 5,
borderBottomLeftRadius: 5,
},
"&:last-of-type": {
borderRight: `1px solid ${BCDesignTokens.themeBlue20}`,
borderTopRightRadius: 5,
borderBottomRightRadius: 5,
},
}));

const StyledTableRow = styled(TableRow)(() => ({}));

type StyledTableRowProps = TableRowProps & { error?: boolean };
export const PackageTableRow = ({
error,
children,
...otherProps
}: StyledTableRowProps) => {
// pass error to every child
const childrenWithProps = React.Children.map(children, (child) =>
React.isValidElement(child)
? React.cloneElement(child, { error } as any) // eslint-disable-line @typescript-eslint/no-explicit-any
: child
);

return (
<StyledTableRow error={error} {...otherProps}>
{childrenWithProps}
</StyledTableRow>
);
};

type DocumentTableRowProps = {
documentItem: {
id: number;
name: string;
submitted_by: string;
version: number;
url: string;
};
error?: boolean;
};
export default function DocumentTableRow({
documentItem,
error = false,
}: DocumentTableRowProps) {
const { name, submitted_by, version, url } = documentItem;

const onActionClick = () => {};
const [pendingGetObject, setPendingGetObject] = useState(false);

const getObjectFromS3 = async () => {
try {
if (pendingGetObject) return;
setPendingGetObject(true);
const response = await downloadObject({
filename: name,
s3sourceuri: url,
});
const linkUrl = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = linkUrl;
link.setAttribute("download", name);
document.body.appendChild(link);
link.click();
} catch (e) {
notify.error("Failed to download documentItem");
} finally {
setPendingGetObject(false);
}
};

return (
<PackageTableRow key={`row-${documentItem.name}`} error={error}>
<DocumentTableCell colSpan={2}>
<Typography
variant="body1"
color="inherit"
sx={{
overflow: "clip",
textOverflow: "ellipsis",
cursor: "pointer",
mx: 0.5,
textDecoration: "none",
}}
>
<MuiLink onClick={getObjectFromS3} sx={{ textDecoration: "none" }}>
{name}
</MuiLink>
</Typography>
</DocumentTableCell>
<DocumentTableCell align="right">{submitted_by}</DocumentTableCell>
<DocumentTableCell align="right">{version}</DocumentTableCell>
<DocumentTableCell align="center">
<Typography
variant="body2"
sx={{
color: BCDesignTokens.typographyColorLink,
"&:hover": {
cursor: "pointer",
textDecoration: "underline",
},
}}
onClick={onActionClick}
>
Remove
</Typography>
</DocumentTableCell>
</PackageTableRow>
);
}
Loading

0 comments on commit f9f8271

Please sign in to comment.