Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/action/ActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ enum ActionType {
LOAD_PERSONAL_ACCESS_TOKENS = "LOAD_PERSONAL_ACCESS_TOKENS",
CREATE_PERSONAL_ACCESS_TOKEN = "CREATE_PERSONAL_ACCESS_TOKEN",
DELETE_PERSONAL_ACCESS_TOKEN = "DELETE_PERSONAL_ACCESS_TOKEN",

LOAD_CUSTOM_ATTRIBUTE_USAGE = "LOAD_CUSTOM_ATTRIBUTE_USAGE",
REMOVE_CUSTOM_ATTRIBUTE = "REMOVE_CUSTOM_ATTRIBUTE",
}

export default ActionType;
54 changes: 5 additions & 49 deletions src/action/AsyncActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import ActionType, {
import Resource, { ResourceData } from "../model/Resource";
import RdfsResource, {
CONTEXT as RDFS_RESOURCE_CONTEXT,
CustomAttribute,
CustomAttributeData,
RdfsResourceData,
} from "../model/RdfsResource";
import TermItState from "../model/TermItState";
Expand Down Expand Up @@ -1081,7 +1079,10 @@ export function getProperties() {
);
}

function getPropertiesImpl<T extends RdfsResourceData, E extends RdfsResource>(
export function getPropertiesImpl<
T extends RdfsResourceData,
E extends RdfsResource
>(
action: Action,
endpoint: string,
mapper: (data: T) => E,
Expand Down Expand Up @@ -1113,7 +1114,7 @@ export function createProperty(property: RdfsResource) {
return createPropertyImpl(property, action, "/data/properties");
}

function createPropertyImpl(
export function createPropertyImpl(
property: { toJsonLd: () => object },
action: Action,
endpoint: string
Expand All @@ -1139,51 +1140,6 @@ function createPropertyImpl(
};
}

export function getCustomAttributes() {
return getPropertiesImpl<CustomAttributeData, CustomAttribute>(
{ type: ActionType.GET_CUSTOM_ATTRIBUTES },
"/data/custom-attributes",
(d) => new CustomAttribute(d),
() => []
);
}

export function createCustomAttribute(attribute: CustomAttribute) {
return createPropertyImpl(
attribute,
{ type: ActionType.CREATE_CUSTOM_ATTRIBUTE },
"/data/custom-attributes"
);
}

export function updateCustomAttribute(attribute: CustomAttribute) {
const action = { type: ActionType.UPDATE_CUSTOM_ATTRIBUTE };
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action, true));
return Ajax.put(
Constants.API_PREFIX +
"/data/custom-attributes/" +
VocabularyUtils.create(attribute.iri).fragment,
content(attribute.toJsonLd())
)
.then(() => {
dispatch(asyncActionSuccess(action));
dispatch(
publishMessage(
new Message(
{
messageId:
"administration.customization.customAttributes.update.success",
},
MessageType.SUCCESS
)
)
);
})
.catch((error: ErrorData) => dispatch(asyncActionFailure(action, error)));
};
}

export function loadLatestTextAnalysisRecord(resourceIri: IRI) {
const action = {
type: ActionType.LOAD_LATEST_TEXT_ANALYSIS_RECORD,
Expand Down
105 changes: 105 additions & 0 deletions src/action/AsyncCustomizationActions.ts
Comment thread
lukaskabc marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { PageRequest, ThunkDispatch } from "../util/Types";
import {
asyncActionFailure,
asyncActionRequest,
asyncActionSuccess,
publishMessage,
} from "./SyncActions";
import Constants from "../util/Constants";
import Ajax, { content, param } from "../util/Ajax";
import { ErrorData } from "../model/ErrorInfo";
import VocabularyUtils, { IRI } from "../util/VocabularyUtils";
import ActionType from "./ActionType";
import { RdfStatement } from "../model/RdfStatement";
import { CustomAttribute, CustomAttributeData } from "../model/RdfsResource";
import { createPropertyImpl, getPropertiesImpl } from "./AsyncActions";
import Message from "../model/Message";
import MessageType from "../model/MessageType";

export function getCustomAttributes() {
return getPropertiesImpl<CustomAttributeData, CustomAttribute>(
{ type: ActionType.GET_CUSTOM_ATTRIBUTES },
"/data/custom-attributes",
(d) => new CustomAttribute(d),
() => []
);
}

export function createCustomAttribute(attribute: CustomAttribute) {
return createPropertyImpl(
attribute,
{ type: ActionType.CREATE_CUSTOM_ATTRIBUTE },
"/data/custom-attributes"
);
}

export function updateCustomAttribute(attribute: CustomAttribute) {
const action = { type: ActionType.UPDATE_CUSTOM_ATTRIBUTE };
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action, true));
return Ajax.put(
Constants.API_PREFIX +
"/data/custom-attributes/" +
VocabularyUtils.create(attribute.iri).fragment,
content(attribute.toJsonLd())
)
.then(() => {
dispatch(asyncActionSuccess(action));
dispatch(
publishMessage(
new Message(
{
messageId:
"administration.customization.customAttributes.update.success",
},
MessageType.SUCCESS
)
)
);
})
.catch((error: ErrorData) => dispatch(asyncActionFailure(action, error)));
};
}

export function loadCustomAttributeUsage(
attributeIri: IRI,
pageRequest: PageRequest
) {
return (dispatch: ThunkDispatch) => {
const action = { type: ActionType.LOAD_CUSTOM_ATTRIBUTE_USAGE };
dispatch(asyncActionRequest(action, true));
return Ajax.getResponse(
`${Constants.API_PREFIX}/data/custom-attributes/${attributeIri.fragment}/usage`,
param("namespace", attributeIri.namespace)
.param("size", pageRequest.size.toString())
.param("page", pageRequest.page.toString())
)
.then((res) => {
dispatch(asyncActionSuccess(action));
return {
data: res.data as RdfStatement[],
totalStatements: res?.headers[Constants.Headers.X_TOTAL_COUNT] || 0,
};
})
.catch((error: ErrorData) => dispatch(asyncActionFailure(action, error)));
};
}

export function removeCustomAttribute(
attributeIri: IRI,
removeUsages: boolean
) {
return (dispatch: ThunkDispatch) => {
const action = { type: ActionType.REMOVE_CUSTOM_ATTRIBUTE };
dispatch(asyncActionRequest(action, false));
return Ajax.delete(
`${Constants.API_PREFIX}/data/custom-attributes/${attributeIri.fragment}`,
param("namespace", attributeIri.namespace).param(
"removeUsages",
removeUsages.toString()
)
)
.then(() => dispatch(asyncActionSuccess(action)))
.catch((error: ErrorData) => dispatch(asyncActionFailure(action, error)));
};
}
10 changes: 5 additions & 5 deletions src/action/AsyncVocabularyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getApiPrefix } from "./ActionUtils";
import SnapshotData, { CONTEXT as SNAPSHOT_CONTEXT } from "../model/Snapshot";
import NotificationType from "../model/NotificationType";
import ExportConfig from "../model/local/ExportConfig";
import RDFStatement, { RDFSTATEMENT_CONTEXT } from "../model/RDFStatement";
import RdfIriStatement, { RDFSTATEMENT_CONTEXT } from "../model/RdfStatement";
import ChangeRecord, {
CONTEXT as CHANGE_RECORD_CONTEXT,
} from "../model/changetracking/ChangeRecord";
Expand Down Expand Up @@ -293,12 +293,12 @@ export function getVocabularyRelations(
param("namespace", vocabularyIri.namespace).signal(abortController)
)
.then((data) =>
JsonLdUtils.compactAndResolveReferencesAsArray<RDFStatement>(
JsonLdUtils.compactAndResolveReferencesAsArray<RdfIriStatement>(
data,
RDFSTATEMENT_CONTEXT
)
)
.then((statements: RDFStatement[]) => {
.then((statements: RdfIriStatement[]) => {
dispatch(asyncActionSuccess(action));
return statements;
})
Expand All @@ -321,12 +321,12 @@ export function getVocabularyTermsRelations(
param("namespace", vocabularyIri.namespace).signal(abortController)
)
.then((data) =>
JsonLdUtils.compactAndResolveReferencesAsArray<RDFStatement>(
JsonLdUtils.compactAndResolveReferencesAsArray<RdfIriStatement>(
data,
RDFSTATEMENT_CONTEXT
)
)
.then((statements: RDFStatement[]) => {
.then((statements: RdfIriStatement[]) => {
dispatch(asyncActionSuccess(action));
return statements;
})
Expand Down
2 changes: 1 addition & 1 deletion src/action/SearchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function executeAdvancedSearch(
searchParams: SearchParam[],
pageSpec: PageRequest = {
page: 0,
size: Constants.DEFAULT_PAGE_SIZE,
size: Constants.DEFAULT_TREE_SELECT_FETCH_SIZE,
}
) {
return (dispatch: ThunkDispatch) => {
Expand Down
4 changes: 4 additions & 0 deletions src/component/MainView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
vertical-align: text-bottom;
}

.sort-icon {
cursor: pointer;
}

.asset-badge {
width: 4.4rem;
vertical-align: text-bottom !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
createCustomAttribute,
getCustomAttributes,
updateCustomAttribute,
} from "../../../action/AsyncActions";
} from "../../../action/AsyncCustomizationActions";
import PromiseTrackingMask from "../../misc/PromiseTrackingMask";
import { useParams } from "react-router-dom";
import VocabularyUtils from "../../../util/VocabularyUtils";
Expand Down
Loading