From 19009129d60a9cd1551d7000fef013fd5ea847f1 Mon Sep 17 00:00:00 2001 From: Aaron Zielstorff Date: Fri, 20 Dec 2024 09:42:36 +0100 Subject: [PATCH] Moves toDisplay functions to ReferableUtils --- .../src/components/AppNavigation/AASList.vue | 3 ++- aas-web-ui/src/utils/ReferableUtils.ts | 21 ++++++++++++++++++ aas-web-ui/src/utils/generalUtils.ts | 22 ------------------- 3 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 aas-web-ui/src/utils/ReferableUtils.ts diff --git a/aas-web-ui/src/components/AppNavigation/AASList.vue b/aas-web-ui/src/components/AppNavigation/AASList.vue index a2fde890..98e2f5fb 100644 --- a/aas-web-ui/src/components/AppNavigation/AASList.vue +++ b/aas-web-ui/src/components/AppNavigation/AASList.vue @@ -170,7 +170,8 @@ import { useNavigationStore } from '@/store/NavigationStore'; import { extractEndpointHref } from '@/utils/DescriptorUtils'; import { URLEncode } from '@/utils/EncodeDecodeUtils'; - import { downloadFile, nameToDisplay } from '@/utils/generalUtils'; + import { downloadFile } from '@/utils/generalUtils'; + import { nameToDisplay } from '@/utils/ReferableUtils'; // Extend the ComponentPublicInstance type to include scrollToIndex interface VirtualScrollInstance extends ComponentPublicInstance { diff --git a/aas-web-ui/src/utils/ReferableUtils.ts b/aas-web-ui/src/utils/ReferableUtils.ts new file mode 100644 index 00000000..f36d083a --- /dev/null +++ b/aas-web-ui/src/utils/ReferableUtils.ts @@ -0,0 +1,21 @@ +// Function to extract the english display name from a referable +export function nameToDisplay(referable: any, defaultNameToDisplay = '') { + if (referable && referable?.displayName) { + const displayNameEn = referable.displayName.find((displayName: any) => { + return displayName.language === 'en' && displayName.text !== ''; + }); + if (displayNameEn && displayNameEn.text) return displayNameEn.text; + } + return !defaultNameToDisplay && referable?.idShort ? referable.idShort : defaultNameToDisplay; +} + +// Function to extract the english description from a referable +export function descriptionToDisplay(referable: any) { + if (referable && referable?.description) { + const descriptionEn = referable.description.find( + (description: any) => description && description.language === 'en' && description.text !== '' + ); + if (descriptionEn && descriptionEn.text) return descriptionEn.text; + } + return ''; +} diff --git a/aas-web-ui/src/utils/generalUtils.ts b/aas-web-ui/src/utils/generalUtils.ts index 911e72de..b951a7d4 100644 --- a/aas-web-ui/src/utils/generalUtils.ts +++ b/aas-web-ui/src/utils/generalUtils.ts @@ -60,25 +60,3 @@ export function downloadFile(filename: string, fileContent: Blob) { link.click(); document.body.removeChild(link); } - -// Function to extract the english display name from a referable -export function nameToDisplay(referable: any, defaultNameToDisplay = '') { - if (referable && referable?.displayName) { - const displayNameEn = referable.displayName.find((displayName: any) => { - return displayName.language === 'en' && displayName.text !== ''; - }); - if (displayNameEn && displayNameEn.text) return displayNameEn.text; - } - return !defaultNameToDisplay && referable?.idShort ? referable.idShort : defaultNameToDisplay; -} - -// Function to extract the english description from a referable -export function descriptionToDisplay(referable: any) { - if (referable && referable?.description) { - const descriptionEn = referable.description.find( - (description: any) => description && description.language === 'en' && description.text !== '' - ); - if (descriptionEn && descriptionEn.text) return descriptionEn.text; - } - return ''; -}