This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PluginType.js
94 lines (85 loc) · 2.51 KB
/
PluginType.js
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
90
91
92
93
94
// We have to remove node_modules/react to avoid having multiple copies loaded.
// eslint-disable-next-line import/no-unresolved
import React, { PropTypes } from 'react';
import Select from '@folio/stripes-components/lib/Select';
class PluginType extends React.Component {
static propTypes = {
stripes: PropTypes.shape({
logger: PropTypes.shape({
log: PropTypes.func.isRequired,
}).isRequired,
}).isRequired,
data: PropTypes.object.isRequired,
mutator: PropTypes.shape({
recordId: PropTypes.shape({
replace: PropTypes.func,
}),
setting: PropTypes.shape({
POST: PropTypes.func.isRequired,
PUT: PropTypes.func.isRequired,
}),
}).isRequired,
pluginType: PropTypes.string.isRequired,
plugins: PropTypes.arrayOf(
PropTypes.shape({}),
).isRequired,
};
static manifest = Object.freeze({
recordId: {},
setting: {
type: 'okapi',
records: 'configs',
path: 'configurations/entries?query=(module=PLUGINS and config_name=!{pluginType})',
POST: {
path: 'configurations/entries',
},
PUT: {
path: 'configurations/entries/${recordId}', // eslint-disable-line no-template-curly-in-string
},
},
});
constructor(props) {
super(props);
this.changeSetting = this.changeSetting.bind(this);
}
changeSetting(e) {
const value = e.target.value;
this.props.stripes.logger.log('action', `changing preferred '${this.props.pluginType}' plugin to ${value}`);
const record = this.props.data.setting[0];
if (record) {
// Setting has been set previously: replace it
this.props.mutator.recordId.replace(record.id);
record.value = value;
this.props.mutator.setting.PUT(record);
} else {
// No setting: create a new one
this.props.mutator.setting.POST({
module: 'PLUGINS',
config_name: this.props.pluginType,
value,
});
}
}
render() {
const settings = this.props.data.setting || [];
const value = (settings.length === 0) ? '' : settings[0].value;
const options = this.props.plugins.map(p => ({
value: p.module,
label: `${p.displayName} v${p.version}`,
}));
return (
<div>
<b>{this.props.pluginType}</b>
<Select
id={this.props.pluginType}
placeholder="---"
value={value}
dataOptions={options}
onChange={this.changeSetting}
/>
</div>
);
}
}
export default PluginType;