From c52fb0b7e2102698df6b7c7cf7466ab6404e9aec Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Thu, 2 Jan 2025 04:43:16 +0100 Subject: [PATCH 1/4] Support question-only requirements --- .../[id=uuid]/flash-mode/+page.svelte | 11 +++++++---- .../[id=uuid]/TreeViewItemContent.svelte | 15 ++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/routes/(app)/(internal)/compliance-assessments/[id=uuid]/flash-mode/+page.svelte b/frontend/src/routes/(app)/(internal)/compliance-assessments/[id=uuid]/flash-mode/+page.svelte index 2af589bd9..d3165ff12 100644 --- a/frontend/src/routes/(app)/(internal)/compliance-assessments/[id=uuid]/flash-mode/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/compliance-assessments/[id=uuid]/flash-mode/+page.svelte @@ -15,8 +15,11 @@ ]; // Reactive variable to keep track of the current item index + const requirementAssessments = data.requirement_assessments.filter( + (requirement) => requirement.name || requirement.description + ); let currentIndex = 0; - $: currentRequirementAssessment = data.requirement_assessments[currentIndex]; + $: currentRequirementAssessment = requirementAssessments[currentIndex]; $: color = complianceResultTailwindColorMap[currentRequirementAssessment.result]; @@ -34,7 +37,7 @@ // Function to handle the "Next" button click function nextItem() { - if (currentIndex < data.requirement_assessments.length - 1) { + if (currentIndex < requirementAssessments.length - 1) { currentIndex += 1; } else { currentIndex = 0; @@ -46,7 +49,7 @@ if (currentIndex > 0) { currentIndex -= 1; } else { - currentIndex = data.requirement_assessments.length - 1; + currentIndex = requirementAssessments.length - 1; } } @@ -92,7 +95,7 @@

{m.goBackToAudit()}

-
{currentIndex + 1}/{data.requirement_assessments.length}
+
{currentIndex + 1}/{requirementAssessments.length}

{title}

diff --git a/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte b/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte index 073944f53..c415a1de0 100644 --- a/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte +++ b/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte @@ -116,11 +116,16 @@ breadcrumbAction="push" href="/requirement-assessments/{ra_id}/edit?next={$page.url.pathname}" > - {#if title} - {title} - {/if} - {#if description} -

{description}

+ {#if title || description} + {#if title} + {title} + {/if} + {#if description} +

{description}

+ {/if} + {:else if node.question.questions && node.question.questions[0]} + + {node.question.questions[0].text} {/if} {:else} From ef63e51af1d3d6a727acf010e1e4b95195b71028 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Mon, 6 Jan 2025 19:30:33 +0100 Subject: [PATCH 2/4] Include search params in edit next URL when coming from list --- frontend/src/lib/components/ModelTable/ModelTable.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/lib/components/ModelTable/ModelTable.svelte b/frontend/src/lib/components/ModelTable/ModelTable.svelte index 36b309071..a5caa0426 100644 --- a/frontend/src/lib/components/ModelTable/ModelTable.svelte +++ b/frontend/src/lib/components/ModelTable/ModelTable.svelte @@ -406,7 +406,7 @@ URLModel={actionsURLModel} detailURL={`/${actionsURLModel}/${row.meta[identifierField]}${detailQueryParameter}`} editURL={!(row.meta.builtin || row.meta.urn) - ? `/${actionsURLModel}/${row.meta[identifierField]}/edit?next=${$page.url.pathname}` + ? `/${actionsURLModel}/${row.meta[identifierField]}/edit?next=${encodeURIComponent($page.url.pathname + $page.url.search)}` : undefined} {row} hasBody={$$slots.actionsBody} From db559405b7bf0bd40f8491f2374a0d0e6d5e262f Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Tue, 7 Jan 2025 10:41:15 +0100 Subject: [PATCH 3/4] Fix question not being displayed in framework and libary detail views --- backend/core/helpers.py | 4 ++-- backend/library/utils.py | 5 +++-- .../frameworks/[id=uuid]/+page.server.ts | 9 ++++----- .../[id=uuid]/TreeViewItemContent.svelte | 20 +++++++++---------- .../[id=uuid]/TreeViewItemContent.svelte | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/backend/core/helpers.py b/backend/core/helpers.py index 5f5601e27..d9b3c707a 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -287,7 +287,7 @@ def get_sorted_requirement_nodes_rec(start: list) -> dict: "is_scored": req_as.is_scored if req_as else None, "score": req_as.score if req_as else None, "max_score": max_score if req_as else None, - "question": req_as.answer if req_as else None, + "question": req_as.answer if req_as else node.question, "mapping_inference": req_as.mapping_inference if req_as else None, "status_display": req_as.get_status_display() if req_as else None, "status_i18n": camel_case(req_as.status) if req_as else None, @@ -325,7 +325,7 @@ def get_sorted_requirement_nodes_rec(start: list) -> dict: "is_scored": child_req_as.is_scored if child_req_as else None, "score": child_req_as.score if child_req_as else None, "max_score": max_score if child_req_as else None, - "question": child_req_as.answer if child_req_as else None, + "question": child_req_as.answer if child_req_as else child.question, "mapping_inference": child_req_as.mapping_inference if child_req_as else None, diff --git a/backend/library/utils.py b/backend/library/utils.py index 161a1a0ff..92c9375a6 100644 --- a/backend/library/utils.py +++ b/backend/library/utils.py @@ -38,9 +38,9 @@ def preview_library(framework: dict) -> dict[str, list]: """ preview = {} requirement_nodes_list = [] - if framework.get("requirement_nodes"): + if (requirement_nodes := framework.get("requirement_nodes")) is not None: index = 0 - for requirement_node in framework["requirement_nodes"]: + for requirement_node in requirement_nodes: parent_urn = requirement_node.get("parent_urn") if parent_urn: parent_urn = parent_urn.lower() @@ -55,6 +55,7 @@ def preview_library(framework: dict) -> dict[str, list]: urn=requirement_node["urn"].lower(), parent_urn=parent_urn, order_id=index, + question=requirement_node.get("question"), ) ) preview["requirement_nodes"] = requirement_nodes_list diff --git a/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/+page.server.ts b/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/+page.server.ts index 3b32b3f3d..57a6d4cf7 100644 --- a/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/+page.server.ts @@ -5,10 +5,9 @@ export const load = (async ({ fetch, params }) => { const URLModel = 'frameworks'; const endpoint = `${BASE_API_URL}/${URLModel}/${params.id}/object/`; - const res = await fetch(endpoint); - const framework = await res.json(); - const tree = await fetch(`${BASE_API_URL}/${URLModel}/${params.id}/tree`).then((res) => - res.json() - ); + const [framework, tree] = await Promise.all([ + fetch(endpoint).then((res) => res.json()), + fetch(`${BASE_API_URL}/${URLModel}/${params.id}/tree`).then((res) => res.json()) + ]); return { URLModel, framework, tree }; }) satisfies PageServerLoad; diff --git a/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/TreeViewItemContent.svelte b/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/TreeViewItemContent.svelte index 642d077c5..029df6e0f 100644 --- a/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/TreeViewItemContent.svelte +++ b/frontend/src/routes/(app)/(internal)/frameworks/[id=uuid]/TreeViewItemContent.svelte @@ -49,18 +49,16 @@

- {#if title} - - {title} - - {#if assessableNodes.length > 1 || (!assessable && assessableNodes.length > 0)} - - {assessableNodes.length} - + {#if title || description} + {#if title} + {title} {/if} - {/if} - {#if description} - {description} + {#if description} +

{description}

+ {/if} + {:else if node.question && node.question.questions && node.question.questions[0]} + + {node.question.questions[0].text} {/if}

diff --git a/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte b/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte index c415a1de0..1fcbf0078 100644 --- a/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte +++ b/frontend/src/routes/(app)/(third-party)/compliance-assessments/[id=uuid]/TreeViewItemContent.svelte @@ -123,7 +123,7 @@ {#if description}

{description}

{/if} - {:else if node.question.questions && node.question.questions[0]} + {:else if node.question && node.question.questions && node.question.questions[0]} {node.question.questions[0].text} {/if} From 8c80046ecd6ccd8c12958b0151e14508b61e350b Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 7 Jan 2025 11:21:11 +0100 Subject: [PATCH 4/4] Update trimBreadcrumbsToCurrentPath predicates --- frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte b/frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte index 79adbf2e5..a89d2677a 100644 --- a/frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte +++ b/frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte @@ -10,8 +10,9 @@ breadcrumbs: Breadcrumb[], currentPath: string ): Promise { - const idx = breadcrumbs.findIndex((c) => c.href === currentPath); - if (idx >= 0 && idx < breadcrumbs.length - 1) { + const idx = breadcrumbs.findIndex((c) => c.href?.startsWith(currentPath)); + // First breadcrumb is home, its href is always '/' + if (idx > 0 && idx < breadcrumbs.length - 1) { breadcrumbs = breadcrumbs.slice(0, idx + 1); } return breadcrumbs;