Skip to content

Commit

Permalink
[Enhancement kbss-cvut#520] Move shrinkFullIri to Utils
Browse files Browse the repository at this point in the history
Moving shrinkFullIri to Utils allows consistent IRI shrinking outside the AssetLabel component.
  • Loading branch information
lukaskabc committed Nov 1, 2024
1 parent c06df39 commit f5f4d9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/component/misc/AssetLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/util/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f5f4d9f

Please sign in to comment.