-
Notifications
You must be signed in to change notification settings - Fork 4
/
Lane.tsx
170 lines (159 loc) · 4.89 KB
/
Lane.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import * as React from "react";
import { LaneData } from "../interfaces";
import { Link } from "react-router";
import GrabIcon from "./icons/GrabIcon";
import PyramidIcon from "./icons/PyramidIcon";
import VisibleIcon from "./icons/VisibleIcon";
import HiddenIcon from "./icons/HiddenIcon";
import AddIcon from "./icons/AddIcon";
import PencilIcon from "./icons/PencilIcon";
import { Button } from "library-simplified-reusable-components";
export interface LaneProps {
lane: LaneData;
active: boolean;
snapshot?: any;
provided?: any;
orderChanged: boolean;
toggleLaneVisibility: (
lane: LaneData,
shouldBeVisible: boolean
) => Promise<void>;
parent?: LaneData;
library: string;
renderLanes: (lanes: LaneData[], parent: LaneData | null) => JSX.Element;
}
export interface LaneState {
expanded: boolean;
visible: boolean;
}
// Individual list elements appearing in the sidebar on the Lane Manager page
export default class Lane extends React.Component<LaneProps, LaneState> {
constructor(props: LaneProps) {
super(props);
// Top-level lanes start out expanded.
this.state = {
expanded: !this.props.parent,
visible: this.props.lane.visible,
};
this.toggleExpanded = this.toggleExpanded.bind(this);
this.toggleVisible = this.toggleVisible.bind(this);
this.renderVisibilityToggle = this.renderVisibilityToggle.bind(this);
this.renderButton = this.renderButton.bind(this);
}
render(): JSX.Element {
const { lane, active, snapshot, provided, renderLanes } = this.props;
const hasSublanes = lane.sublanes && !!lane.sublanes.length;
return (
<li key={lane.id}>
<div
className={
"lane-parent" +
(snapshot && snapshot.isDragging ? "dragging " : " ") +
(active ? "active" : "")
}
ref={provided && provided.innerRef}
style={provided && provided.draggableStyle}
{...(provided ? provided.dragHandleProps : {})}
>
<div className={"lane-info" + (provided ? " draggable" : "")}>
<span>
{snapshot && <GrabIcon />}
<Button
className={`transparent ${
this.state.expanded ? "collapse-button" : "expand-button"
}`}
type="button"
callback={this.toggleExpanded}
aria-label={`Button to expand or collapse a lane`}
content={<PyramidIcon />}
/>
{lane.display_name + " (" + lane.count + ")"}
</span>
{this.renderVisibilityToggle()}
</div>
{this.state.expanded && (
<div className="lane-buttons">
{this.renderButton("edit")}
{this.renderButton("create")}
</div>
)}
{this.state.expanded &&
hasSublanes &&
renderLanes(lane.sublanes, lane)}
</div>
{provided && provided.placeholder}
</li>
);
}
UNSAFE_componentWillReceiveProps(newProps) {
this.setState({
expanded: this.state.expanded,
visible: newProps.lane.visible,
});
}
toggleVisible(): void {
const change = !this.state.visible;
this.props.toggleLaneVisibility(this.props.lane, change);
this.setState({ expanded: this.state.expanded, visible: change });
}
renderVisibilityToggle(): JSX.Element {
// If the lane order is currently being changed, or if this lane has a parent which is hidden, disable the toggle.
const parentHidden = this.props.parent && !this.props.parent.visible;
const canToggle = !this.props.orderChanged && !parentHidden;
const className = this.state.visible ? "hide-lane" : "show-lane";
const buttonContent = this.state.visible ? (
<span>
Visible
<VisibleIcon />
</span>
) : (
<span>
Hidden
<HiddenIcon />
</span>
);
return (
<Button
className={"small transparent top-align bottom-align " + className}
disabled={!canToggle}
callback={this.toggleVisible}
content={buttonContent}
/>
);
}
renderButton(editOrCreate: string): JSX.Element {
const link = this.props.orderChanged
? null
: `/admin/web/lanes/${this.props.library}/${editOrCreate}/${this.props.lane.id}`;
const content =
editOrCreate === "create" ? (
<span>
Create Sublane
<AddIcon />
</span>
) : (
<span>
Edit Lane
<PencilIcon />
</span>
);
const button = (
<Link
className={
`btn small right-align ${editOrCreate}-lane ` +
(this.props.orderChanged ? "disabled" : "")
}
to={link}
>
{content}
</Link>
);
return button;
}
toggleExpanded(): void {
this.setState({
expanded: !this.state.expanded,
visible: this.state.visible,
});
}
}