Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 745cddc

Browse files
baigel1hlomzik
andauthored
feat: Add a drag and drop Ranker component and tag (#1207)
* added drag and drop board component and tag * added multi and single column support, revamped styling, changed name to Ranker, and added Ranker example * Update config.xml * changed name to Ranker and added example to correct directory * deleted old rankerboard component files * added support for pre-annotated data * fixed warnings from linter * Fix Ranker result initialization + small linter fixes * Remove old broken Ranker tag * More tiny fixes for good merge * Correct example pre-annotation * Fix resultType and valueType for Ranker Because Ranker is object and has to emulate these properties. * Add sample classnames and example with styles * Fix creating a fresh new annotation There are no deserialization in this case, so let's check pk. * Fix small linting issue * comment and variable changes in response to pr feedback * Remove RankerRegion; we need just classification * Create result not on start, but before submit Also rerender Ranker on every result change. * Fix deleteAllRegions() when toggling draft Remove all checks and extra work. * Fix readonly recursion on Ranker level * Add FF to wrap deleteAllRegion() method fflag_feat_front_lsdv_4832_new_ranker_tag_120423_short * Set Ranker FF to true by default * Add Ranker tag description and attributes list * Update yarn.lock --------- Co-authored-by: hlomzik <[email protected]>
1 parent 2acc4f3 commit 745cddc

File tree

25 files changed

+720
-12
lines changed

25 files changed

+720
-12
lines changed

Diff for: examples/ranker/annotations/1.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"annotations": [
3+
{
4+
"id": "1001",
5+
"result": [
6+
{
7+
"from_name": "ranker",
8+
"id": "beFiQTT1cU",
9+
"source": "$items",
10+
"to_name": "ranker",
11+
"type": "ranker",
12+
"value": {
13+
"ranker": ["1234", "123", "12345", "123456", "1234567"]
14+
}
15+
}
16+
]
17+
}
18+
]
19+
}

Diff for: examples/ranker/config.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<View>
2+
<Style>
3+
.htx-ranker-column { background: cornflowerblue; }
4+
.htx-ranker-item { background: lightgoldenrodyellow; }
5+
</Style>
6+
<Ranker name="ranker" value="$items" mode="rank" title="Search Results"/>
7+
</View>

Diff for: examples/ranker/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import config from './config.xml';
2+
import tasks from './tasks.json';
3+
import annotation from './annotations/1.json';
4+
5+
export const Ranker = { config, tasks, annotation };

Diff for: examples/ranker/tasks.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"data": {
4+
"items":[
5+
{
6+
"title": "item 0 title",
7+
"body": "'item 0 description'",
8+
"id": "123"
9+
},
10+
{
11+
"title": "'item 1 title'",
12+
"body": "'item 1 description'",
13+
"id": "1234"
14+
},
15+
{
16+
"title": "'item 2 title'",
17+
"body": "'item 2 description'",
18+
"id": "12345"
19+
},
20+
{
21+
"title": "'item 3 title'",
22+
"body": "'item 3 description'",
23+
"id": "123456"
24+
},
25+
{
26+
"title": "'item 4 title'",
27+
"body": "'item 4 description'",
28+
"id": "1234567"
29+
}
30+
]},
31+
"predictions": []
32+
}
33+
]

Diff for: examples/table/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<Choice value="Chicken" />
88
<Choice value="Spicy" />
99
</Choices>
10-
</View>
10+
</View>

Diff for: images/screenshots/ranker.png

51.6 KB
Loading

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@
8787
"dependencies": {
8888
"@martel/audio-file-decoder": "2.3.15",
8989
"@thi.ng/rle-pack": "^2.1.6",
90+
"@types/react-beautiful-dnd": "^13.1.3",
9091
"babel-plugin-istanbul": "^6.1.1",
9192
"babel-preset-react-app": "^9.1.1",
9293
"d3": "^5.16.0",
9394
"magic-wand-js": "^1.0.0",
9495
"papaparse": "^5.3.1",
9596
"rc-tree": "^5.3.0",
97+
"react-beautiful-dnd": "^13.1.1",
9698
"react-konva-utils": "^0.2.0",
9799
"react-virtualized-auto-sizer": "^1.0.6",
98100
"react-window": "^1.8.6"

Diff for: public/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@
150150
store.setHistory(annotationHistory)
151151
}
152152
})
153-
153+
ls.on("updateAnnotation", (_, annotation) => {
154+
console.log(annotation.serializeAnnotation());
155+
})
154156
ls.on("regionFinishedDrawing", (region, list) => {
155157
console.log("finish drawing", {region, list})
156158
})

Diff for: src/components/Ranker/Column.tsx

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* components
3+
*/
4+
import { StrictModeDroppable } from './StrictModeDroppable';
5+
import Item from './Item';
6+
import { ColumnData, InputItem } from './createData';
7+
8+
/**
9+
* styles
10+
*/
11+
import styles from './Ranker.module.scss';
12+
/**
13+
* types
14+
*/
15+
interface ColumnProps {
16+
column: ColumnData;
17+
items: InputItem[];
18+
title: string;
19+
}
20+
21+
/*
22+
* defines a column component used by the DragDropBoard component. Each column contains items
23+
* that can be reordered by dragging.
24+
*/
25+
26+
const Column = (props: ColumnProps) => {
27+
const { column, items, title } = props;
28+
29+
return (
30+
<div className={[styles.columnStyle, 'htx-ranker-column'].join(' ')}>
31+
<h1>{title ? title : column.title}</h1>
32+
<StrictModeDroppable droppableId={column.id}>
33+
{provided => (
34+
<div ref={provided.innerRef} {...provided.droppableProps} className={styles.dropAreaStyle}>
35+
{items.map((item, index) => (
36+
<Item key={item.id} item={item} index={index} />
37+
))}
38+
{provided.placeholder}
39+
</div>
40+
)}
41+
</StrictModeDroppable>
42+
</div>
43+
);
44+
};
45+
46+
export default Column;

Diff for: src/components/Ranker/Item.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* libraries
3+
*/
4+
import { Draggable } from 'react-beautiful-dnd';
5+
6+
/**
7+
* components
8+
*/
9+
import { InputItem } from './createData';
10+
11+
/**
12+
* styles
13+
*/
14+
import styles from './Ranker.module.scss';
15+
16+
/**
17+
* types
18+
*/
19+
interface ItemProps {
20+
item: InputItem;
21+
index: number;
22+
}
23+
24+
/**
25+
* Item component represents a draggable item within each column. Items can be dragged within a
26+
* given column as well as between columns.
27+
*/
28+
const Item = (props: ItemProps) => {
29+
const { item, index } = props;
30+
31+
return (
32+
<Draggable draggableId={item.id} index={index}>
33+
{provided => {
34+
return (
35+
<div
36+
{...provided.draggableProps}
37+
{...provided.dragHandleProps}
38+
className={[styles.itemStyle, 'htx-ranker-item'].join(' ')}
39+
ref={provided.innerRef}
40+
>
41+
<h3 className={styles.itemLineStyle}>{item.title}</h3>
42+
<p className={styles.itemLineStyle}>{item.body}</p>
43+
<p className={styles.itemLineStyle}>{item.id}</p>
44+
</div>
45+
);
46+
}}
47+
</Draggable>
48+
);
49+
};
50+
51+
export default Item;

Diff for: src/components/Ranker/Ranker.module.scss

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.rankerBoard {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
background-color: lightgray;
6+
border: 1px solid rgba(34, 36, 38, 0.15);
7+
}
8+
9+
.buttonContainer {
10+
display: flex;
11+
}
12+
13+
.buttonStyle {
14+
margin: 2px;
15+
cursor: pointer;
16+
}
17+
18+
#buttonStyle__removeButton {
19+
background-color: white;
20+
color: #e30615;
21+
}
22+
23+
#buttonStyle__addButton {
24+
background-color: #1a9bf1;
25+
color: white;
26+
}
27+
28+
.boardStyle {
29+
display: flex;
30+
width: 100%;
31+
margin-top: 10px;
32+
background-color: lightgray;
33+
}
34+
35+
.columnsStyle {
36+
display: flex;
37+
justify-content: space-evenly;
38+
width: 100%;
39+
}
40+
41+
.columnStyle {
42+
margin: 10px;
43+
border: 1px solid rgba(34, 36, 38, 0.15);
44+
background-color: white;
45+
padding: 8px;
46+
border-radius: 2px;
47+
display: flex;
48+
flex-direction: column;
49+
align-items: center;
50+
overflow-y: scroll;
51+
box-shadow: 2px 2px 8px #aaa;
52+
}
53+
54+
.itemStyle {
55+
display: flex;
56+
flex-direction: column;
57+
border: 1px solid rgba(34, 36, 38, 0.15);
58+
margin-top: 20px;
59+
padding: 8px;
60+
border-radius: 2px;
61+
background-color: lightgray;
62+
color: black;
63+
width: 250px;
64+
box-shadow: 2px 2px 8px #aaa;
65+
}
66+
67+
.itemLineStyle {
68+
margin: 0;
69+
}
70+
71+
.dropAreaStyle {
72+
min-height: 50%;
73+
min-width: 80%;
74+
display: flex;
75+
flex-direction: column;
76+
align-items: center;
77+
}
78+
79+
@media screen and (max-width: 1520px) {
80+
.itemStyle {
81+
width: 200px;
82+
}
83+
}
84+
85+
@media screen and (max-width: 1000px) {
86+
.itemStyle {
87+
width: 100px;
88+
}
89+
}

0 commit comments

Comments
 (0)