Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/headings.tsx
1691 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Headings of the task list:
8
9
- Custom
10
- Due
11
- Changed
12
*/
13
14
import { Row, Col } from "../../antd-bootstrap";
15
import { React } from "../../app-framework";
16
import { Icon, Gap } from "../../components";
17
18
import { HEADINGS, HEADINGS_DIR } from "./headings-info";
19
import { TaskActions } from "./actions";
20
import { Headings as ColumnHeadings, HeadingsDir, Sort } from "./types";
21
22
const NEXT_DIR = {
23
asc: "desc", // since @props.dir is defined, heading is currently selected
24
desc: "asc", // heading currently selected
25
undefined: "asc", // this heading is not selected, so make it selected and asc
26
} as const;
27
28
interface HeadingProps {
29
actions: TaskActions;
30
heading: ColumnHeadings;
31
dir?: HeadingsDir;
32
}
33
34
const Heading: React.FC<HeadingProps> = React.memo(
35
({ actions, heading, dir }) => {
36
return (
37
<a
38
onClick={() => actions.set_sort_column(heading, NEXT_DIR[`${dir}`])}
39
style={{ cursor: "pointer" }}
40
>
41
{heading}
42
{dir != null && (
43
<span>
44
<Gap />
45
{dir == "asc" ? (
46
<Icon name="caret-down" />
47
) : (
48
<Icon name="caret-up" />
49
)}
50
</span>
51
)}
52
</a>
53
);
54
}
55
);
56
57
interface HeadingsProps {
58
actions: TaskActions;
59
sort: Sort;
60
}
61
export const Headings: React.FC<HeadingsProps> = React.memo(
62
({ actions, sort }) => {
63
function render_heading(heading, dir) {
64
return (
65
<Heading actions={actions} key={heading} heading={heading} dir={dir} />
66
);
67
}
68
69
function render_headings() {
70
const column = sort?.get("column") ?? HEADINGS[0];
71
const dir = sort?.get("dir") ?? HEADINGS_DIR[0];
72
// NOTE: we use xs below so that the HEADING columns never wordwrap on
73
// skinny screens, since they are really important for being
74
// able to control the order. On the other hand, if they wrap,
75
// then they use a LOT of vertical space, which is at an extreme
76
// premium for task lists... See
77
// https://github.com/sagemathinc/cocalc/issues/4305
78
// We hide the done column though since it overlaps and we can't
79
// sort by that.
80
return (
81
<Row style={{ borderBottom: "1px solid lightgray", marginLeft: "8px" }}>
82
<Col xs={1} style={{ color: "#666" }}>
83
Drag
84
</Col>
85
<Col xs={7} style={{ color: "#666" }}>
86
Description
87
</Col>
88
<Col xs={1}>
89
{render_heading(
90
HEADINGS[0],
91
column === HEADINGS[0] ? dir : undefined
92
)}
93
</Col>
94
<Col xs={1}>
95
{render_heading(
96
HEADINGS[1],
97
column === HEADINGS[1] ? dir : undefined
98
)}
99
</Col>
100
<Col xs={1}>
101
{render_heading(
102
HEADINGS[2],
103
column === HEADINGS[2] ? dir : undefined
104
)}
105
</Col>
106
<Col
107
xs={1}
108
style={{ color: "#666", textAlign: "center" }}
109
className={"visible-sm-inline visible-md-inline visible-lg-inline"}
110
>
111
Done
112
</Col>
113
</Row>
114
);
115
}
116
117
return <div style={{ padding: "0 10px" }}>{render_headings()}</div>;
118
}
119
);
120
121