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

Commit 5ccf3d3

Browse files
authored
feat: dev-1593: Rejection Dialog (#472)
* dev-1593 * add length checking * BEM
1 parent d524d8c commit 5ccf3d3

File tree

6 files changed

+103
-15
lines changed

6 files changed

+103
-15
lines changed

src/common/Dropdown/DropdownComponent.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import ReactDOM from "react-dom";
33
import { Block, cn } from "../../utils/bem";
44
import { alignElements } from "../../utils/dom";
@@ -91,6 +91,14 @@ export const Dropdown = React.forwardRef(
9191
}
9292
}, [close, currentVisible, open]);
9393

94+
useEffect(() => {
95+
if (visible) {
96+
open();
97+
} else {
98+
close();
99+
}
100+
}, [visible]);
101+
94102
React.useEffect(() => {
95103
if (!ref) return;
96104

src/components/TopBar/Controls.js

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { isDefined } from "../../utils/utilities";
66
import { IconBan } from "../../assets/icons";
77

88
import "./Controls.styl";
9+
import { useCallback, useMemo, useState } from "react";
10+
import { Dropdown } from "../../common/Dropdown/DropdownComponent";
11+
import { FF_DEV_1593, isFF } from "../../utils/feature-flags";
912

1013
const TOOLTIP_DELAY = 0.8;
1114

@@ -28,6 +31,48 @@ const controlsInjector = inject(({ store }) => {
2831
};
2932
});
3033

34+
const RejectDialog = ({ disabled, store }) => {
35+
const [show, setShow] = useState(false);
36+
const [comment, setComment] = useState('');
37+
const onReject = useCallback(() => {
38+
store.rejectAnnotation({ comment: comment.length ? comment : null });
39+
setShow(false);
40+
setComment('');
41+
});
42+
43+
return (
44+
<Dropdown.Trigger
45+
visible={show}
46+
toggle={() => { }}
47+
onToggle={(visible) => {
48+
setShow(visible);
49+
}}
50+
content={(
51+
<Block name="reject-dialog">
52+
<Elem name="input-title">
53+
Reason of Rejection
54+
</Elem>
55+
<Elem
56+
name='input'
57+
tag={'textarea'}
58+
type="text"
59+
value={comment}
60+
onChange={(event) => { setComment(event.target.value); }}
61+
/>
62+
<Elem name='footer' >
63+
<Button onClick={() => setShow(false)}>Cancel</Button>
64+
<Button style={{ marginLeft: 8 }} look="danger" onClick={onReject}>Reject</Button>
65+
</Elem >
66+
</Block >
67+
)}
68+
>
69+
<Button aria-label="reject-annotation" disabled={disabled} look="danger">
70+
Reject
71+
</Button>
72+
</Dropdown.Trigger >
73+
);
74+
};
75+
3176
export const Controls = controlsInjector(observer(({ store, history, annotation }) => {
3277
const isReview = store.hasInterface("review");
3378
const historySelected = isDefined(store.annotationStore.selectedHistory);
@@ -37,14 +82,22 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
3782
const disabled = store.isSubmitting || historySelected;
3883
const submitDisabled = store.hasInterface("annotations:deny-empty") && results.length === 0;
3984

85+
const RejectButton = useMemo(() => {
86+
if (isFF(FF_DEV_1593)) {
87+
return <RejectDialog disabled={disabled} store={store} />;
88+
} else {
89+
return (
90+
<ButtonTooltip key="reject" title="Reject annotation: [ Ctrl+Space ]">
91+
<Button aria-label="reject-annotation" disabled={disabled} look="danger" onClick={store.rejectAnnotation}>
92+
Reject
93+
</Button>
94+
</ButtonTooltip>
95+
);
96+
}
97+
}, [disabled, store]);
98+
4099
if (isReview) {
41-
buttons.push(
42-
<ButtonTooltip key="reject" title="Reject annotation: [ Ctrl+Space ]">
43-
<Button aria-label="reject-annotation" disabled={disabled} look="danger" onClick={store.rejectAnnotation}>
44-
Reject
45-
</Button>
46-
</ButtonTooltip>,
47-
);
100+
buttons.push(RejectButton);
48101

49102
buttons.push(
50103
<ButtonTooltip key="accept" title="Accept annotation: [ Ctrl+Enter ]">

src/components/TopBar/Controls.styl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,25 @@
2626
font-size 16px
2727
box-shadow none
2828
border-radius 0
29+
30+
.reject-dialog
31+
height 278px
32+
width 480px
33+
padding 12px 16px
34+
display flex
35+
flex-direction column
36+
37+
&__input-title
38+
margin-bottom 4px
39+
40+
&__input
41+
resize none
42+
flex 1 1 auto
43+
margin-bottom 16px
44+
background-color #FAFAFA
45+
font-size 16px
46+
47+
&__footer
48+
display flex
49+
flex-direction row
50+
justify-content end

src/regions/VideoRegion.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ const Model = types
128128

129129
closestKeypoint(targetFrame) {
130130
const seq = self.sequence;
131-
let keypoints, result;
131+
let result;
132+
133+
const keypoints = seq.filter(({ frame }) => frame <= targetFrame);
132134

133-
keypoints = seq.filter(({ frame }) => frame <= targetFrame);
134135
result = keypoints[keypoints.length - 1];
135136

136137
if (!result) {

src/stores/AppStore.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export default types
276276
hotkeys.addNamed("annotation:skip", () => {
277277
if (self.annotationStore.viewingAll) return;
278278

279-
if (self.hasInterface("review")){
279+
if (self.hasInterface("review")) {
280280
self.rejectAnnotation();
281281
} else {
282282
self.skipTask();
@@ -393,7 +393,8 @@ export default types
393393
}
394394
self.task = Task.create(taskObject);
395395
if (self.taskHistory.findIndex((x) => x.taskId === self.task.id) === -1) {
396-
self.taskHistory.push({ taskId: self.task.id,
396+
self.taskHistory.push({
397+
taskId: self.task.id,
397398
annotationId: null,
398399
});
399400
}
@@ -501,7 +502,7 @@ export default types
501502
}, "Error during accept, try again");
502503
}
503504

504-
function rejectAnnotation() {
505+
function rejectAnnotation({ comment = null }) {
505506
if (self.isSubmitting) return;
506507

507508
handleSubmittingFlag(async () => {
@@ -513,7 +514,7 @@ export default types
513514
const isDirty = entity.history.canUndo;
514515

515516
entity.dropDraft();
516-
await getEnv(self).events.invoke('rejectAnnotation', self, { isDirty, entity });
517+
await getEnv(self).events.invoke('rejectAnnotation', self, { isDirty, entity, comment });
517518
}, "Error during reject, try again");
518519
}
519520

src/utils/feature-flags.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const FF_DEV_1564_DEV_1565 = "ff_front_dev_1564_dev_1565_shortcuts_focus_
1414
// @requires FF_DEV_1564_DEV_1565
1515
export const FF_DEV_1566 = "ff_front_dev_1566_shortcuts_in_results_010222_short";
1616

17+
// Show or not dialog for rejection
18+
export const FF_DEV_1593 = "ff_front_1593_rejection_comment_040222_short";
19+
1720
function getFeatureFlags() {
1821
return window.APP_SETTINGS?.feature_flags || {};
1922
}
@@ -22,7 +25,7 @@ export function isFF(id) {
2225
const featureFlags = getFeatureFlags();
2326

2427
if (id in featureFlags) {
25-
return featureFlags[id] === true;
28+
return featureFlags[id] === true;
2629
}
2730
else {
2831
return window.APP_SETTINGS?.feature_flags_default_value === true;

0 commit comments

Comments
 (0)