forked from ukrbublik/react-awesome-query-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupActions.jsx
More file actions
56 lines (50 loc) · 2.05 KB
/
GroupActions.jsx
File metadata and controls
56 lines (50 loc) · 2.05 KB
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
import React, { PureComponent } from "react";
const groupActionsPositionList = {
topLeft: "group--actions--tl",
topCenter: "group--actions--tc",
topRight: "group--actions--tr",
bottomLeft: "group--actions--bl",
bottomCenter: "group--actions--bc",
bottomRight: "group--actions--br"
};
const defaultPosition = "topRight";
export class GroupActions extends PureComponent {
render() {
const {
config,
addRule, addGroup, removeSelf, setLock, isLocked, isTrueLocked, id,
canAddGroup, canAddRule, canDeleteGroup
} = this.props;
const {
immutableGroupsMode, addRuleLabel, addGroupLabel, delGroupLabel, groupActionsPosition,
renderButton, renderSwitch, renderButtonGroup,
lockLabel, lockedLabel, showLock, canDeleteLocked,
} = config.settings;
const Btn = (pr) => renderButton(pr, config.ctx);
const Switch = (pr) => renderSwitch(pr, config.ctx);
const BtnGrp = (pr) => renderButtonGroup(pr, config.ctx);
const position = groupActionsPositionList[groupActionsPosition || defaultPosition];
const setLockSwitch = showLock && !(isLocked && !isTrueLocked) && <Switch
type="lock" id={id} value={isLocked} setValue={setLock} label={lockLabel} checkedLabel={lockedLabel} config={config}
/>;
const addRuleBtn = !immutableGroupsMode && canAddRule && !isLocked && <Btn
type="addRule" onClick={addRule} label={addRuleLabel} readonly={isLocked} config={config}
/>;
const addGroupBtn = !immutableGroupsMode && canAddGroup && !isLocked && <Btn
type="addGroup" onClick={addGroup} label={addGroupLabel} readonly={isLocked} config={config}
/>;
const delGroupBtn = !immutableGroupsMode && canDeleteGroup && (!isLocked || isLocked && canDeleteLocked) && <Btn
type="delGroup" onClick={removeSelf} label={delGroupLabel} config={config}
/>;
return (
<div className={`group--actions ${position}`}>
<BtnGrp config={config}>
{setLockSwitch}
{addRuleBtn}
{addGroupBtn}
{delGroupBtn}
</BtnGrp>
</div>
);
}
}