Skip to content

Commit 0be81c6

Browse files
huglxJanCizmar
andauthored
fix: activity label zero keys (tolgee#2433)
- do not show activities with an empty list of modified entities --------- Co-authored-by: Jan Cizmar <cizmar@chlupac.com>
1 parent 86d1589 commit 0be81c6

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/ProjectActivityControllerTest.kt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package io.tolgee.api.v2.controllers
22

33
import io.tolgee.ProjectAuthControllerTest
44
import io.tolgee.development.testDataBuilder.data.dataImport.ImportTestData
5-
import io.tolgee.fixtures.andAssertThatJson
6-
import io.tolgee.fixtures.andIsOk
7-
import io.tolgee.fixtures.isValidId
8-
import io.tolgee.fixtures.node
5+
import io.tolgee.fixtures.*
96
import io.tolgee.model.activity.ActivityRevision
107
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod
118
import net.javacrumbs.jsonunit.assertj.JsonAssert
@@ -41,6 +38,54 @@ class ProjectActivityControllerTest : ProjectAuthControllerTest("/v2/projects/")
4138
}
4239
}
4340

41+
@Test
42+
@ProjectJWTAuthTestMethod
43+
fun `returns no activity while 0 tags are added to the key`() {
44+
val keyTag = "tag"
45+
val key = testData.addKeyWithTag(keyTag)
46+
testDataService.saveTestData(testData.root)
47+
48+
performProjectAuthPost("start-batch-job/tag-keys", mapOf("keyIds" to listOf(key.id), "tags" to listOf(keyTag)))
49+
.andIsOk
50+
51+
waitForNotThrowing(timeout = 1000) {
52+
val revisionsWithTag =
53+
findBatchTagKeysActivityRevisions()
54+
55+
assert(revisionsWithTag.isEmpty())
56+
}
57+
}
58+
59+
@Test
60+
@ProjectJWTAuthTestMethod
61+
fun `returns activity while 1 or more tags are added to the key`() {
62+
val key = testData.addKeyWithTag("tag")
63+
testDataService.saveTestData(testData.root)
64+
65+
performProjectAuthPost(
66+
"start-batch-job/tag-keys",
67+
mapOf("keyIds" to listOf(key.id), "tags" to listOf("tag1", "tag2", "tag3")),
68+
)
69+
.andIsOk
70+
71+
waitForNotThrowing(timeout = 1000) {
72+
val revisionsWithTag =
73+
findBatchTagKeysActivityRevisions()
74+
75+
assert(revisionsWithTag.isNotEmpty())
76+
}
77+
}
78+
79+
fun findBatchTagKeysActivityRevisions(): List<ActivityRevision> {
80+
return entityManager.createQuery(
81+
"""
82+
select ar from ActivityRevision ar
83+
where ar.type = 'BATCH_TAG_KEYS' and ar.authorId = ${testData.userAccount.id}
84+
""".trimIndent(),
85+
ActivityRevision::class.java,
86+
).resultList
87+
}
88+
4489
private fun JsonAssert.assertCountsOnlyResult() {
4590
node("modifiedEntities").isNull()
4691
node("counts") {

backend/data/src/main/kotlin/io/tolgee/activity/ActivityService.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class ActivityService(
3737
activityRevision: ActivityRevision,
3838
modifiedEntities: ModifiedEntitiesType,
3939
) {
40+
if (!activityRevision.shouldSaveWithoutModification() && modifiedEntities.isEmpty()) {
41+
return
42+
}
43+
4044
// let's keep the persistent context small
4145
entityManager.flushAndClear()
4246

@@ -156,4 +160,9 @@ class ActivityService(
156160
ModificationsByRevisionsProvider(applicationContext, projectId, listOf(revisionId), pageable, filterEntityClass)
157161
return provider.get()
158162
}
163+
164+
private fun ActivityRevision.shouldSaveWithoutModification(): Boolean {
165+
val type = this.type ?: return true
166+
return type.saveWithoutModification
167+
}
159168
}

backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/dataImport/ImportTestData.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ class ImportTestData {
210210
return user.self
211211
}
212212

213+
fun addKeyWithTag(keyTag: String): io.tolgee.model.key.Key {
214+
return this.projectBuilder.addKey {
215+
name = "key with tag"
216+
this.keyMeta
217+
}.build {
218+
addTag(keyTag)
219+
}.self
220+
}
221+
213222
fun useViewEnOnlyUser(): UserAccount {
214223
val user =
215224
this.root.addUserAccount {

webapp/src/component/activity/ActivityTitle.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const ActivityTitle: React.FC<Props> = ({ activity }) => {
3333
KeyCount: 0,
3434
TranslationCount: 0,
3535
KeyMeta: 0,
36+
KeyMetaCount: 0,
3637
};
3738

3839
Object.entries(activity.counts || {}).forEach(([entity, value]) => {

0 commit comments

Comments
 (0)