Skip to content

Commit d76dbc5

Browse files
fixing change to make sure test passes + lint
1 parent 901db49 commit d76dbc5

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

label_studio/tests/data_import/test_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ def test_file_upload_list_empty_ids_returns_empty_for_non_draft_project(business
1313
"""GET file-uploads with ids=[] and non-draft project returns empty list (reopened import modal)."""
1414
# Create project and ensure it is not draft
1515
r = business_client.post(
16-
"/api/projects/",
17-
data=json.dumps({"title": "Test", "label_config": "<View></View>"}),
18-
content_type="application/json",
16+
'/api/projects/',
17+
data=json.dumps({'title': 'Test', 'label_config': '<View></View>'}),
18+
content_type='application/json',
1919
)
2020
assert r.status_code == 201
21-
project_id = r.json()["id"]
21+
project_id = r.json()['id']
2222
project = Project.objects.get(id=project_id)
2323
project.is_draft = False
24-
project.save(update_fields=["is_draft"])
24+
project.save(update_fields=['is_draft'])
2525

2626
# Create a file upload that would appear if we returned "all"
2727
FileUpload.objects.create(
2828
user=business_client.admin,
2929
project=project,
30-
file=ContentFile(b"x", name="upload/test.txt"),
30+
file=ContentFile(b'x', name='upload/test.txt'),
3131
)
3232

3333
# Request with explicit empty ids: must return empty list (no previously imported files)
3434
r = business_client.get(
35-
f"/api/projects/{project_id}/file-uploads",
36-
data={"ids": "[]"},
35+
f'/api/projects/{project_id}/file-uploads',
36+
data={'ids': '[]'},
3737
)
3838
assert r.status_code == 200
3939
assert r.json() == []
@@ -43,19 +43,19 @@ def test_file_upload_list_empty_ids_returns_empty_for_non_draft_project(business
4343
def test_file_upload_list_get_sends_cache_control_no_store(business_client):
4444
"""GET file-uploads response includes Cache-Control: no-store so list is not cached."""
4545
r = business_client.post(
46-
"/api/projects/",
47-
data=json.dumps({"title": "Test", "label_config": "<View></View>"}),
48-
content_type="application/json",
46+
'/api/projects/',
47+
data=json.dumps({'title': 'Test', 'label_config': '<View></View>'}),
48+
content_type='application/json',
4949
)
5050
assert r.status_code == 201
51-
project_id = r.json()["id"]
51+
project_id = r.json()['id']
5252
project = Project.objects.get(id=project_id)
5353
project.is_draft = False
54-
project.save(update_fields=["is_draft"])
54+
project.save(update_fields=['is_draft'])
5555

5656
r = business_client.get(
57-
f"/api/projects/{project_id}/file-uploads",
58-
data={"ids": "[]"},
57+
f'/api/projects/{project_id}/file-uploads',
58+
data={'ids': '[]'},
5959
)
6060
assert r.status_code == 200
61-
assert r.get("Cache-Control") == "no-store"
61+
assert r.get('Cache-Control') == 'no-store'

web/apps/labelstudio/src/pages/CreateProject/Import/Import.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ export const ImportPage = ({
166166
}
167167
if (action.setList !== undefined) {
168168
const list = action.setList ?? [];
169+
if (action.merge) {
170+
return {
171+
...state,
172+
uploaded: unique([...state.uploaded, ...list], (a, b) => a.id === b.id),
173+
ids: unique([...state.ids, ...list.map((f) => f.id)]),
174+
};
175+
}
169176
return {
170177
...state,
171178
uploaded: list,
@@ -214,7 +221,8 @@ export const ImportPage = ({
214221
params: { pk: project.id, ...query },
215222
});
216223

217-
dispatch({ setList: files ?? [] });
224+
const merge = Boolean(file_upload_ids?.length);
225+
dispatch({ setList: files ?? [], merge });
218226
return files;
219227
},
220228
[project?.id],

0 commit comments

Comments
 (0)