From 585d429ac87a35fd58545a49f1b064ed0b2e4bfc Mon Sep 17 00:00:00 2001 From: Axxiar Date: Mon, 16 Dec 2024 14:59:37 +0100 Subject: [PATCH] fix: Library uuid replaced by name in matrix view --- backend/core/serializers.py | 1 + frontend/src/lib/utils/crud.ts | 3 ++- .../risk-matrices/[id=uuid]/+page.svelte | 17 +++++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/core/serializers.py b/backend/core/serializers.py index 43332b224..6595dd66a 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -119,6 +119,7 @@ class AssessmentReadSerializer(BaseModelSerializer): class RiskMatrixReadSerializer(ReferentialSerializer): folder = FieldsRelatedField() json_definition = serializers.JSONField(source="get_json_translated") + library = FieldsRelatedField(["name", "id"]) class Meta: model = RiskMatrix diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index b9a6d9357..2ee86eeb9 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -177,7 +177,8 @@ export const URL_MODEL_MAP: ModelMap = { verboseName: 'Risk matrix', verboseNamePlural: 'Risk matrices', foreignKeyFields: [ - { field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO&content_type=GL' } + { field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO&content_type=GL' }, + { field: 'library', urlModel: 'libraries' } ] }, 'risk-assessments': { diff --git a/frontend/src/routes/(app)/(internal)/risk-matrices/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/(internal)/risk-matrices/[id=uuid]/+page.svelte index d4c653f8a..e5947f4ec 100644 --- a/frontend/src/routes/(app)/(internal)/risk-matrices/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/risk-matrices/[id=uuid]/+page.svelte @@ -38,12 +38,17 @@ {/each} {:else if value.id} - {@const itemHref = `/${ - URL_MODEL_MAP['risk-matrices']['foreignKeyFields']?.find( - (item) => item.field === key - )?.urlModel - }/${value.id}`} - {value.str} + {#if key === 'library'} + {@const itemHref = `/libraries/${value.id}?loaded`} + {value.name} + {:else} + {@const itemHref = `/${ + URL_MODEL_MAP['risk-matrices']['foreignKeyFields']?.find( + (item) => item.field === key + )?.urlModel + }/${value.id}`} + {value.str} + {/if} {:else} {value.str ?? value} {/if}