Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/framework-detail-page-title
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Jan 7, 2025
2 parents c5fb71b + e1d9807 commit f64220c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions backend/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
breadcrumbs: Breadcrumb[],
currentPath: string
): Promise<Breadcrumb[]> {
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;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/ModelTable/ModelTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -46,7 +49,7 @@
if (currentIndex > 0) {
currentIndex -= 1;
} else {
currentIndex = data.requirement_assessments.length - 1;
currentIndex = requirementAssessments.length - 1;
}
}
Expand Down Expand Up @@ -92,7 +95,7 @@
<p class="">{m.goBackToAudit()}</p>
</a>
</div>
<div class="font-semibold">{currentIndex + 1}/{data.requirement_assessments.length}</div>
<div class="font-semibold">{currentIndex + 1}/{requirementAssessments.length}</div>
</div>
<div class="flex flex-col items-center text-center justify-center">
<p class="font-semibold">{title}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, title: framework.name };
}) satisfies PageServerLoad;
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@
<div>
<span class="whitespace-pre-line" style="font-weight: 300;">
<p class="max-w-[80ch]">
{#if title}
<span style="font-weight: 600;">
{title}
</span>
{#if assessableNodes.length > 1 || (!assessable && assessableNodes.length > 0)}
<span class="badge variant-soft-primary">
{assessableNodes.length}
</span>
{#if title || description}
{#if title}
<span style="font-weight: 600;">{title}</span>
{/if}
{/if}
{#if description}
{description}
{#if description}
<p>{description}</p>
{/if}
{:else if node.question && node.question.questions && node.question.questions[0]}
<!-- This only displays the first question -->
{node.question.questions[0].text}
{/if}
</p>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@
breadcrumbAction="push"
href="/requirement-assessments/{ra_id}/edit?next={$page.url.pathname}"
>
{#if title}
<span style="font-weight: 600;">{title}</span>
{/if}
{#if description}
<p>{description}</p>
{#if title || description}
{#if title}
<span style="font-weight: 600;">{title}</span>
{/if}
{#if description}
<p>{description}</p>
{/if}
{:else if node.question && node.question.questions && node.question.questions[0]}
<!-- This only displays the first question -->
{node.question.questions[0].text}
{/if}
</Anchor>
{:else}
Expand Down

0 comments on commit f64220c

Please sign in to comment.