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