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

examples/ranker/annotations/1.json

Lines changed: 19 additions & 0 deletions
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+
}

examples/ranker/config.xml

Lines changed: 7 additions & 0 deletions
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>

examples/ranker/index.js

Lines changed: 5 additions & 0 deletions
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 };

examples/ranker/tasks.json

Lines changed: 33 additions & 0 deletions
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+
]

examples/table/config.xml

Lines changed: 1 addition & 1 deletion
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>

images/screenshots/ranker.png

51.6 KB
Loading

package.json

Lines changed: 2 additions & 0 deletions
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"

public/index.html

Lines changed: 3 additions & 1 deletion
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
})

src/components/Ranker/Column.tsx

Lines changed: 46 additions & 0 deletions
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;

src/components/Ranker/Item.tsx

Lines changed: 51 additions & 0 deletions
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;

0 commit comments

Comments
 (0)