Skip to content

Commit 5eb99f0

Browse files
committed
CCKEY-204 Added colorpicker to tag modal
React-color component library used in the tag modal, showing sample tag in the tag table
1 parent 537b4e2 commit 5eb99f0

File tree

4 files changed

+68
-32
lines changed

4 files changed

+68
-32
lines changed

package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"prop-type": "latest",
4343
"rc-queue-anim": "1.0.4",
4444
"react": "15.4.2",
45+
"react-color": "2.13.8",
4546
"react-copy-to-clipboard": "5.0.0",
4647
"react-dom": "15.4.2",
4748
"react-file-download": "0.3.4",

src/components/data/TagModal.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import {Button, Col, Form, Icon, Input, Modal, Row, Tooltip} from "antd";
4+
import { SliderPicker } from "react-color";
45
import "antd/lib/button/style/index.less";
56
import "antd/lib/checkbox/style/index.less";
67
import "antd/lib/col/style/css";
@@ -18,7 +19,7 @@ import "./TagModal.less";
1819
*/
1920
const ManagedForm = Form.create()(
2021
(props) => {
21-
const {administrationMode, tag, creationMode, form} = props;
22+
const {tag, creationMode, form, colorPicker} = props;
2223
const {getFieldDecorator} = form;
2324

2425
return (
@@ -34,26 +35,11 @@ const ManagedForm = Form.create()(
3435
})(
3536
<Input
3637
addonBefore="Name"
37-
readOnly={!administrationMode}
3838
/>
3939
)}
4040
</Form.Item>
41-
<Form.Item
42-
{...managedFormItemLayout}
43-
validateStatus={form.getFieldError("color") ? "error" : ""}
44-
colon={false}
45-
>
46-
{getFieldDecorator("color", {
47-
initialValue: tag.name,
48-
rules: [{required: true, message: "Color is required"}]
49-
})(
50-
<Input
51-
addonBefore="Color"
52-
readOnly={!administrationMode}
53-
/>
54-
)}
55-
</Form.Item>
56-
{!creationMode && administrationMode &&
41+
{colorPicker()}
42+
{!creationMode &&
5743
<div>
5844
<Form.Item {...managedFormItemLayout}>
5945
<Input
@@ -136,6 +122,7 @@ class TagModal extends React.Component {
136122
constructor(props) {
137123
super(props);
138124
this.state = {
125+
color: props.tag.color ? props.tag.color : "#2ad127"
139126
};
140127
}
141128

@@ -144,6 +131,7 @@ class TagModal extends React.Component {
144131
*/
145132
handleActionButtonOnClick = () => this.form.validateFields((errors, payload) => {
146133
if (!errors) {
134+
payload.color = this.state.color;
147135
this.props.onSave(payload);
148136
this.form.resetFields();
149137
}
@@ -164,9 +152,19 @@ class TagModal extends React.Component {
164152
*/
165153
saveManagedFormRef = (form) => this.form = form;
166154

155+
/**
156+
* Gets the color from the color picker
157+
*
158+
* @param color - The color picked by the user
159+
*/
160+
handleChangeComplete = (color) => {
161+
this.setState({
162+
color: color.hex
163+
});
164+
};
165+
167166
render() {
168167
const {
169-
administrationMode,
170168
creationMode,
171169
loading,
172170
locked,
@@ -189,7 +187,7 @@ class TagModal extends React.Component {
189187
<Row type="flex" align="middle">
190188
<Col span={8}>
191189
<div className="operations">
192-
{!creationMode && administrationMode &&
190+
{!creationMode &&
193191
<Button.Group>
194192
<Button disabled={locked} key="delete" type="danger" ghost={true} size="large" icon="delete" onClick={onDelete}/>
195193
</Button.Group>
@@ -208,6 +206,15 @@ class TagModal extends React.Component {
208206
</div>
209207
);
210208

209+
const colorPicker = () => (
210+
<Form.Item {...managedFormItemLayout} colon={false}>
211+
<SliderPicker
212+
color={this.state.color}
213+
onChangeComplete={this.handleChangeComplete}
214+
/>
215+
</Form.Item>
216+
);
217+
211218
return (
212219
<Modal
213220
id="cckey-components-data-views-tag-modal"
@@ -222,24 +229,19 @@ class TagModal extends React.Component {
222229
<ManagedForm
223230
ref={this.saveManagedFormRef}
224231
tag={tag}
225-
administrationMode={administrationMode}
226232
creationMode={creationMode}
233+
colorPicker={colorPicker}
227234
/>
228235
</Col>
229236
</Row>
230-
{!creationMode && administrationMode && <Row span={4}>{lockStatusButton()}</Row>}
237+
{!creationMode && <Row span={4}>{lockStatusButton()}</Row>}
231238
<Row><Col>{footer()}</Col></Row>
232239
</Modal>
233240
);
234241
}
235242
}
236243

237244
TagModal.propTypes = {
238-
/**
239-
* Indicates if the user group modal is in administration mode.
240-
*/
241-
administrationMode: PropTypes.bool,
242-
243245
/**
244246
* Indicates if the user group modal is in creation mode.
245247
*
@@ -298,7 +300,6 @@ TagModal.propTypes = {
298300
};
299301

300302
TagModal.defaultProps = {
301-
administrationMode: false,
302303
creationMode: false,
303304
loading: false
304305
};

src/routes/administration/TagAdministration.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import update from "immutability-helper";
33
import _ from "lodash";
4-
import {Button, Col, Icon, Row, Table} from "antd";
4+
import {Button, Col, Icon, Row, Table, Tag} from "antd";
55
import {inject, observer, PropTypes as MobXPropTypes} from "mobx-react";
66
import {toJS} from "mobx";
77
import TagModal from "./../../components/data/TagModal";
@@ -13,15 +13,25 @@ import "antd/lib/col/style/css";
1313
import "antd/lib/icon/style/css";
1414
import "antd/lib/row/style/css";
1515
import "antd/lib/table/style/index.less";
16+
import "antd/lib/tag/style/index.less";
1617
import "./TagAdministration.less";
1718
import "./../../BaseLayout.less";
1819

20+
/**
21+
* A tag component to show the color in the table
22+
*
23+
* @param {object} tag - The tag containing the color
24+
* @constructor
25+
*/
26+
export const TAG_TABLE_COLOR_TAG = (tag) =>
27+
<Tag color={tag.color}>{tag.color}</Tag>;
28+
1929
/**
2030
* The default tag table column configuration.
2131
*/
2232
export const TAG_TABLE_DEFAULT_COLUMNS = [
2333
{title: "Name", dataIndex: "name", key: "name", fixed: true},
24-
{title: "Color", dataIndex: "color", key: "color"}
34+
{title: "Color", render: TAG_TABLE_COLOR_TAG}
2535
];
2636

2737
/**
@@ -165,7 +175,7 @@ class TagAdministration extends React.Component {
165175

166176
render() {
167177
const {processing, tag, tagModalCreationMode, tagModalLocked, tagModalVisible} = this.state;
168-
const {authStore, tagStore} = this.props;
178+
const {tagStore} = this.props;
169179

170180
const mainDataView = () => (
171181
<div>
@@ -198,7 +208,6 @@ class TagAdministration extends React.Component {
198208
visible={tagModalVisible}
199209
key={tag.id}
200210
tag={tag}
201-
administrationMode={authStore.privileged}
202211
locked={tagModalLocked}
203212
creationMode={tagModalCreationMode}
204213
loading={processing}

0 commit comments

Comments
 (0)