Skip to content

Commit

Permalink
Configuring the URI link target
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorBaptist4 authored and tdonohue committed Dec 19, 2024
1 parent eb3db9c commit 25ab69f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

<!-- Render value as a link (href and label) -->
<ng-template #link let-value="value">
<a class="dont-break-out ds-simple-metadata-link" target="_blank" [href]="value">
<a class="dont-break-out ds-simple-metadata-link"
[href]="value"
[attr.target]="getLinkAttributes(value).target"
[attr.rel]="getLinkAttributes(value).rel">
{{value}}
</a>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface';
import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
import { hasValue } from '../../../shared/empty.util';
import { VALUE_LIST_BROWSE_DEFINITION } from '../../../core/shared/value-list-browse-definition.resource-type';
import { environment } from '../../../../environments/environment';

/**
* This component renders the configured 'values' into the ds-metadata-field-wrapper component.
Expand Down Expand Up @@ -90,4 +91,25 @@ export class MetadataValuesComponent implements OnChanges {
}
return queryParams;
}

/**
* Checks if the given link value is an internal link.
* @param linkValue - The link value to check.
* @returns True if the link value starts with the base URL defined in the environment configuration, false otherwise.
*/
hasInternalLink(linkValue: string): boolean {
return linkValue.startsWith(environment.ui.baseUrl);
}

/**
* This method performs a validation and determines the target of the url.
* @returns - Returns the target url.
*/
getLinkAttributes(urlValue: string): { target: string, rel: string } {
if (this.hasInternalLink(urlValue)) {
return { target: '_self', rel: '' };
} else {
return { target: '_blank', rel: 'noopener noreferrer' };
}
}
}

0 comments on commit 25ab69f

Please sign in to comment.