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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import io.github.openflocon.flocondesktop.common.db.converters.MapStringsConvert
import kotlinx.coroutines.Dispatchers

@Database(
version = 78,
version = 79,
entities = [
FloconNetworkCallEntity::class,
FileEntity::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ fun MockNetworkUiModel.toDomain(): MockNetworkDomainModel = MockNetworkDomainMod
delay = response.delay,
classPath = response.classPath,
)
}
},
displayName = displayName,
)

fun MockNetworkDomainModel.toUi(): MockNetworkUiModel = MockNetworkUiModel(
Expand All @@ -57,7 +58,8 @@ fun MockNetworkDomainModel.toUi(): MockNetworkUiModel = MockNetworkUiModel(
delay = r.delay,
classPath = r.classPath,
)
}
},
displayName = displayName,
)

fun createEditable(initialMock: SelectedMockUiModel): EditableMockNetworkUiModel = when (initialMock) {
Expand All @@ -81,10 +83,11 @@ fun createEditable(initialMock: MockNetworkUiModel?): EditableMockNetworkUiModel
isShared = initialMock?.isShared ?: false,
responseType = when (initialMock?.response) {
null,
is MockNetworkUiModel.Response.Body -> EditableMockNetworkUiModel.ResponseType.BODY
is MockNetworkUiModel.Response.Body -> ResponseType.BODY

is MockNetworkUiModel.Response.Exception -> EditableMockNetworkUiModel.ResponseType.EXCEPTION
is MockNetworkUiModel.Response.Exception -> ResponseType.EXCEPTION
},
displayName = initialMock?.displayName.orEmpty(),
)

private fun editableBodyResponse(initialMock: MockNetworkUiModel?): EditableMockNetworkUiModel.Response.Body {
Expand Down Expand Up @@ -126,7 +129,8 @@ fun editableToUi(editable: EditableMockNetworkUiModel): Either<Throwable, MockNe
delay = editable.delay,
classPath = editable.exceptionResponse.classPath,
)
}
},
displayName = editable.displayName,
).success()
} catch (t: Throwable) {
t.failure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class MockNetworkUiModel(
val isShared: Boolean, // not displayed
val expectation: Expectation,
val response: Response,
val displayName: String,
) {
data class Expectation(
val urlPattern: String, // a regex
Expand Down Expand Up @@ -39,6 +40,7 @@ data class EditableMockNetworkUiModel(
val responseType: ResponseType,
val exceptionResponse: Response.Exception,
val bodyResponse: Response.Body,
val displayName: String,
) {
data class Expectation(
val urlPattern: String?, // a regex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -32,10 +31,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEach
Expand Down Expand Up @@ -152,6 +149,16 @@ fun MockEditorScreen(
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
)
FloconTextField(
value = mock.displayName,
onValueChange = { newValue ->
mock = mock.copy(displayName = newValue)
},
label = defaultLabel("Display name"),
placeholder = defaultPlaceHolder("Enter a display name"),
modifier = Modifier.fillMaxWidth(),
containerColor = FloconTheme.colorPalette.primary,
Comment thread
nilsjr marked this conversation as resolved.
)
FloconTextField(
value = mock.expectation.urlPattern ?: "",
onValueChange = { newValue ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun MockNetworkDomainModel.toLineUi(): MockNetworkLineUiModel = MockNetworkLineU
urlPattern = expectation.urlPattern,
method = toMockMethodUi(expectation.method),
isShared = isShared,
displayName = displayName,
)

fun toMockMethodUi(text: String): MockNetworkMethodUi = when (text.lowercase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class MockNetworkLineUiModel(
val urlPattern: String,
val isShared: Boolean,
val method: MockNetworkMethodUi,
val displayName: String,
)

fun previewMockNetworkLineUiModel(method: MockNetworkMethodUi = MockNetworkMethodUi.GET) = MockNetworkLineUiModel(
Expand All @@ -18,4 +19,5 @@ fun previewMockNetworkLineUiModel(method: MockNetworkMethodUi = MockNetworkMetho
urlPattern = "http://.*youtube.*v=.*",
method = method,
isShared = false,
displayName = "Mock for YouTube video",
)
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package io.github.openflocon.flocondesktop.features.network.mock.list.view

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.github.openflocon.flocondesktop.features.network.mock.edition.model.MockNetworkMethodUi
import io.github.openflocon.flocondesktop.features.network.mock.edition.view.MockNetworkMethodView
import io.github.openflocon.flocondesktop.features.network.mock.list.model.MockNetworkLineUiModel
Expand All @@ -26,7 +27,6 @@ import io.github.openflocon.library.designsystem.components.FloconCheckbox
import io.github.openflocon.library.designsystem.components.FloconIconButton
import io.github.openflocon.library.designsystem.components.FloconSurface
import io.github.openflocon.library.designsystem.components.FloconSwitch
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
fun MockLineView(
Expand All @@ -38,7 +38,9 @@ fun MockLineView(
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier.padding(vertical = 2.dp),
modifier = modifier
.clickable { onClicked(item.id) }
.padding(vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Box(
Expand All @@ -55,29 +57,42 @@ fun MockLineView(
}

Row(
modifier = Modifier.fillMaxWidth()
.clickable {
onClicked(item.id)
},
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
) {
Box(modifier = Modifier.width(90.dp), contentAlignment = Alignment.Center) {
MockNetworkMethodView(item.method)
}

Text(
text = item.urlPattern,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = FloconTheme.typography.bodySmall.copy(fontSize = 11.sp),
color = FloconTheme.colorPalette.onSurface,
modifier = Modifier.weight(2f)
.background(
color = FloconTheme.colorPalette.primary.copy(alpha = 0.8f),
shape = RoundedCornerShape(4.dp),
if (item.displayName.isEmpty()) {
Text(
text = item.urlPattern,
modifier = Modifier.weight(1f),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = FloconTheme.typography.titleSmall,
color = FloconTheme.colorPalette.onSurface,
)
} else {
Column(Modifier.weight(1f)) {
Text(
text = item.displayName,
modifier = Modifier.fillMaxWidth(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = FloconTheme.typography.titleSmall,
color = FloconTheme.colorPalette.onSurface,
)
.padding(horizontal = 8.dp, vertical = 6.dp),
)
Spacer(Modifier.height(8.dp))
Text(
text = item.urlPattern,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = FloconTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth().alpha(.5f),
)
}
}
Comment on lines +67 to +95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The previous implementation of urlPattern included a distinct background and rounded corners, which helped in visual separation and readability. The current change removes this styling when displayName is empty, and for urlPattern when displayName is present, it's displayed with alpha(.5f). While the new layout with displayName is good, consider if the urlPattern still needs some visual distinction or if its reduced prominence (especially when displayName is empty and it becomes the primary text) affects readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see #513 (comment)
Would say its readable :D


Row(
modifier = Modifier
Expand Down Expand Up @@ -114,6 +129,7 @@ private fun MockLineViewPreview() {
isEnabled = true,
method = MockNetworkMethodUi.GET,
isShared = false,
displayName = "Mock for YouTube video",
),
onClicked = {},
onDeleteClicked = {},
Expand All @@ -136,6 +152,7 @@ private fun MockLineViewPreview_url() {
isEnabled = false,
method = MockNetworkMethodUi.ALL,
isShared = false,
displayName = "Mock for YouTube video",
),
onClicked = {},
onDeleteClicked = {},
Expand All @@ -158,6 +175,7 @@ private fun MockLineViewPreview_url_patch() {
isEnabled = true,
method = MockNetworkMethodUi.PATCH,
isShared = true,
displayName = "Mock for YouTube video",
),
onClicked = {},
onDeleteClicked = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ fun MocksHeaderView(modifier: Modifier = Modifier) {
modifier = Modifier.padding(horizontal = 8.dp).width(50.dp),
)
Text(
"Pattern",
"Method",
textAlign = TextAlign.Center,
style = typo,
color = textColor,
modifier = Modifier.width(90.dp),
)
Text(
"Name / Pattern",
textAlign = TextAlign.Center,
style = typo,
color = textColor,
Comment thread
rteyssandier marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.FileDownload
import androidx.compose.material.icons.outlined.FileUpload
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.github.openflocon.flocondesktop.features.network.mock.NetworkMocksViewModel
Expand All @@ -25,7 +28,6 @@ import io.github.openflocon.library.designsystem.components.FloconButton
import io.github.openflocon.library.designsystem.components.FloconDialogHeader
import io.github.openflocon.library.designsystem.components.FloconDropdownMenuItem
import io.github.openflocon.library.designsystem.components.FloconOverflow
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.viewmodel.koinViewModel

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -125,6 +127,7 @@ private fun NetworkMocksContent(
},
modifier = Modifier.fillMaxWidth(),
)
HorizontalDivider(Modifier.fillMaxWidth(), color = MaterialTheme.colorScheme.outline)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class MockNetworkExportedModel(
val expectation: Expectation,
val response: Response,
val isShared: Boolean,
val displayName: String,
) {
@Serializable
data class Expectation(
Expand Down Expand Up @@ -43,7 +44,8 @@ fun MockNetworkDomainModel.toExportedModel(): MockNetworkExportedModel = MockNet
isEnabled = this.isEnabled,
isShared = this.isShared,
expectation = this.expectation.toExportedModel(),
response = this.response.toExportedModel()
response = this.response.toExportedModel(),
displayName = this.displayName,
)

fun MockNetworkDomainModel.Expectation.toExportedModel(): MockNetworkExportedModel.Expectation = MockNetworkExportedModel.Expectation(
Expand All @@ -70,7 +72,8 @@ fun MockNetworkExportedModel.toDomainModel(): MockNetworkDomainModel = MockNetwo
isEnabled = this.isEnabled,
isShared = this.isShared,
expectation = this.expectation.toDomainModel(),
response = this.response.toDomainModel()
response = this.response.toDomainModel(),
displayName = this.displayName,
)

fun MockNetworkExportedModel.Expectation.toDomainModel(): MockNetworkDomainModel.Expectation = MockNetworkDomainModel.Expectation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fun MockNetworkDomainModel.toEntity(
method = expectation.method,
),
response = response,
displayName = displayName,
)
}

Expand Down Expand Up @@ -63,6 +64,7 @@ fun MockNetworkEntity.toDomain(
),
response = response,
isShared = deviceId == null || packageName == null,
displayName = displayName,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.openflocon.data.local.network.models.mock

import androidx.room.ColumnInfo
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.ForeignKey
Expand Down Expand Up @@ -29,6 +30,8 @@ data class MockNetworkEntity(
@Embedded(prefix = "expectation_")
val expectation: MockNetworkExpectationEmbedded,
val response: String, // saved as json
@ColumnInfo(name = "displayName")
val displayName: String,
)

data class MockNetworkExpectationEmbedded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ data class MockNetworkDomainModel(
val expectation: Expectation,
val response: Response,
val isShared: Boolean,
val displayName: String,
) {
data class Expectation(
val urlPattern: String, // a regex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GenerateNetworkMockFromNetworkCallUseCase(
@OptIn(ExperimentalUuidApi::class)
suspend operator fun invoke(
requestId: String,
): MockNetworkDomainModel? = getCurrentDeviceIdAndPackageNameUseCase()?.let { deviceIdAndPackageName ->
): MockNetworkDomainModel? = getCurrentDeviceIdAndPackageNameUseCase()?.let { _ ->
observeNetworkRequestsByIdUseCase(requestId = requestId).firstOrNull()
}?.let { request ->
MockNetworkDomainModel(
Expand All @@ -27,6 +27,7 @@ class GenerateNetworkMockFromNetworkCallUseCase(
),
isEnabled = true, // enabled by default
isShared = false,
displayName = "",
response = request.response?.let {
when (it) {
is FloconNetworkCallDomainModel.Response.Failure -> null // maybe generate error response in this case
Expand Down