Skip to content

Commit

Permalink
Merge pull request #417 from intuitem/hotfix/risk-scenarios-table-sor…
Browse files Browse the repository at this point in the history
…ting

Fix sorting for risk scenarios table inside risk assessment
  • Loading branch information
ab-smith authored May 18, 2024
2 parents fc5b407 + 6b284db commit 5f6b6e5
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { superValidate } from 'sveltekit-superforms';
import { z } from 'zod';
import type { LayoutServerLoad } from './$types';
import { zod } from 'sveltekit-superforms/adapters';
import { listViewFields } from '$lib/utils/table';

export const load: LayoutServerLoad = async ({ fetch, params }) => {
const endpoint = `${BASE_API_URL}/risk-assessments/${params.id}/`;
Expand All @@ -20,25 +21,34 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
`${BASE_API_URL}/risk-matrices/${risk_assessment.risk_matrix.id}/`
).then((res) => res.json());

const headFields = [
'rid',
'name',
'threats',
'existingControls',
'currentLevel',
'appliedControls',
'residualLevel'
];

const bodyFields = [
'rid',
'name',
'threats',
'existing_controls',
'current_level',
'applied_controls',
'residual_level'
];

const headData: Record<string, string> = bodyFields.reduce((obj, key, index) => {
obj[key] = headFields[index];
return obj;
}, {});

const scenariosTable: TableSource = {
head: [
'rid',
'name',
'threats',
'existingControls',
'currentLevel',
'appliedControls',
'residualLevel'
],
body: tableSourceMapper(scenarios, [
'rid',
'name',
'threats',
'existing_controls',
'current_level',
'applied_controls',
'residual_level'
]),
head: headData,
body: tableSourceMapper(scenarios, bodyFields),
meta: scenarios
};

Expand Down

0 comments on commit 5f6b6e5

Please sign in to comment.