Update frontend to use reportFile on Audit
Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
@@ -41,15 +41,14 @@ export const auditNodeQuery = graphql`
|
||||
name
|
||||
validFrom
|
||||
validUntil
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
mimeType
|
||||
size
|
||||
downloadUrl
|
||||
createdAt
|
||||
}
|
||||
reportUrl
|
||||
state
|
||||
framework {
|
||||
id
|
||||
@@ -82,9 +81,9 @@ export const createAuditMutation = graphql`
|
||||
name
|
||||
validFrom
|
||||
validUntil
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
}
|
||||
state
|
||||
framework {
|
||||
@@ -108,9 +107,9 @@ export const updateAuditMutation = graphql`
|
||||
name
|
||||
validFrom
|
||||
validUntil
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
}
|
||||
state
|
||||
framework {
|
||||
@@ -241,9 +240,9 @@ export const uploadAuditReportMutation = graphql`
|
||||
uploadAuditReport(input: $input) {
|
||||
audit {
|
||||
id
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
downloadUrl
|
||||
createdAt
|
||||
}
|
||||
@@ -286,9 +285,9 @@ export const deleteAuditReportMutation = graphql`
|
||||
deleteAuditReport(input: $input) {
|
||||
audit {
|
||||
id
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
downloadUrl
|
||||
createdAt
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ export default function AuditDetailsPage(props: Props) {
|
||||
});
|
||||
|
||||
const handleDeleteReport = () => {
|
||||
if (!auditEntry.report || !auditEntry.id) return;
|
||||
if (!auditEntry.reportFile || !auditEntry.id) return;
|
||||
|
||||
confirm(
|
||||
async () => {
|
||||
@@ -152,7 +152,7 @@ export default function AuditDetailsPage(props: Props) {
|
||||
__(
|
||||
"This will permanently delete the audit report \"%s\". This action cannot be undone.",
|
||||
),
|
||||
auditEntry.report.filename,
|
||||
auditEntry.reportFile.fileName,
|
||||
),
|
||||
},
|
||||
);
|
||||
@@ -253,7 +253,7 @@ export default function AuditDetailsPage(props: Props) {
|
||||
<div className="space-y-4">
|
||||
<h3 className="text-lg font-medium">{__("Audit Report")}</h3>
|
||||
|
||||
{auditEntry.report
|
||||
{auditEntry.reportFile
|
||||
? (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between p-4 bg-success-50 border border-success-200 rounded-lg">
|
||||
@@ -261,14 +261,14 @@ export default function AuditDetailsPage(props: Props) {
|
||||
<IconArrowInbox className="text-success-600" size={20} />
|
||||
<div className="flex-1">
|
||||
<p className="font-medium text-success-900">
|
||||
{auditEntry.report.filename}
|
||||
{auditEntry.reportFile.fileName}
|
||||
</p>
|
||||
<div className="flex items-center gap-4 text-sm text-success-700">
|
||||
<span>{fileSize(__, auditEntry.report.size)}</span>
|
||||
<span>{fileSize(__, auditEntry.reportFile.size)}</span>
|
||||
<span>
|
||||
{__("Uploaded")}
|
||||
{" "}
|
||||
{formatDate(auditEntry.report.createdAt)}
|
||||
{formatDate(auditEntry.reportFile.createdAt)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -276,8 +276,8 @@ export default function AuditDetailsPage(props: Props) {
|
||||
<ActionDropdown>
|
||||
<DropdownItem
|
||||
onClick={() => {
|
||||
if (auditEntry.report?.downloadUrl) {
|
||||
window.open(auditEntry.report.downloadUrl, "_blank");
|
||||
if (auditEntry.reportFile?.downloadUrl) {
|
||||
window.open(auditEntry.reportFile.downloadUrl, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
}}
|
||||
icon={IconArrowInbox}
|
||||
|
||||
@@ -82,7 +82,7 @@ const paginatedAuditsFragment = graphql`
|
||||
name
|
||||
validFrom
|
||||
validUntil
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
}
|
||||
state
|
||||
@@ -293,7 +293,7 @@ function AuditRow({
|
||||
<Td>{formatDate(entry.validFrom) || __("Not set")}</Td>
|
||||
<Td>{formatDate(entry.validUntil) || __("Not set")}</Td>
|
||||
<Td>
|
||||
{entry.report
|
||||
{entry.reportFile
|
||||
? (
|
||||
<div className="flex flex-col">
|
||||
<Badge variant="success">{__("Uploaded")}</Badge>
|
||||
|
||||
@@ -53,14 +53,13 @@ const documentAccessFragment = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
filename
|
||||
audit {
|
||||
id
|
||||
framework {
|
||||
name
|
||||
}
|
||||
fileName
|
||||
}
|
||||
audit {
|
||||
framework {
|
||||
name
|
||||
}
|
||||
}
|
||||
trustCenterFile {
|
||||
@@ -95,15 +94,15 @@ function toDocumentAccessInfo(
|
||||
status: node.status,
|
||||
};
|
||||
}
|
||||
if (node.report) {
|
||||
if (node.reportFile) {
|
||||
return {
|
||||
persisted: node.id !== node.report.id,
|
||||
persisted: node.id !== node.reportFile.id,
|
||||
variant: "success",
|
||||
name: node.report.filename,
|
||||
name: node.reportFile.fileName,
|
||||
type: "report",
|
||||
typeLabel: __("Report"),
|
||||
category: node.report.audit?.framework?.name ?? "",
|
||||
id: node.report.id,
|
||||
category: node.audit?.framework?.name ?? "",
|
||||
id: node.reportFile.id,
|
||||
status: node.status,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ const requestAccessMutation = graphql`
|
||||
mutation AuditRow_requestAccessMutation($input: RequestReportAccessInput!) {
|
||||
requestReportAccess(input: $input) {
|
||||
audit {
|
||||
report {
|
||||
reportFile {
|
||||
access {
|
||||
id
|
||||
status
|
||||
@@ -55,7 +55,7 @@ const requestAccessMutation = graphql`
|
||||
const auditRowFragment = graphql`
|
||||
fragment AuditRowFragment on Audit {
|
||||
name
|
||||
report {
|
||||
reportFile {
|
||||
id
|
||||
isUserAuthorized
|
||||
access {
|
||||
@@ -80,7 +80,7 @@ export function AuditRow(props: { audit: AuditRowFragment$key }) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const audit = useFragment(auditRowFragment, props.audit);
|
||||
const hasRequested = audit.report?.access?.status === "REQUESTED";
|
||||
const hasRequested = audit.reportFile?.access?.status === "REQUESTED";
|
||||
|
||||
const [requestAccess, isRequestingAccess]
|
||||
= useMutation<AuditRow_requestAccessMutation>(requestAccessMutation);
|
||||
@@ -89,7 +89,7 @@ export function AuditRow(props: { audit: AuditRowFragment$key }) {
|
||||
requestAccess({
|
||||
variables: {
|
||||
input: {
|
||||
reportId: audit.report?.id ?? "",
|
||||
reportId: audit.reportFile?.id ?? "",
|
||||
},
|
||||
},
|
||||
onCompleted: (_, errors) => {
|
||||
@@ -110,7 +110,7 @@ export function AuditRow(props: { audit: AuditRowFragment$key }) {
|
||||
onError: (error) => {
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
const pathPrefix = getPathPrefix();
|
||||
searchParams.set("request-report-id", audit.report?.id ?? "");
|
||||
searchParams.set("request-report-id", audit.reportFile?.id ?? "");
|
||||
const urlSearchParams = new URLSearchParams([[
|
||||
"continue",
|
||||
window.location.origin + pathPrefix + location.pathname + "?" + searchParams.toString(),
|
||||
@@ -135,14 +135,14 @@ export function AuditRow(props: { audit: AuditRowFragment$key }) {
|
||||
<IconMedal size={16} className="flex-none text-txt-tertiary" />
|
||||
{audit.name ?? audit.framework.name}
|
||||
</div>
|
||||
{audit.report && (
|
||||
audit.report.isUserAuthorized
|
||||
{audit.reportFile && (
|
||||
audit.reportFile.isUserAuthorized
|
||||
? (
|
||||
<Button
|
||||
className="w-full md:w-max"
|
||||
variant="secondary"
|
||||
icon={IconArrowLink}
|
||||
to={`/documents/${audit.report.id}`}
|
||||
to={`/documents/${audit.reportFile.id}`}
|
||||
>
|
||||
{__("View")}
|
||||
</Button>
|
||||
|
||||
@@ -48,7 +48,7 @@ const reportMutation = graphql`
|
||||
) {
|
||||
requestReportAccess(input: $input) {
|
||||
audit {
|
||||
report {
|
||||
reportFile {
|
||||
access {
|
||||
id
|
||||
status
|
||||
|
||||
@@ -70,9 +70,9 @@ export const documentPageQuery = graphql`
|
||||
status
|
||||
}
|
||||
}
|
||||
... on Report {
|
||||
... on AuditReport {
|
||||
id
|
||||
filename
|
||||
fileName
|
||||
isUserAuthorized
|
||||
access {
|
||||
id
|
||||
@@ -149,7 +149,7 @@ const requestReportAccessMutation = graphql`
|
||||
) {
|
||||
requestReportAccess(input: $input) {
|
||||
audit {
|
||||
report {
|
||||
reportFile {
|
||||
access {
|
||||
id
|
||||
status
|
||||
@@ -185,8 +185,8 @@ function getNodeTitle(node: DocumentPageQueryType["response"]["node"]): string |
|
||||
return node.title;
|
||||
case "TrustCenterFile":
|
||||
return node.name;
|
||||
case "Report":
|
||||
return node.filename;
|
||||
case "AuditReport":
|
||||
return node.fileName;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ function getNodeId(node: DocumentPageQueryType["response"]["node"]): string | un
|
||||
switch (node.__typename) {
|
||||
case "Document":
|
||||
case "TrustCenterFile":
|
||||
case "Report":
|
||||
case "AuditReport":
|
||||
return node.id;
|
||||
default:
|
||||
return undefined;
|
||||
@@ -221,7 +221,7 @@ export function DocumentPage({ queryRef }: Props) {
|
||||
if (
|
||||
node.__typename !== "Document"
|
||||
&& node.__typename !== "TrustCenterFile"
|
||||
&& node.__typename !== "Report"
|
||||
&& node.__typename !== "AuditReport"
|
||||
) {
|
||||
throw new Error(`Unexpected node type: ${node.__typename}`);
|
||||
}
|
||||
@@ -296,7 +296,7 @@ export function DocumentPage({ queryRef }: Props) {
|
||||
onError,
|
||||
});
|
||||
break;
|
||||
case "Report":
|
||||
case "AuditReport":
|
||||
exportReport({
|
||||
variables: { input: { reportId: node.id } },
|
||||
onCompleted: (response, errors) => {
|
||||
@@ -358,7 +358,7 @@ export function DocumentPage({ queryRef }: Props) {
|
||||
onError,
|
||||
});
|
||||
break;
|
||||
case "Report":
|
||||
case "AuditReport":
|
||||
requestReportAccess({
|
||||
variables: { input: { reportId: node.id } },
|
||||
onCompleted,
|
||||
@@ -370,7 +370,7 @@ export function DocumentPage({ queryRef }: Props) {
|
||||
|
||||
const isRequesting = isRequestingAccess || isRequestingFileAccess || isRequestingReportAccess;
|
||||
const hasRequested = node.access?.status === "REQUESTED";
|
||||
const isPdf = node.__typename === "Document" || node.__typename === "Report" || (node.__typename === "TrustCenterFile" && pdfData !== null);
|
||||
const isPdf = node.__typename === "Document" || node.__typename === "AuditReport" || (node.__typename === "TrustCenterFile" && pdfData !== null);
|
||||
|
||||
const handleDownload = () => {
|
||||
if (!fileData || !nodeTitle) return;
|
||||
|
||||
Reference in New Issue
Block a user