forked from folio-org/stripes-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditableList.js
54 lines (49 loc) · 1.33 KB
/
EditableList.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
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import EditableListForm from './EditableListForm';
const propTypes = {
/**
* maps column fields to strings that should be rendered in the list headers.
*/
columnMapping: PropTypes.object,
/**
* set custom column widths.
*/
columnWidths: PropTypes.object,
/**
* Array of objects to be rendered as list items.
*/
contentData: PropTypes.arrayOf(PropTypes.object).isRequired,
/**
* set custom component for editing
*/
fieldComponents: PropTypes.object,
/**
* Used to render custom components within the cells of the list.
*/
formatter: PropTypes.object,
/**
* id for add button
*/
id: PropTypes.string,
/**
* The key that uniquely names listed objects: defaults to 'name'.
*/
nameKey: PropTypes.string,
/**
* Readonly fields that will not be editable.
*/
readOnlyFields: PropTypes.arrayOf(PropTypes.string),
};
const defaultProps = {
nameKey: 'name',
};
const EditableList = (props) => {
const { contentData, nameKey } = props;
const items = _.sortBy(contentData, [t => t[nameKey] && t[nameKey].toLowerCase()]);
return (<EditableListForm initialValues={{ items }} {...props} />);
};
EditableList.propTypes = propTypes;
EditableList.defaultProps = defaultProps;
export default EditableList;