2019-12-18 10:22:44 -07:00
|
|
|
import React from "react";
|
2019-12-18 11:45:29 -07:00
|
|
|
import { BlurableInput, ColorPicker, Row, Col, ToolTip } from "../ui";
|
2019-12-13 14:26:57 -07:00
|
|
|
import {
|
|
|
|
FolderUnion,
|
|
|
|
FolderItemProps,
|
|
|
|
FolderNodeProps,
|
|
|
|
FolderProps,
|
2019-12-18 12:28:15 -07:00
|
|
|
FolderState,
|
|
|
|
FolderDropButtonProps,
|
|
|
|
AddFolderBtn,
|
|
|
|
AddSequenceProps
|
2019-12-13 14:26:57 -07:00
|
|
|
} from "./constants";
|
2019-12-05 15:40:06 -07:00
|
|
|
import {
|
|
|
|
createFolder,
|
|
|
|
deleteFolder,
|
|
|
|
setFolderName,
|
|
|
|
toggleFolderOpenState,
|
|
|
|
toggleFolderEditState,
|
2019-12-06 08:47:52 -07:00
|
|
|
toggleAll,
|
2019-12-11 08:52:40 -07:00
|
|
|
updateSearchTerm,
|
|
|
|
addNewSequenceToFolder,
|
2019-12-11 12:22:48 -07:00
|
|
|
moveSequence,
|
|
|
|
setFolderColor
|
2019-12-05 15:40:06 -07:00
|
|
|
} from "./actions";
|
2019-12-11 08:52:40 -07:00
|
|
|
import { Link } from "../link";
|
|
|
|
import { urlFriendly } from "../util";
|
|
|
|
import { setActiveSequenceByName } from "../sequences/set_active_sequence_by_name";
|
2019-12-17 17:32:30 -07:00
|
|
|
import { Position, Popover } from "@blueprintjs/core";
|
2019-12-12 15:56:57 -07:00
|
|
|
import { t } from "../i18next_wrapper";
|
2019-12-18 11:45:29 -07:00
|
|
|
import { ToolTips } from "../constants";
|
2019-12-04 15:42:27 -07:00
|
|
|
|
2019-12-17 16:37:05 -07:00
|
|
|
const FolderListItem = (props: FolderItemProps) => {
|
2019-12-11 08:52:40 -07:00
|
|
|
const { sequence, onClick } = props;
|
2019-12-17 13:19:17 -07:00
|
|
|
const url = `/app/sequences/${urlFriendly(sequence.body.name) || ""}`;
|
2019-12-18 10:33:23 -07:00
|
|
|
const style = props.isMoveTarget ? { border: "1px solid red" } : {};
|
|
|
|
return <li style={style}>
|
2019-12-18 12:28:15 -07:00
|
|
|
<i onClick={() => onClick(sequence.uuid)} className="fa fa-lg fa-arrows">{""}</i>
|
2019-12-17 13:19:17 -07:00
|
|
|
<Link to={url} key={sequence.uuid} onClick={setActiveSequenceByName}>
|
2019-12-18 10:33:23 -07:00
|
|
|
{sequence.body.name}
|
2019-12-11 08:52:40 -07:00
|
|
|
</Link>
|
|
|
|
</li>;
|
2019-12-09 07:48:52 -07:00
|
|
|
};
|
2019-12-04 13:01:49 -07:00
|
|
|
|
2019-12-17 16:37:05 -07:00
|
|
|
const DropFolderHereBtn = (props: FolderDropButtonProps) => {
|
2019-12-17 15:25:08 -07:00
|
|
|
if (props.active) {
|
2019-12-18 10:33:23 -07:00
|
|
|
return <button className="drag-drop-area visible" onClick={props.onClick}>
|
2019-12-18 12:28:15 -07:00
|
|
|
Move sequence here
|
2019-12-18 10:33:23 -07:00
|
|
|
</button>;
|
2019-12-17 15:25:08 -07:00
|
|
|
} else {
|
|
|
|
return <span />;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const AddFolderBtn = ({ folder }: AddFolderBtn) => {
|
2019-12-18 12:28:15 -07:00
|
|
|
return <div
|
|
|
|
title={"Create Subfolder"}
|
|
|
|
onClick={() => createFolder(folder || {})}
|
|
|
|
className="fa-stack">
|
|
|
|
<i className="fa fa-folder fa-stack-1x"></i>
|
|
|
|
<i style={{ color: "gray" }} className="fa fa-plus fa-stack-1x"></i>
|
|
|
|
</div>;
|
2019-12-17 15:25:08 -07:00
|
|
|
};
|
|
|
|
|
2019-12-18 12:28:15 -07:00
|
|
|
const AddSequence = ({ folderId }: AddSequenceProps) => <i
|
|
|
|
className="fa fa-lg fa-server"
|
|
|
|
onClick={() => addNewSequenceToFolder(folderId)} />;
|
2019-12-17 15:25:08 -07:00
|
|
|
|
2019-12-18 10:22:44 -07:00
|
|
|
const FolderButtonCluster = ({ node }: FolderNodeProps) => {
|
2019-12-18 10:57:03 -07:00
|
|
|
return <div style={{ display: "flex" }}>
|
|
|
|
<ColorPicker
|
|
|
|
position={Position.LEFT}
|
|
|
|
onChange={(color) => setFolderColor(node.id, color)}
|
|
|
|
current={node.color} />
|
2019-12-17 16:37:05 -07:00
|
|
|
{node.kind !== "terminal" && <AddFolderBtn folder={{ parent_id: node.id }} />}
|
2019-12-18 12:28:15 -07:00
|
|
|
<i className="fa fa-lg fa-trash" onClick={() => deleteFolder(node.id)} />
|
|
|
|
<i className="fa fa-lg fa-pencil" onClick={() => toggleFolderEditState(node.id)} />
|
2019-12-17 16:37:05 -07:00
|
|
|
<AddSequence folderId={node.id} />
|
|
|
|
</div>;
|
|
|
|
};
|
|
|
|
|
2019-12-18 10:22:44 -07:00
|
|
|
const FolderNameEditor = (props: FolderNodeProps) => {
|
2019-12-18 10:33:23 -07:00
|
|
|
const { node } = props;
|
|
|
|
|
2019-12-17 15:25:08 -07:00
|
|
|
if (props.movedSequenceUuid) {
|
2019-12-17 16:37:05 -07:00
|
|
|
return <DropFolderHereBtn
|
|
|
|
active={true}
|
|
|
|
onClick={() => props.onMoveEnd(node.id)} />;
|
2019-12-17 15:25:08 -07:00
|
|
|
}
|
2019-12-17 17:06:36 -07:00
|
|
|
|
|
|
|
const onCommit = (e: React.SyntheticEvent<HTMLInputElement, Event>) => {
|
|
|
|
const { currentTarget } = e;
|
|
|
|
return setFolderName(node.id, currentTarget.value)
|
|
|
|
.then(() => toggleFolderEditState(node.id));
|
|
|
|
};
|
|
|
|
let namePart: JSX.Element;
|
2019-12-18 10:57:03 -07:00
|
|
|
const btnColor = "fb-btn " + node.color;
|
2019-12-17 17:06:36 -07:00
|
|
|
|
|
|
|
if (node.editing) {
|
|
|
|
namePart = <BlurableInput value={node.name} onCommit={onCommit} />;
|
|
|
|
} else {
|
2019-12-18 10:57:03 -07:00
|
|
|
namePart = <span className={btnColor}>{node.name}</span>;
|
2019-12-17 17:06:36 -07:00
|
|
|
}
|
2019-12-17 17:32:30 -07:00
|
|
|
const buttonPart = <Popover>
|
2019-12-18 12:28:15 -07:00
|
|
|
<i className={btnColor + " fa fa-lg fa-gear"} />
|
2019-12-17 17:32:30 -07:00
|
|
|
<FolderButtonCluster {...props} />
|
|
|
|
</Popover>;
|
2019-12-18 12:28:15 -07:00
|
|
|
const faIcon = ` fa fa-lg fa-chevron-${node.open ? "down" : "right"}`;
|
2019-12-18 10:57:03 -07:00
|
|
|
return <div style={{ display: "flex", cursor: "pointer" }}>
|
2019-12-18 11:45:29 -07:00
|
|
|
<i
|
|
|
|
className={btnColor + faIcon}
|
2019-12-18 10:57:03 -07:00
|
|
|
title={"Open/Close Folder"}
|
|
|
|
onClick={() => toggleFolderOpenState(node.id)}>
|
2019-12-18 11:45:29 -07:00
|
|
|
</i>
|
2019-12-17 17:06:36 -07:00
|
|
|
{buttonPart}
|
2019-12-17 17:32:30 -07:00
|
|
|
{namePart}
|
2019-12-17 17:06:36 -07:00
|
|
|
</div>;
|
2019-12-17 16:37:05 -07:00
|
|
|
};
|
2019-12-17 17:06:36 -07:00
|
|
|
|
2019-12-11 08:52:40 -07:00
|
|
|
const FolderNode = (props: FolderNodeProps) => {
|
|
|
|
const { node, sequences } = props;
|
2019-12-09 07:48:52 -07:00
|
|
|
|
2019-12-11 07:03:21 -07:00
|
|
|
const names = node
|
|
|
|
.content
|
2019-12-17 16:37:05 -07:00
|
|
|
.map(x => <FolderListItem
|
2019-12-11 08:52:40 -07:00
|
|
|
sequence={sequences[x]}
|
|
|
|
key={"F" + x}
|
|
|
|
onClick={props.onMoveStart}
|
|
|
|
isMoveTarget={props.movedSequenceUuid === x} />);
|
2019-12-04 15:42:27 -07:00
|
|
|
|
|
|
|
const children = <ul> {names} </ul>;
|
2019-12-11 08:52:40 -07:00
|
|
|
const mapper = (n2: FolderUnion) => <FolderNode
|
|
|
|
node={n2}
|
|
|
|
key={n2.id}
|
|
|
|
sequences={sequences}
|
|
|
|
movedSequenceUuid={props.movedSequenceUuid}
|
|
|
|
onMoveStart={props.onMoveStart}
|
2019-12-17 15:25:08 -07:00
|
|
|
onMoveEnd={props.onMoveEnd} />;
|
2019-12-09 07:48:52 -07:00
|
|
|
const array: FolderUnion[] = node.children || [];
|
2019-12-17 17:32:30 -07:00
|
|
|
return <div style={{ marginLeft: 10 }}>
|
2019-12-17 13:19:17 -07:00
|
|
|
<Row>
|
2019-12-17 16:37:05 -07:00
|
|
|
<Col xs={12} className="color-picker-col">
|
2019-12-17 17:06:36 -07:00
|
|
|
<FolderNameEditor {...props} />
|
2019-12-17 13:19:17 -07:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2019-12-05 14:52:01 -07:00
|
|
|
{!!node.open && children}
|
2019-12-17 17:32:30 -07:00
|
|
|
{!!node.open && array.map(mapper)}
|
2019-12-04 16:26:16 -07:00
|
|
|
</div>;
|
2019-12-04 15:42:27 -07:00
|
|
|
};
|
2019-12-03 09:32:27 -07:00
|
|
|
|
2019-12-13 14:26:57 -07:00
|
|
|
export class Folders extends React.Component<FolderProps, FolderState> {
|
|
|
|
state: FolderState = { toggleDirection: true };
|
2019-12-05 15:40:06 -07:00
|
|
|
|
2019-12-03 09:32:27 -07:00
|
|
|
Graph = (_props: {}) => {
|
2019-12-12 15:56:57 -07:00
|
|
|
|
2019-11-22 10:43:30 -07:00
|
|
|
return <div>
|
2019-12-12 15:56:57 -07:00
|
|
|
{this.props.rootFolder.folders.map(grandparent => {
|
2019-12-04 15:42:27 -07:00
|
|
|
return <FolderNode
|
|
|
|
node={grandparent}
|
|
|
|
key={grandparent.id}
|
2019-12-11 08:52:40 -07:00
|
|
|
movedSequenceUuid={this.state.movedSequenceUuid}
|
|
|
|
onMoveStart={this.startSequenceMove}
|
|
|
|
onMoveEnd={this.endSequenceMove}
|
2019-12-04 15:42:27 -07:00
|
|
|
sequences={this.props.sequences} />;
|
2019-12-03 09:32:27 -07:00
|
|
|
})}
|
2019-11-22 10:43:30 -07:00
|
|
|
</div>;
|
|
|
|
}
|
2019-12-03 09:32:27 -07:00
|
|
|
|
2019-12-05 15:40:06 -07:00
|
|
|
toggleAll = () => {
|
|
|
|
toggleAll(this.state.toggleDirection);
|
|
|
|
this.setState({ toggleDirection: !this.state.toggleDirection });
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:52:40 -07:00
|
|
|
startSequenceMove = (seqUuid: string) => {
|
|
|
|
this.setState({ movedSequenceUuid: seqUuid });
|
|
|
|
}
|
|
|
|
|
|
|
|
endSequenceMove = (folderId: number) => {
|
|
|
|
moveSequence(this.state.movedSequenceUuid || "", folderId);
|
2019-12-11 09:08:49 -07:00
|
|
|
this.setState({ movedSequenceUuid: undefined });
|
2019-12-11 08:52:40 -07:00
|
|
|
}
|
2019-12-17 15:25:08 -07:00
|
|
|
|
2019-12-13 14:26:57 -07:00
|
|
|
rootSequences = () => this
|
|
|
|
.props
|
|
|
|
.rootFolder
|
|
|
|
.noFolder
|
2019-12-17 16:37:05 -07:00
|
|
|
.map(x => <FolderListItem
|
2019-12-13 14:26:57 -07:00
|
|
|
key={x}
|
|
|
|
sequence={this.props.sequences[x]}
|
|
|
|
onClick={this.startSequenceMove}
|
|
|
|
isMoveTarget={this.state.movedSequenceUuid === x} />);
|
2019-12-11 08:52:40 -07:00
|
|
|
|
2019-12-03 09:32:27 -07:00
|
|
|
render() {
|
2019-12-10 14:46:53 -07:00
|
|
|
return <div>
|
2019-12-18 11:45:29 -07:00
|
|
|
<h3>{t("Sequences")}</h3>
|
|
|
|
<ToolTip helpText={ToolTips.SEQUENCE_LIST} />
|
2019-12-18 11:48:48 -07:00
|
|
|
<div className="thin-search-wrapper">
|
|
|
|
<div className="text-input-wrapper">
|
2019-12-18 12:28:15 -07:00
|
|
|
<i className="fa fa-lg fa-search"></i>
|
2019-12-18 11:48:48 -07:00
|
|
|
<input
|
|
|
|
value={this.props.searchTerm || ""}
|
|
|
|
onChange={({ currentTarget }) => { updateSearchTerm(currentTarget.value); }}
|
|
|
|
type="text"
|
2019-12-18 12:28:15 -07:00
|
|
|
placeholder={t("Search sequences and folders...")} />
|
2019-12-18 11:48:48 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-18 11:45:29 -07:00
|
|
|
<i
|
2019-12-18 12:28:15 -07:00
|
|
|
className={`fa fa-${this.state.toggleDirection ? "plus" : "minus"}-square`}
|
2019-12-18 11:45:29 -07:00
|
|
|
onClick={this.toggleAll}></i>
|
2019-12-17 15:25:08 -07:00
|
|
|
<AddFolderBtn />
|
|
|
|
<AddSequence />
|
2019-12-17 16:37:05 -07:00
|
|
|
<DropFolderHereBtn
|
2019-12-17 15:25:08 -07:00
|
|
|
onClick={() => this.endSequenceMove(0)}
|
|
|
|
active={!!this.state.movedSequenceUuid} />
|
2019-12-18 10:33:23 -07:00
|
|
|
<this.Graph />
|
2019-12-17 15:25:08 -07:00
|
|
|
<ul> {this.rootSequences()} </ul>
|
2019-12-10 14:46:53 -07:00
|
|
|
</div>;
|
2019-12-03 09:32:27 -07:00
|
|
|
}
|
2019-11-22 10:43:30 -07:00
|
|
|
}
|