Skip to content

Commit

Permalink
Moves toDisplay functions to ReferableUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronzi committed Dec 20, 2024
1 parent e8aa565 commit 1900912
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
3 changes: 2 additions & 1 deletion aas-web-ui/src/components/AppNavigation/AASList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions aas-web-ui/src/utils/ReferableUtils.ts
Original file line number Diff line number Diff line change
@@ -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 '';
}
22 changes: 0 additions & 22 deletions aas-web-ui/src/utils/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}

0 comments on commit 1900912

Please sign in to comment.