Skip to content

Commit 24b56ee

Browse files
authored
Merge pull request #306 from nitheesh-aot/s3-private
S3 private
2 parents ffb89de + 945f7db commit 24b56ee

File tree

14 files changed

+183
-161
lines changed

14 files changed

+183
-161
lines changed

compliance-api/src/compliance_api/services/inspection_requirement.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ def _update_the_findigs_by_images(
323323
if matching_photo:
324324
# Update the image ID in the span
325325
span["data-imageid"] = str(matching_photo.id)
326-
# Update image URL if needed
327-
span["data-imageurl"] = matching_photo.relative_url
328326
except (ValueError, IndexError):
329327
# Invalid photo number format
330328
pass
@@ -341,8 +339,6 @@ def _update_the_findigs_by_images(
341339
if matching_figure:
342340
# Update the image ID in the span
343341
span["data-imageid"] = str(matching_figure.id)
344-
# Update image URL if needed
345-
span["data-imageurl"] = matching_figure.relative_url
346342
except (ValueError, IndexError):
347343
# Invalid figure number format
348344
pass

compliance-web/cypress/components/_components/_App/_Inspections/_Requirements/_Images/ImageCard.cy.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("ImageCard Component", () => {
88
relative_url: "test-image.jpg",
99
caption: "Test Image Caption",
1010
sort_order: 1,
11+
url: "https://test-image.jpg",
1112
};
1213

1314
const renderImageCard = (props = {}) => {
@@ -28,7 +29,7 @@ describe("ImageCard Component", () => {
2829
renderImageCard();
2930

3031
// Check if image is rendered with correct source
31-
cy.get("img").should("have.attr", "src").and("include", "test-image.jpg");
32+
cy.get("img").should("have.attr", "src").and("include", "https://test-image.jpg");
3233

3334
// Check if caption is rendered correctly
3435
cy.get("a").should("contain.text", "Photo 1: Test Image Caption");

compliance-web/cypress/components/_components/_App/_Inspections/_Requirements/_Images/ImageModal.cy.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("ImageModal Component", () => {
2626
const mockImageData: RequirementImage = {
2727
id: 1,
2828
relative_url: "test-url",
29+
url: "https://test-image.jpg",
2930
caption: "Test Caption",
3031
taken_by: mockStaffUsers[0] as unknown as StaffUser,
3132
taken_by_id: mockStaffUsers[0].id,
@@ -37,7 +38,10 @@ describe("ImageModal Component", () => {
3738

3839
const queryClient = new QueryClient();
3940

40-
function mountImageModal(imageData?: RequirementImage, onDelete?: () => void): React.ReactNode {
41+
function mountImageModal(
42+
imageData?: RequirementImage,
43+
onDelete?: () => void
44+
): React.ReactNode {
4145
return (
4246
<QueryClientProvider client={queryClient}>
4347
<ImageModal
@@ -106,7 +110,7 @@ describe("ImageModal Component", () => {
106110

107111
// Click delete button
108112
cy.get('[data-testid="delete-action-modal-button"]').click();
109-
113+
110114
// Confirm deletion
111115
cy.get('[data-testid="delete-confirmation-button"]').click();
112116

compliance-web/src/components/App/Inspections/Profile/Reports/ReportTabContents/IRImageSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { RequirementImage } from "@/models/Image";
2-
import { formatS3Url } from "@/utils/appUtils";
32
import { Typography } from "@mui/material";
43
import { Box } from "@mui/material";
54
import imageNotFound from "@/assets/images/image-not-found.svg";
@@ -19,7 +18,7 @@ const IRImageSection = ({ image }: { image: RequirementImage }) => {
1918
}}
2019
>
2120
<img
22-
src={formatS3Url(image.relative_url ?? "")}
21+
src={image.url ?? ""}
2322
alt={image.caption}
2423
style={{
2524
width: "100%",

compliance-web/src/components/App/Inspections/Profile/Requirements/Images/ImageCard.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Box } from "@mui/material";
33
import { RequirementImage } from "@/models/Image";
44
import { arraySwap, useSortable } from "@dnd-kit/sortable";
55
import { CSS } from "@dnd-kit/utilities";
6-
import { formatS3Url } from "@/utils/appUtils";
76
import imageNotFound from "@/assets/images/image-not-found.svg";
87
import { BCDesignTokens } from "epic.theme";
98

@@ -66,7 +65,7 @@ export default function ImageCard({
6665
}}
6766
>
6867
<img
69-
src={formatS3Url(image.relative_url ?? "")}
68+
src={image.url ?? ""}
7069
alt={image.caption}
7170
width={"100%"}
7271
onError={(e) => {

compliance-web/src/components/App/Inspections/Profile/Requirements/Images/ImageModal.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import GridLabelValuePair from "@/components/Shared/GridLabelValuePair";
1313
import { ImageFormData, RequirementImage } from "@/models/Image";
1414
import { useEffect, useMemo } from "react";
1515
import { useImageUpload } from "@/hooks/useImageUpload";
16-
import { formatS3Url } from "@/utils/appUtils";
1716
import dayjs from "dayjs";
1817
import dateUtils from "@/utils/dateUtils";
1918
import { ImageTypeEnum } from "@/components/App/Inspections/Profile/Requirements/RequirementUtils";
@@ -69,11 +68,15 @@ const ImageModal: React.FC<ImageModalProps> = ({
6968

7069
const { handleSubmit, reset, getValues } = methods;
7170

72-
const onSuccess = (uploadedFileUrl: string) => {
71+
const onSuccess = (uploadedFile: {
72+
presigned_url: string;
73+
relative_url: string;
74+
}) => {
7375
const takenBy = getValues("takenBy") as StaffUser;
7476
const imageFormData: RequirementImage = {
7577
id: Date.now(),
76-
relative_url: uploadedFileUrl,
78+
relative_url: uploadedFile.relative_url,
79+
url: uploadedFile.presigned_url,
7780
caption: getValues("caption"),
7881
taken_by: takenBy,
7982
taken_by_id: takenBy?.id,
@@ -139,7 +142,7 @@ const ImageModal: React.FC<ImageModalProps> = ({
139142
src={
140143
file
141144
? URL.createObjectURL(file)
142-
: formatS3Url(requirementImage?.relative_url ?? "")
145+
: (requirementImage?.url ?? "")
143146
}
144147
alt="Preview"
145148
style={{ maxHeight: "100%", maxWidth: "100%" }}
@@ -181,8 +184,9 @@ const ImageModal: React.FC<ImageModalProps> = ({
181184
? dateUtils.formatDate(
182185
dayjs(file.lastModified).toISOString()
183186
)
184-
: dateUtils.formatDate(requirementImage?.date_taken ?? "") ||
185-
"No file selected"
187+
: dateUtils.formatDate(
188+
requirementImage?.date_taken ?? ""
189+
) || "No file selected"
186190
}
187191
gridProps={{ xs: 4 }}
188192
isBold

compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export const formatImagesToMentionList = (images: RequirementImage[]): MentionDa
224224
return images.map((image) => ({
225225
id: image.id ?? 0,
226226
name: `${image.image_type ?? ""} ${image.sort_order}`,
227-
imageRelativeUrl: image.relative_url ?? "",
227+
imageUrl: image.url ?? "",
228228
}));
229229
};
230230

@@ -359,7 +359,7 @@ export const formatRequirementImagesInFindings = (
359359
const imageLabel = `${image.image_type} ${image.sort_order}`;
360360
span.textContent = imageLabel;
361361
span.setAttribute("data-mention", imageLabel);
362-
span.setAttribute("data-imageurl", image.relative_url ?? "");
362+
span.setAttribute("data-imageurl", image.url ?? "");
363363
} else {
364364
span.parentNode?.removeChild(span);
365365
}

compliance-web/src/components/Shared/LexicalEditor/LexicalUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type MentionData = {
22
id: number;
33
name: string;
4-
imageRelativeUrl?: string;
4+
imageUrl?: string;
55
};
66

77
export const LexicalTheme = {

0 commit comments

Comments
 (0)