Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ data class SearchState(
*/
@Parcelize
data class Content(
val displayItems: List<DisplayItem>,
val displayItems: ImmutableList<DisplayItem>,
) : ViewState() {
override val hasVaultFilter: Boolean get() = true
}
Expand Down Expand Up @@ -1188,9 +1188,9 @@ data class SearchState(
val totpCode: String?,
val iconData: IconData,
val extraIconList: ImmutableList<IconData>,
val overflowOptions: List<ListingItemOverflowAction>,
val overflowOptions: ImmutableList<ListingItemOverflowAction>,
val overflowTestTag: String?,
val autofillSelectionOptions: List<AutofillSelectionOption>,
val autofillSelectionOptions: ImmutableList<AutofillSelectionOption>,
val shouldDisplayMasterPasswordReprompt: Boolean,
val itemType: ItemType,
) : Parcelable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import com.x8bit.bitwarden.ui.vault.feature.util.toLabelIcons
import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toLoginIconData
import com.x8bit.bitwarden.ui.vault.util.toSdkCipherType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import java.time.Clock
import java.time.format.FormatStyle

Expand Down Expand Up @@ -199,8 +202,7 @@ fun List<CipherListView>.toViewState(
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
)
.sortAlphabetically(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just got moved into the toDisplayItemList function

),
)
}

Expand All @@ -219,17 +221,20 @@ private fun List<CipherListView>.toDisplayItemList(
isAutofill: Boolean,
isPremiumUser: Boolean,
isArchiveEnabled: Boolean,
): List<SearchState.DisplayItem> =
this.map {
it.toDisplayItem(
baseIconUrl = baseIconUrl,
hasMasterPassword = hasMasterPassword,
isIconLoadingDisabled = isIconLoadingDisabled,
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
)
}
): ImmutableList<SearchState.DisplayItem> =
this
.map {
it.toDisplayItem(
baseIconUrl = baseIconUrl,
hasMasterPassword = hasMasterPassword,
isIconLoadingDisabled = isIconLoadingDisabled,
isAutofill = isAutofill,
isPremiumUser = isPremiumUser,
isArchiveEnabled = isArchiveEnabled,
)
}
.sortAlphabetically()
.toImmutableList()

@Suppress("LongParameterList")
private fun CipherListView.toDisplayItem(
Expand Down Expand Up @@ -263,9 +268,8 @@ private fun CipherListView.toDisplayItem(
// Only valid for autofill
.filter { isAutofill }
// Only Login types get the save option
.filter {
this.login != null || (it != AutofillSelectionOption.AUTOFILL_AND_SAVE)
},
.filter { this.login != null || (it != AutofillSelectionOption.AUTOFILL_AND_SAVE) }
.toImmutableList(),
shouldDisplayMasterPasswordReprompt = hasMasterPassword &&
reprompt == CipherRepromptType.PASSWORD,
itemType = SearchState.DisplayItem.ItemType.Vault(type = this.type.toSdkCipherType()),
Expand Down Expand Up @@ -364,8 +368,7 @@ fun List<SendView>.toViewState(
displayItems = toDisplayItemList(
baseWebSendUrl = baseWebSendUrl,
clock = clock,
)
.sortAlphabetically(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just got moved into the toDisplayItemList function

),
)
}

Expand All @@ -379,13 +382,16 @@ fun List<SendView>.toViewState(
private fun List<SendView>.toDisplayItemList(
baseWebSendUrl: String,
clock: Clock,
): List<SearchState.DisplayItem> =
this.map {
it.toDisplayItem(
baseWebSendUrl = baseWebSendUrl,
clock = clock,
)
}
): ImmutableList<SearchState.DisplayItem> =
this
.map {
it.toDisplayItem(
baseWebSendUrl = baseWebSendUrl,
clock = clock,
)
}
.sortAlphabetically()
.toImmutableList()

private fun SendView.toDisplayItem(
baseWebSendUrl: String,
Expand All @@ -411,7 +417,7 @@ private fun SendView.toDisplayItem(
overflowOptions = toOverflowActions(baseWebSendUrl = baseWebSendUrl),
overflowTestTag = "SendOptionsButton",
totpCode = null,
autofillSelectionOptions = emptyList(),
autofillSelectionOptions = persistentListOf(),
shouldDisplayMasterPasswordReprompt = false,
itemType = SearchState.DisplayItem.ItemType.Sends(type = this.type),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun SendView.toLabelIcons(clock: Clock = Clock.systemDefaultZone()): ImmutableLi
*/
fun SendView.toOverflowActions(
baseWebSendUrl: String,
): List<ListingItemOverflowAction.SendAction> =
): ImmutableList<ListingItemOverflowAction.SendAction> =
this
.id
?.let { sendId ->
Expand All @@ -55,6 +55,7 @@ fun SendView.toOverflowActions(
)
}
.orEmpty()
.toImmutableList()

/**
* Creates a sharable url from a [SendView].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun CipherListView.toOverflowActions(
hasMasterPassword: Boolean,
isPremiumUser: Boolean,
isArchiveEnabled: Boolean,
): List<ListingItemOverflowAction.VaultAction> =
): ImmutableList<ListingItemOverflowAction.VaultAction> =
this
.id
?.let { cipherId ->
Expand Down Expand Up @@ -98,6 +98,7 @@ fun CipherListView.toOverflowActions(
)
}
.orEmpty()
.toImmutableList()

/**
* Checks if the list is empty and if not returns an icon in a list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.x8bit.bitwarden.ui.platform.components.dialog.BitwardenMasterPassword
import com.x8bit.bitwarden.ui.platform.components.listitem.BitwardenGroupItem
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import com.x8bit.bitwarden.ui.vault.feature.vault.handlers.VaultHandlers
import kotlinx.collections.immutable.toImmutableList

private const val TOTP_TYPES_COUNT: Int = 1
private const val HIDDEN_TYPES_COUNT: Int = 2
Expand Down Expand Up @@ -157,7 +156,7 @@ fun VaultContent(
vaultHandlers.vaultItemClick(favoriteItem)
}
},
overflowOptions = favoriteItem.overflowOptions.toImmutableList(),
overflowOptions = favoriteItem.overflowOptions,
onOverflowOptionClick = { action ->
if (favoriteItem.shouldShowMasterPasswordReprompt &&
action.requiresPasswordReprompt
Expand Down Expand Up @@ -359,7 +358,7 @@ fun VaultContent(
vaultHandlers.vaultItemClick(noFolderItem)
}
},
overflowOptions = noFolderItem.overflowOptions.toImmutableList(),
overflowOptions = noFolderItem.overflowOptions,
onOverflowOptionClick = { action ->
if (noFolderItem.shouldShowMasterPasswordReprompt &&
action.requiresPasswordReprompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ data class VaultState(
/**
* The overflow options to be displayed for the vault item.
*/
abstract val overflowOptions: List<ListingItemOverflowAction.VaultAction>
abstract val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>

/**
* Whether to prompt the user for their password when they select an overflow option.
Expand Down Expand Up @@ -1738,7 +1738,7 @@ data class VaultState(
override val startIcon: IconData = IconData.Local(BitwardenDrawable.ic_globe),
override val startIconTestTag: String = "LoginCipherIcon",
override val extraIconList: ImmutableList<IconData> = persistentListOf(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
override val shouldShowMasterPasswordReprompt: Boolean,
override val hasDecryptionError: Boolean,
val username: Text?,
Expand All @@ -1762,7 +1762,7 @@ data class VaultState(
),
override val startIconTestTag: String = "CardCipherIcon",
override val extraIconList: ImmutableList<IconData> = persistentListOf(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
override val shouldShowMasterPasswordReprompt: Boolean,
override val hasDecryptionError: Boolean,
private val brand: VaultCardBrand? = null,
Expand Down Expand Up @@ -1795,7 +1795,7 @@ data class VaultState(
override val startIcon: IconData = IconData.Local(BitwardenDrawable.ic_id_card),
override val startIconTestTag: String = "IdentityCipherIcon",
override val extraIconList: ImmutableList<IconData> = persistentListOf(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
override val hasDecryptionError: Boolean,
override val shouldShowMasterPasswordReprompt: Boolean,
val fullName: Text?,
Expand All @@ -1815,7 +1815,7 @@ data class VaultState(
override val startIcon: IconData = IconData.Local(BitwardenDrawable.ic_note),
override val startIconTestTag: String = "SecureNoteCipherIcon",
override val extraIconList: ImmutableList<IconData> = persistentListOf(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
override val hasDecryptionError: Boolean,
override val shouldShowMasterPasswordReprompt: Boolean,
) : VaultItem() {
Expand All @@ -1833,7 +1833,7 @@ data class VaultState(
override val startIcon: IconData = IconData.Local(BitwardenDrawable.ic_ssh_key),
override val startIconTestTag: String = "SshKeyCipherIcon",
override val extraIconList: ImmutableList<IconData> = persistentListOf(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
override val shouldShowMasterPasswordReprompt: Boolean,
override val hasDecryptionError: Boolean,
) : VaultItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
import com.x8bit.bitwarden.ui.vault.feature.vault.VaultState
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
import com.x8bit.bitwarden.ui.vault.model.findVaultCardBrandWithNameOrNull
import kotlinx.collections.immutable.persistentListOf

private const val ANDROID_URI = "androidapp://"
private const val IOS_URI = "iosapp://"
Expand Down Expand Up @@ -304,7 +305,7 @@ private fun CipherListView.toVaultItemOrNull(
usePasskeyDefaultIcon = false,
),
overflowOptions = if (hasDecryptionError) {
emptyList()
persistentListOf()
} else {
toOverflowActions(
hasMasterPassword = hasMasterPassword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -226,7 +227,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1),
),
),
Expand All @@ -241,7 +242,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1),
),
),
Expand Down Expand Up @@ -417,7 +418,7 @@ class SearchScreenTest : BitwardenComposeTest() {
fun `clicking on item when reprompt is required should show master password dialog`() {
mutableStateFlow.value = DEFAULT_STATE.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1).copy(
shouldDisplayMasterPasswordReprompt = true,
),
Expand Down Expand Up @@ -595,7 +596,9 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(createMockDisplayItemForCipher(number = number)),
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = number),
),
),
)
}
Expand All @@ -617,7 +620,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(createMockDisplayItemForCipher(number = 1)),
displayItems = persistentListOf(createMockDisplayItemForCipher(number = 1)),
),
)
}
Expand Down Expand Up @@ -754,7 +757,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1)
.copy(shouldDisplayMasterPasswordReprompt = true),
),
Expand Down Expand Up @@ -783,7 +786,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1)
.copy(shouldDisplayMasterPasswordReprompt = true),
),
Expand Down Expand Up @@ -832,7 +835,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(createMockDisplayItemForSend(number = number)),
displayItems = persistentListOf(createMockDisplayItemForSend(number = number)),
),
)
}
Expand All @@ -854,7 +857,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(createMockDisplayItemForSend(number = 1)),
displayItems = persistentListOf(createMockDisplayItemForSend(number = 1)),
),
)
}
Expand Down Expand Up @@ -962,7 +965,7 @@ class SearchScreenTest : BitwardenComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(createMockDisplayItemForSend(number = 1)),
displayItems = persistentListOf(createMockDisplayItemForSend(number = 1)),
),
)
}
Expand Down Expand Up @@ -1079,12 +1082,11 @@ private fun createStateForAutofill(
): SearchState = DEFAULT_STATE
.copy(
viewState = SearchState.ViewState.Content(
displayItems = listOf(
createMockDisplayItemForCipher(number = 1)
.copy(
autofillSelectionOptions = AutofillSelectionOption.entries,
shouldDisplayMasterPasswordReprompt = isRepromptRequired,
),
displayItems = persistentListOf(
createMockDisplayItemForCipher(number = 1).copy(
autofillSelectionOptions = AutofillSelectionOption.entries.toImmutableList(),
shouldDisplayMasterPasswordReprompt = isRepromptRequired,
),
),
),
)
Loading
Loading