From f5f4d9f5b83ab616a09a0a5f0401e494d07ef9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ka=C5=88ka?= Date: Fri, 1 Nov 2024 11:55:12 +0100 Subject: [PATCH] [Enhancement #520] Move shrinkFullIri to Utils Moving shrinkFullIri to Utils allows consistent IRI shrinking outside the AssetLabel component. --- src/component/misc/AssetLabel.tsx | 14 ++++---------- src/util/Utils.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/component/misc/AssetLabel.tsx b/src/component/misc/AssetLabel.tsx index 049d757d..a6d20d00 100644 --- a/src/component/misc/AssetLabel.tsx +++ b/src/component/misc/AssetLabel.tsx @@ -4,6 +4,7 @@ import { ThunkDispatch } from "../../util/Types"; import { getLabel } from "../../action/AsyncActions"; import Namespaces from "../../util/Namespaces"; import TermItState from "../../model/TermItState"; +import Utils from "../../util/Utils"; interface AssetLabelProps { iri: string; @@ -70,17 +71,10 @@ export class AssetLabel extends React.Component< } private shrinkFullIri(iri: string): string { - if (!this.props.shrinkFullIri || iri.indexOf("://") === -1) { - return iri; // It is prefixed + if (!this.props.shrinkFullIri) { + return iri; } - const lastSlashIndex = iri.lastIndexOf("/"); - const lastHashIndex = iri.lastIndexOf("#"); - return ( - "..." + - iri.substring( - lastHashIndex > lastSlashIndex ? lastHashIndex : lastSlashIndex - ) - ); + return Utils.shrinkFullIri(iri); } } diff --git a/src/util/Utils.ts b/src/util/Utils.ts index 45b54beb..18e9530a 100644 --- a/src/util/Utils.ts +++ b/src/util/Utils.ts @@ -367,6 +367,20 @@ const Utils = { notBlank(str?: string | null) { return !!(str && str.trim().length > 0); }, + + shrinkFullIri(iri: string): string { + if (iri.indexOf("://") === -1) { + return iri; // It is prefixed + } + const lastSlashIndex = iri.lastIndexOf("/"); + const lastHashIndex = iri.lastIndexOf("#"); + return ( + "..." + + iri.substring( + lastHashIndex > lastSlashIndex ? lastHashIndex : lastSlashIndex + ) + ); + }, }; export default Utils;