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

Commit 64c42c5

Browse files
feat: DEV-1621: Add ability to create annotation with pre-created regions (#496)
* feat: DEV-1621: Add ability to create new annotations already with some results from predictions * fix: DEV-1621: Fix default coords in not interactive predictions for images * Use proper FF notation Co-authored-by: Nick Skriabin <[email protected]> Co-authored-by: nicholasrq <[email protected]>
1 parent 5a0a4bf commit 64c42c5

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

src/components/AnnotationTabs/AnnotationTabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const AnnotationTabs = observer(({
7777
}, [as]);
7878

7979
const onCreateAnnotation = useCallback(() => {
80-
const c = as.addAnnotation({ userGenerate: true });
80+
const c = as.createAnnotation();
8181

8282
as.selectAnnotation(c.id);
8383
}, [as]);

src/components/Annotations/Annotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class Annotations extends Component {
223223
size="small"
224224
onClick={ev => {
225225
ev.preventDefault();
226-
const c = store.annotationStore.addAnnotation({ userGenerate: true });
226+
const c = store.annotationStore.createAnnotation();
227227

228228
store.annotationStore.selectAnnotation(c.id);
229229
// c.list.selectAnnotation(c);

src/components/TopBar/Annotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const Annotations = observer(({ store, annotationStore }) => {
105105

106106
const CreateAnnotation = observer(({ annotationStore, onClick }) => {
107107
const onCreateAnnotation = useCallback(() => {
108-
const c = annotationStore.addAnnotation({ userGenerate: true });
108+
const c = annotationStore.createAnnotation();
109109

110110
annotationStore.selectAnnotation(c.id);
111111
onClick();

src/stores/AnnotationStore.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Area from "../regions/Area";
1717
import throttle from "lodash.throttle";
1818
import { ViewModel } from "../tags/visual";
1919
import { UserExtended } from "./UserStore";
20-
import { FF_DEV_1555, isFF } from "../utils/feature-flags";
20+
import { FF_DEV_1555, FF_DEV_1621, isFF } from "../utils/feature-flags";
2121

2222
const hotkeys = Hotkey("Annotations", "Annotations");
2323

@@ -1224,6 +1224,15 @@ export default types
12241224
return self.root;
12251225
}
12261226

1227+
function findNonInteractivePredictionResults() {
1228+
return self.predictions.reduce((results, prediction) => {
1229+
return [
1230+
...results,
1231+
...prediction._initialAnnotationObj.filter(result => result.interactive_mode === false).map(r => ({ ...r })),
1232+
];
1233+
}, []);
1234+
}
1235+
12271236
function createItem(options) {
12281237
const { user, config } = self.store;
12291238

@@ -1285,6 +1294,39 @@ export default types
12851294
return record;
12861295
}
12871296

1297+
function createAnnotation(options = { userGenerate: true }) {
1298+
const result = isFF(FF_DEV_1621) ? findNonInteractivePredictionResults() : [];
1299+
const c = self.addAnnotation({ ...options, result });
1300+
1301+
if (result && result.length) {
1302+
const ids = {};
1303+
1304+
// Area id is <uniq-id>#<annotation-id> to be uniq across all tree
1305+
result.forEach(r => {
1306+
if ("id" in r) {
1307+
const id = r.id.replace(/#.*$/, `#${c.id}`);
1308+
1309+
ids[r.id] = id;
1310+
r.id = id;
1311+
}
1312+
});
1313+
1314+
result.forEach(r => {
1315+
if (r.parent_id) {
1316+
if (ids[r.parent_id]) r.parent_id = ids[r.parent_id];
1317+
// impossible case but to not break the app better to reset it
1318+
else r.parent_id = null;
1319+
}
1320+
});
1321+
1322+
selectAnnotation(c.id);
1323+
c.deserializeAnnotation(result);
1324+
// reinit will trigger `updateObjects()` so we omit it here
1325+
c.reinitHistory();
1326+
}
1327+
return c;
1328+
}
1329+
12881330

12891331
function addHistory(options = {}) {
12901332
options.type = "history";
@@ -1404,6 +1446,7 @@ export default types
14041446

14051447
addPrediction,
14061448
addAnnotation,
1449+
createAnnotation,
14071450
addAnnotationFromPrediction,
14081451
addHistory,
14091452
clearHistory,

src/utils/feature-flags.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const FF_DEV_1536 = "ff_front_dev_1536_taxonomy_user_labels_150222_long";
2020
// Show or not dialog for rejection
2121
export const FF_DEV_1593 = "ff_front_1593_rejection_comment_040222_short";
2222

23+
// Add an interactivity flag to the results to make some predictions' results be able to be automatically added to newly created annotations.
24+
export const FF_DEV_1621 = "ff_front_dev_1621_interactive_mode_150222_short";
25+
2326
function getFeatureFlags() {
2427
return window.APP_SETTINGS?.feature_flags || {};
2528
}
@@ -28,7 +31,7 @@ export function isFF(id) {
2831
const featureFlags = getFeatureFlags();
2932

3033
if (id in featureFlags) {
31-
return featureFlags[id] === true;
34+
return featureFlags[id] === true;
3235
} else {
3336
return window.APP_SETTINGS?.feature_flags_default_value === true;
3437
}

0 commit comments

Comments
 (0)