diff --git a/src/action/AsyncVocabularyActions.ts b/src/action/AsyncVocabularyActions.ts index 48b156b6..030a5aa7 100644 --- a/src/action/AsyncVocabularyActions.ts +++ b/src/action/AsyncVocabularyActions.ts @@ -32,6 +32,7 @@ import ChangeRecord, { } from "../model/changetracking/ChangeRecord"; import AssetFactory from "../util/AssetFactory"; import { VocabularyContentChangeFilterData } from "../model/filter/VocabularyContentChangeFilterData"; +import { getLocalized } from "../model/MultilingualString"; export function loadTermCount(vocabularyIri: IRI) { const action = { type: ActionType.LOAD_TERM_COUNT, vocabularyIri }; @@ -174,6 +175,19 @@ export function loadVocabularyContentDetailedChanges( CHANGE_RECORD_CONTEXT ) ) + .then((data: ChangeRecord[]) => { + // adding labels to the label cache as they cannot be fetched from server + const labels: { [key: string]: string } = {}; + data.forEach((r) => { + if (r["label"]) { + labels[r.changedEntity.iri] = getLocalized(r["label"]); + } + }); + dispatch( + asyncActionSuccessWithPayload({ type: ActionType.GET_LABEL }, labels) + ); + return data; + }) .then((data: ChangeRecord[]) => { dispatch(asyncActionSuccess(action)); return data.map((r) => AssetFactory.createChangeRecord(r)); diff --git a/src/component/changetracking/VocabularyContentDeleteRow.tsx b/src/component/changetracking/VocabularyContentDeleteRow.tsx index 6c1b67bc..55205364 100644 --- a/src/component/changetracking/VocabularyContentDeleteRow.tsx +++ b/src/component/changetracking/VocabularyContentDeleteRow.tsx @@ -24,7 +24,7 @@ export const VocabularyContentDeleteRow: React.FC = (props) => { - + {i18n(record.typeLabel)} diff --git a/src/component/changetracking/VocabularyContentPersistRow.tsx b/src/component/changetracking/VocabularyContentPersistRow.tsx index 6009cac5..343a67c7 100644 --- a/src/component/changetracking/VocabularyContentPersistRow.tsx +++ b/src/component/changetracking/VocabularyContentPersistRow.tsx @@ -22,7 +22,7 @@ export const VocabularyContentPersistRow: React.FC = ( - + {i18n(record.typeLabel)} diff --git a/src/component/changetracking/VocabularyContentUpdateRow.tsx b/src/component/changetracking/VocabularyContentUpdateRow.tsx index 85890e71..73af65d7 100644 --- a/src/component/changetracking/VocabularyContentUpdateRow.tsx +++ b/src/component/changetracking/VocabularyContentUpdateRow.tsx @@ -21,7 +21,7 @@ export const VocabularyContentUpdateRow: React.FC = (props) => { - + {i18n(record.typeLabel)} diff --git a/src/component/term/TermIriLink.tsx b/src/component/term/TermIriLink.tsx index 6b337538..18e72a38 100644 --- a/src/component/term/TermIriLink.tsx +++ b/src/component/term/TermIriLink.tsx @@ -4,31 +4,46 @@ import VocabularyUtils from "../../util/VocabularyUtils"; import Term from "../../model/Term"; import { useDispatch } from "react-redux"; import { ThunkDispatch } from "../../util/Types"; -import { loadTermByIri } from "../../action/AsyncActions"; +import { getLabel, loadTermByIri } from "../../action/AsyncActions"; import TermLink from "./TermLink"; import OutgoingLink from "../misc/OutgoingLink"; +import Utils from "../../util/Utils"; interface TermIriLinkProps { iri: string; id?: string; activeTab?: string; + shrinkFullIri?: boolean; } const TermIriLink: React.FC = (props) => { const { iri, id, activeTab } = props; const [term, setTerm] = useState(null); const dispatch: ThunkDispatch = useDispatch(); + const [label, setLabel] = useState(); useEffect(() => { const tIri = VocabularyUtils.create(iri); dispatch(loadTermByIri(tIri)).then((term) => setTerm(term)); }, [iri, dispatch, setTerm]); + // if term is null, try to acquire the label from cache + useEffect(() => { + if (term === null) { + dispatch(getLabel(iri)).then((label) => setLabel(label)); + } + }, [term, iri, dispatch]); + return ( <> {term !== null ? ( ) : ( - + )} ); diff --git a/src/model/changetracking/ChangeRecord.ts b/src/model/changetracking/ChangeRecord.ts index b06c268d..4101fb6a 100644 --- a/src/model/changetracking/ChangeRecord.ts +++ b/src/model/changetracking/ChangeRecord.ts @@ -1,6 +1,7 @@ import VocabularyUtils from "../../util/VocabularyUtils"; import User, { CONTEXT as USER_CONTEXT, UserData } from "../User"; import Utils from "../../util/Utils"; +import { context } from "../MultilingualString"; const ctx = { timestamp: { @@ -12,6 +13,7 @@ const ctx = { changedAttribute: `${VocabularyUtils.PREFIX}m\u00e1-zm\u011bn\u011bn\u00fd-atribut`, originalValue: `${VocabularyUtils.PREFIX}m\u00e1-p\u016fvodn\u00ed-hodnotu`, newValue: `${VocabularyUtils.PREFIX}m\u00e1-novou-hodnotu`, + label: context(VocabularyUtils.RDFS_LABEL), }; export const CONTEXT = Object.assign({}, ctx, USER_CONTEXT); diff --git a/src/model/changetracking/DeleteRecord.ts b/src/model/changetracking/DeleteRecord.ts index 120059e3..1eb257d2 100644 --- a/src/model/changetracking/DeleteRecord.ts +++ b/src/model/changetracking/DeleteRecord.ts @@ -10,7 +10,6 @@ export interface DeleteRecordData extends ChangeRecordData { */ export default class DeleteRecord extends ChangeRecord { public readonly label: MultilingualString; - public readonly vocabulary?: string; public constructor(data: DeleteRecordData) { super(data); this.label = data.label;