From 9740ad78dd0c3c1df0bb67f72ea94a0fcbfd6d91 Mon Sep 17 00:00:00 2001 From: Boris Sekachev <40690378+bsekachev@users.noreply.github.com> Date: Tue, 5 May 2020 22:00:29 +0300 Subject: [PATCH] session.annotations.put() returns indexes of added objects (#1493) * session.annotations.put() returns indexes of added objects * Updated changelog --- CHANGELOG.md | 2 +- cvat-core/src/annotations-collection.js | 2 ++ cvat-core/src/session.js | 1 + cvat-core/tests/api/annotations.js | 16 ++++++++++++---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb98ac4135f1..77c4cb330456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ### Changed -- +- cvat-core: session.annotations.put() now returns identificators of added objects () ### Deprecated - diff --git a/cvat-core/src/annotations-collection.js b/cvat-core/src/annotations-collection.js index d3a7f4ac82a9..1d9fc0fc9b19 100644 --- a/cvat-core/src/annotations-collection.js +++ b/cvat-core/src/annotations-collection.js @@ -806,6 +806,8 @@ object.removed = false; }); }, importedArray.map((object) => object.clientID), objectStates[0].frame); + + return importedArray.map((value) => value.clientID); } select(objectStates, x, y) { diff --git a/cvat-core/src/session.js b/cvat-core/src/session.js index 9643cb1bf173..1726766d3289 100644 --- a/cvat-core/src/session.js +++ b/cvat-core/src/session.js @@ -280,6 +280,7 @@ * @method put * @memberof Session.annotations * @param {module:API.cvat.classes.ObjectState[]} data + * @returns {number[]} identificators of added objects * array of objects on the specific frame * @throws {module:API.cvat.exceptions.PluginError} * @throws {module:API.cvat.exceptions.DataError} diff --git a/cvat-core/tests/api/annotations.js b/cvat-core/tests/api/annotations.js index e02f3c5a6fbb..fca42dd36617 100644 --- a/cvat-core/tests/api/annotations.js +++ b/cvat-core/tests/api/annotations.js @@ -88,8 +88,10 @@ describe('Feature: put annotations', () => { zOrder: 0, }); - await task.annotations.put([state]); + const indexes = await task.annotations.put([state]); annotations = await task.annotations.get(1); + expect(indexes).toBeInstanceOf(Array); + expect(indexes).toHaveLength(1); expect(annotations).toHaveLength(length + 1); }); @@ -108,7 +110,9 @@ describe('Feature: put annotations', () => { zOrder: 0, }); - await job.annotations.put([state]); + const indexes = await job.annotations.put([state]); + expect(indexes).toBeInstanceOf(Array); + expect(indexes).toHaveLength(1); annotations = await job.annotations.get(5); expect(annotations).toHaveLength(length + 1); }); @@ -128,7 +132,9 @@ describe('Feature: put annotations', () => { zOrder: 0, }); - await task.annotations.put([state]); + const indexes = await task.annotations.put([state]); + expect(indexes).toBeInstanceOf(Array); + expect(indexes).toHaveLength(1); annotations = await task.annotations.get(1); expect(annotations).toHaveLength(length + 1); }); @@ -148,7 +154,9 @@ describe('Feature: put annotations', () => { zOrder: 0, }); - await job.annotations.put([state]); + const indexes = await job.annotations.put([state]); + expect(indexes).toBeInstanceOf(Array); + expect(indexes).toHaveLength(1); annotations = await job.annotations.get(5); expect(annotations).toHaveLength(length + 1); });