-
Notifications
You must be signed in to change notification settings - Fork 4
/
MetadataServices.tsx
89 lines (83 loc) · 2.93 KB
/
MetadataServices.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from "react";
import EditableConfigList, {
EditableConfigListStateProps,
EditableConfigListDispatchProps,
EditableConfigListOwnProps,
} from "./EditableConfigList";
import { connect } from "react-redux";
import ActionCreator from "../actions";
import { MetadataServicesData, MetadataServiceData } from "../interfaces";
import ServiceEditForm from "./ServiceEditForm";
/** Right panel for metadata services on the system configuration page.
Shows a list of current metadata services and allows creating a new
service or editing or deleting an existing service. */
export class MetadataServices extends EditableConfigList<
MetadataServicesData,
MetadataServiceData
> {
EditForm = ServiceEditForm;
listDataKey = "metadata_services";
itemTypeName = "metadata service";
urlBase = "/admin/web/config/metadata/";
identifierKey = "id";
labelKey = "protocol";
links = this.renderLinks();
renderLinks(): { [key: string]: JSX.Element } {
const linkBase = "/admin/web/troubleshooting/self-tests/metadataServices";
const linkElement = <a href={linkBase}>the troubleshooting page</a>;
return {
info: (
<>
Self-tests for the metadata services have been moved to {linkElement}.
</>
),
footer: (
<>Problems with your metadata services? Please visit {linkElement}.</>
),
};
}
label(item): string {
const label = item.name ? `${item.name}: ${item.protocol}` : item.protocol;
return label;
}
}
function mapStateToProps(state, ownProps) {
const data = Object.assign(
{},
(state.editor.metadataServices && state.editor.metadataServices.data) || {}
);
if (state.editor.libraries && state.editor.libraries.data) {
data.allLibraries = state.editor.libraries.data.libraries;
}
// fetchError = an error involving loading the list of metadata services; formError = an error upon submission of the
// create/edit form.
return {
data: data,
responseBody:
state.editor.metadataServices &&
state.editor.metadataServices.successMessage,
fetchError: state.editor.metadataServices.fetchError,
formError: state.editor.metadataServices.formError,
isFetching:
state.editor.metadataServices.isFetching ||
state.editor.metadataServices.isEditing,
};
}
function mapDispatchToProps(dispatch, ownProps) {
const actions = new ActionCreator(null, ownProps.csrfToken);
return {
fetchData: () => dispatch(actions.fetchMetadataServices()),
editItem: (data: FormData) => dispatch(actions.editMetadataService(data)),
deleteItem: (identifier: string | number) =>
dispatch(actions.deleteMetadataService(identifier)),
};
}
const ConnectedMetadataServices = connect<
EditableConfigListStateProps<MetadataServicesData>,
EditableConfigListDispatchProps<MetadataServicesData>,
EditableConfigListOwnProps
>(
mapStateToProps,
mapDispatchToProps
)(MetadataServices);
export default ConnectedMetadataServices;