Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Fix of '[FEATURE] Reports by Excluding Tags' #3554

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 86 additions & 24 deletions screen/reports/src/main/java/com/ivy/reports/FilterOverlay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ fun BoxWithConstraintsScope.FilterOverlay(
var maxAmountModalShown by remember { mutableStateOf(false) }
var includeKeywordModalShown by remember { mutableStateOf(false) }
var excludeKeywordModalShown by remember { mutableStateOf(false) }
var tagModalVisible by remember { mutableStateOf(false) }
val selectedTags by remember(localFilter) {
var includedTagModalVisible by remember { mutableStateOf(false) }
var excludedTagModalVisible by remember { mutableStateOf(false) }
val includedTags by remember(localFilter) {
derivedStateOf {
localFilter?.selectedTags?.toImmutableList() ?: persistentListOf()
localFilter?.includedTags?.toImmutableList() ?: persistentListOf()
}
}
val excludedTags by remember(localFilter) {
derivedStateOf {
localFilter?.excludedTags?.toImmutableList() ?: persistentListOf()
}
}

Expand Down Expand Up @@ -272,10 +278,13 @@ fun BoxWithConstraintsScope.FilterOverlay(

FilterDivider()

OthersFilter(
TagsFilter(
filter = localFilter,
onTagButtonClick = {
tagModalVisible = true
onIncludesTagButtonClick = {
includedTagModalVisible = true
},
onExcludesTagButtonClick = {
excludedTagModalVisible = true
}
)

Expand Down Expand Up @@ -396,15 +405,49 @@ fun BoxWithConstraintsScope.FilterOverlay(
}

ShowTagModal(
visible = tagModalVisible,
visible = includedTagModalVisible,
selectOnlyMode = true,
onDismiss = {
includedTagModalVisible = false
// Reset TagList, avoids showing incorrect tag list if user had searched for a tag previously
onTagSearch("")
},
allTagList = allTags,
selectedTagList = includedTags,
onTagAdd = {
// Do Nothing
},
onTagEdit = { oldTag, newTag ->
// Do Nothing
},
onTagDelete = {
// Do Nothing
},
onTagSelected = {
localFilter = nonNullFilter(localFilter).copy(
includedTags = nonNullFilter(localFilter).includedTags.plus(it.id)
)
},
onTagDeSelected = {
localFilter = nonNullFilter(localFilter).copy(
includedTags = nonNullFilter(localFilter).includedTags.minus(it.id)
)
},
onTagSearch = {
onTagSearch(it)
}
)

ShowTagModal(
visible = excludedTagModalVisible,
selectOnlyMode = true,
onDismiss = {
tagModalVisible = false
excludedTagModalVisible = false
// Reset TagList, avoids showing incorrect tag list if user had searched for a tag previously
onTagSearch("")
},
allTagList = allTags,
selectedTagList = selectedTags,
selectedTagList = excludedTags,
onTagAdd = {
// Do Nothing
},
Expand All @@ -416,12 +459,12 @@ fun BoxWithConstraintsScope.FilterOverlay(
},
onTagSelected = {
localFilter = nonNullFilter(localFilter).copy(
selectedTags = nonNullFilter(localFilter).selectedTags.plus(it.id)
excludedTags = nonNullFilter(localFilter).excludedTags.plus(it.id)
)
},
onTagDeSelected = {
localFilter = nonNullFilter(localFilter).copy(
selectedTags = nonNullFilter(localFilter).selectedTags.minus(it.id)
excludedTags = nonNullFilter(localFilter).excludedTags.minus(it.id)
)
},
onTagSearch = {
Expand All @@ -431,18 +474,45 @@ fun BoxWithConstraintsScope.FilterOverlay(
}

@Composable
fun ColumnScope.OthersFilter(
fun ColumnScope.TagsFilter(
filter: ReportFilter?,
onTagButtonClick: () -> Unit,
onIncludesTagButtonClick: () -> Unit,
onExcludesTagButtonClick: () -> Unit,
@Suppress("UnusedParameter") modifier: Modifier = Modifier
) {
FilterTitleText(
text = stringResource(R.string.others_optional),
text = stringResource(R.string.tags_optional),
active = false
)

Spacer(Modifier.height(12.dp))

Text(
modifier = Modifier.padding(start = 32.dp),
text = stringResource(R.string.includes_uppercase),
style = UI.typo.b2.style(
fontWeight = FontWeight.ExtraBold
)
)

TagFilter(
selectedTags = filter?.includedTags?.toImmutableList() ?: persistentListOf(),
onTagButtonClick = onIncludesTagButtonClick,
)

Spacer(Modifier.height(20.dp))

Text(
modifier = Modifier.padding(start = 32.dp),
text = stringResource(R.string.excludes_uppercase),
style = UI.typo.b2.style(
fontWeight = FontWeight.ExtraBold
)
)

TagFilter(
selectedTags = filter?.selectedTags?.toImmutableList() ?: persistentListOf(),
onTagButtonClick = onTagButtonClick,
selectedTags = filter?.excludedTags?.toImmutableList() ?: persistentListOf(),
onTagButtonClick = onExcludesTagButtonClick,
)
}

Expand All @@ -452,14 +522,6 @@ fun ColumnScope.TagFilter(
onTagButtonClick: () -> Unit,
@Suppress("UnusedParameter") modifier: Modifier = Modifier
) {
Text(
modifier = Modifier.padding(start = 32.dp, top = 16.dp),
text = stringResource(R.string.tags),
style = UI.typo.b2.style(
fontWeight = FontWeight.ExtraBold
)
)

Spacer(Modifier.height(12.dp))

if (selectedTags.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ data class ReportFilter(
val maxAmount: Double?,
val includeKeywords: List<String>,
val excludeKeywords: List<String>,
val selectedTags: List<TagId>
val includedTags: List<TagId>,
val excludedTags: List<TagId>,
ILIYANGERMANOV marked this conversation as resolved.
Show resolved Hide resolved

) {
companion object {
fun emptyFilter(
Expand All @@ -33,7 +35,8 @@ data class ReportFilter(
excludeKeywords = emptyList(),
minAmount = null,
maxAmount = null,
selectedTags = emptyList()
includedTags = emptyList(),
excludedTags = emptyList()
)
}

Expand Down
25 changes: 21 additions & 4 deletions screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class ReportViewModel @Inject constructor(
private var overdueExpenses by mutableDoubleStateOf(0.0)
private var history by mutableStateOf<ImmutableList<TransactionHistoryItem>>(persistentListOf())
private var upcomingTransactions by
mutableStateOf<ImmutableList<LegacyTransaction>>(persistentListOf())
mutableStateOf<ImmutableList<LegacyTransaction>>(persistentListOf())
private var overdueTransactions by
mutableStateOf<ImmutableList<LegacyTransaction>>(persistentListOf())
mutableStateOf<ImmutableList<LegacyTransaction>>(persistentListOf())
private var accounts by mutableStateOf<ImmutableList<Account>>(persistentListOf())
private var upcomingExpanded by mutableStateOf(false)
private var overdueExpanded by mutableStateOf(false)
Expand Down Expand Up @@ -375,8 +375,8 @@ class ReportViewModel @Inject constructor(
val filterRange =
filter.period?.toRange(ivyContext.startDayOfMonth, timeConverter, timeProvider)

val transactions = if (filter.selectedTags.isNotEmpty()) {
tagRepository.findByAllAssociatedIdForTagId(filter.selectedTags)
val transactions = if (filter.includedTags.isNotEmpty()) {
tagRepository.findByAllAssociatedIdForTagId(filter.includedTags)
.asSequence()
.flatMap { it.value }
.map { TransactionId(it.associatedId.value) }
Expand All @@ -389,7 +389,24 @@ class ReportViewModel @Inject constructor(
transactionRepository.findAll()
}

val excludeableByTagTransactionsIds = if (filter.excludedTags.isNotEmpty()) {
tagRepository.findByAllAssociatedIdForTagId(filter.excludedTags)
.asSequence()
.flatMap { it.value }
.distinct()
shamim-emon marked this conversation as resolved.
Show resolved Hide resolved
.map { TransactionId(it.associatedId.value) }
.toList()
.let {
transactionRepository.findByIds(it)
}.map {
it.id
}
} else {
emptyList()
}

return transactions
.filter { !excludeableByTagTransactionsIds.contains(it.id) }
.filter {
with(transactionMapper) {
filter.trnTypes.contains(it.getTransactionType())
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
<string name="decrease_loan">Verringern</string>
<string name="msg_select_account_to_transfer">Wähle das Ziel für den Übertrag</string>
<string name="msg_source_account_destination_account_same_for_transfer">Wählen ein anders Ziel-Konto für den Übertrag</string>
<string name="others_optional">Andere (optional)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">Tags</string>
<string name="search_tags">Tags durchsuchen</string>
<string name="exchange_rates">Wechselkurse</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<string name="decrease_loan">Diminuzione</string>
<string name="msg_select_account_to_transfer">Seleziona la destinazione del trasferimento</string>
<string name="msg_source_account_destination_account_same_for_transfer">Selezionare un altro conto come destinazione per il trasferimento</string>
<string name="others_optional">Altro (opzionale)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">Etichette</string>
<string name="search_tags">Tag di Ricerca</string>
<string name="exchange_rates">Tassi di cambio</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<string name="decrease_loan">Diminuir</string>
<string name="msg_select_account_to_transfer">Selecione o destino da transferência</string>
<string name="msg_source_account_destination_account_same_for_transfer">Selecione uma conta de destino diferente para a transferência</string>
<string name="others_optional">Outro (opcional)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">Tags</string>
<string name="search_tags">Pesquisar Tags</string>
<string name="exchange_rates">Taxas de câmbio</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
<string name="decrease_loan">Giảm</string>
<string name="msg_select_account_to_transfer">Chọn tài khoản đích</string>
<string name="msg_source_account_destination_account_same_for_transfer">Chọn một tài khoản đích khác để chuyển</string>
<string name="others_optional">Khác (tùy chọn)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">Thẻ</string>
<string name="search_tags">Tìm thẻ</string>
<string name="exchange_rates">Các tỷ giá hối đoái</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<string name="decrease_loan">减少</string>
<string name="msg_select_account_to_transfer">选择转账目标账户</string>
<string name="msg_source_account_destination_account_same_for_transfer">请选择不同的目标账户进行转账</string>
<string name="others_optional">其他(可选)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">标签</string>
<string name="search_tags">搜索标签</string>
<string name="exchange_rates">汇率</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
<string name="decrease_loan">減少</string>
<string name="msg_select_account_to_transfer">選擇傳輸目的地</string>
<string name="msg_source_account_destination_account_same_for_transfer">選擇不同的目標帳戶進行轉帳</string>
<string name="others_optional">其他 (可選)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">標籤</string>
<string name="search_tags">搜尋標籤</string>
<string name="exchange_rates">匯率</string>
Expand Down
2 changes: 1 addition & 1 deletion shared/ui/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
<string name="decrease_loan">Decrease</string>
<string name="msg_select_account_to_transfer">Select the transfer destination</string>
<string name="msg_source_account_destination_account_same_for_transfer">Select a different destination account for the transfer</string>
<string name="others_optional">Other (optional)</string>
<string name="tags_optional">Tags (optional)</string>
<string name="tags">Tags</string>
<string name="search_tags">Search Tags</string>
<string name="exchange_rates">Exchange rates</string>
Expand Down