Skip to content
Open
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
@@ -1,5 +1,6 @@
package io.github.openflocon.flocondesktop.core.data.settings.models

import io.github.openflocon.domain.models.settings.NetworkDetailTab
import io.github.openflocon.domain.models.settings.NetworkSettings
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -17,20 +18,26 @@ internal data class NetworkSettingsLocal(
val autoScroll: Boolean = false,

@SerialName("invert_list")
val invertList: Boolean = false
val invertList: Boolean = false,

@SerialName("default_selected_tab")
val defaultSelectedTab: NetworkDetailTab = NetworkDetailTab.Request,

)

internal fun NetworkSettingsLocal.toDomain() = NetworkSettings(
pinnedDetails = pinnedDetails,
displayOldSessions = displayOldSessions,
autoScroll = autoScroll,
invertList = invertList
invertList = invertList,
defaultSelectedTab = defaultSelectedTab,
)

internal fun NetworkSettings.toLocal() = NetworkSettingsLocal(
pinnedDetails = pinnedDetails,
displayOldSessions = displayOldSessions,
autoScroll = autoScroll,
invertList = invertList
invertList = invertList,
defaultSelectedTab = defaultSelectedTab,
)

Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ internal fun mapToUi(

internal fun parseDeeplinkString(
input: String,
deepLink: DeeplinkDomainModel,
variables: List<DeeplinkVariableDomainModel>,
variableValues: Map<String, String>
deepLink: DeeplinkDomainModel = DeeplinkDomainModel(
id = 0,
label = null,
link = input,
description = null,
parameters = emptyList()
),
variables: List<DeeplinkVariableDomainModel> = emptyList(),
variableValues: Map<String, String> = emptyMap()
): List<DeeplinkPart> {
val regex = "\\[([^\\[\\]]*)\\]".toRegex() // Regex pour trouver [quelquechose]
val result = mutableListOf<DeeplinkPart>()
Expand Down Expand Up @@ -91,12 +97,20 @@ internal fun parseDeeplinkString(
)
}
)
} else {
result.add(
DeeplinkPart.TextField(
label = value,
autoComplete = null
)
)
}

lastIndex = range.last + 1
}

// 3. Ajouter la dernière partie "Text" après le dernier [value] (s'il y en a une)

if (lastIndex < input.length) {
val remainingText = input.substring(lastIndex)
if (remainingText.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ sealed interface DeeplinkPart {
@Immutable
data class TextField(
val label: String,
val autoComplete: List<String>?,
val autoComplete: List<String>? = null,
) : DeeplinkPart


@Immutable
data class Variable(
val value: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.openflocon.flocondesktop.features.network

import io.github.openflocon.domain.network.usecase.ImportNetworkCallsFromCsvUseCase
import io.github.openflocon.flocondesktop.features.network.badquality.BadQualityNetworkViewModel
import io.github.openflocon.flocondesktop.features.network.body.NetworkJsonViewModel
import io.github.openflocon.flocondesktop.features.network.detail.NetworkDetailDelegate
import io.github.openflocon.flocondesktop.features.network.detail.NetworkDetailViewModel
import io.github.openflocon.flocondesktop.features.network.list.NetworkViewModel
Expand All @@ -20,6 +21,8 @@ import org.koin.dsl.module
internal val networkModule = module {
viewModelOf(::NetworkViewModel)
viewModelOf(::NetworkDetailViewModel)
viewModelOf(::NetworkJsonViewModel)


factoryOf(::MessagesServerDelegate)
factoryOf(::HeaderDelegate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import androidx.compose.ui.unit.dp
import androidx.navigation3.runtime.EntryProviderScope
import io.github.openflocon.domain.settings.repository.SettingsRepository
import io.github.openflocon.flocondesktop.app.MenuSceneStrategy
import io.github.openflocon.flocondesktop.features.network.body.NetworkBodyWindow
import io.github.openflocon.flocondesktop.features.network.body.NetworkDiffWindow
import io.github.openflocon.flocondesktop.features.network.body.NetworkJsonScreen
import io.github.openflocon.flocondesktop.features.network.body.model.NetworkBodyDetailUi

import io.github.openflocon.flocondesktop.features.network.body.model.NetworkDiffUi
import io.github.openflocon.flocondesktop.features.network.detail.view.NetworkDetailScreen
import io.github.openflocon.flocondesktop.features.network.list.view.NetworkScreen
Expand Down Expand Up @@ -100,12 +101,22 @@ fun EntryProviderScope<FloconRoute>.networkRoutes() {
NetworkDetailScreen(requestId = it.requestId, key = it.windowKey)
}
entry<NetworkRoutes.JsonDetail>(
metadata = WindowSceneStrategy.window()
metadata = WindowSceneStrategy.window(
WindowProperties(
title = "Body",
size = DpSize(
width = 900.0.dp,
height = 700.0.dp
)
)
)
) {
NetworkBodyWindow(
body = NetworkBodyDetailUi(text = it.json)
NetworkJsonScreen(
json = it.json,
key = it.id,
)
}

entry<NetworkRoutes.Diff>(
metadata = WindowSceneStrategy.window(WindowProperties(title = "Diff"))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.openflocon.flocondesktop.features.network.body

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -11,14 +12,16 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowDownward
import androidx.compose.material.icons.outlined.ArrowUpward
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
Expand All @@ -30,26 +33,50 @@ import androidx.compose.runtime.rememberCoroutineScope
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.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.isShiftPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.sebastianneubauer.jsontree.search.rememberSearchState
import flocondesktop.composeapp.generated.resources.Res
import flocondesktop.composeapp.generated.resources.search
import io.github.openflocon.flocondesktop.features.network.body.model.NetworkBodyDetailUi
import io.github.openflocon.flocondesktop.features.network.body.model.previewNetworkBodyDetailUi
import io.github.openflocon.library.designsystem.FloconTheme
import io.github.openflocon.library.designsystem.components.FloconHorizontalDivider
import io.github.openflocon.library.designsystem.components.FloconIcon
import io.github.openflocon.library.designsystem.components.FloconJsonTree
import io.github.openflocon.library.designsystem.components.FloconSmallIconButton
import io.github.openflocon.library.designsystem.components.FloconSurface
import io.github.openflocon.library.designsystem.components.FloconTextField
import io.github.openflocon.library.designsystem.components.FloconTextFieldWithoutM3
import io.github.openflocon.library.designsystem.components.defaultPlaceHolder
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.viewmodel.koinViewModel
import org.koin.core.parameter.parametersOf

@Composable
fun NetworkJsonScreen(
json: String,
key: String = json,
) {
val viewModel = koinViewModel<NetworkJsonViewModel>(key = key) {
parametersOf(json)
}
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

NetworkBodyContent(
body = uiState,
modifier = Modifier.fillMaxSize(),
)
}

@Composable
fun NetworkBodyWindow(
Expand All @@ -61,6 +88,7 @@ fun NetworkBodyWindow(
)
}


@Composable
private fun NetworkBodyContent(
body: NetworkBodyDetailUi,
Expand Down Expand Up @@ -139,50 +167,113 @@ private fun SearchBar(
focusRequester.requestFocus()
}

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.background(FloconTheme.colorPalette.primary)
.padding(horizontal = 12.dp, vertical = 8.dp),
) {
FloconTextField(
value = query,
onValueChange = { queryChanged(it) },
placeholder = defaultPlaceHolder(stringResource(Res.string.search)),
Column(modifier = modifier) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier
.weight(1f)
.padding(vertical = 8.dp, horizontal = 12.dp)
.heightIn(min = 24.dp)
.focusRequester(focusRequester),
)

AnimatedVisibility(visible = totalResults > 0) {
Row(
verticalAlignment = Alignment.CenterVertically,
.fillMaxWidth()
.background(FloconTheme.colorPalette.primary)
.padding(horizontal = 12.dp, vertical = 6.dp),
) {
FloconTextFieldWithoutM3(
value = query,
onValueChange = { queryChanged(it) },
placeholder = defaultPlaceHolder(
stringResource(Res.string.search),
color = FloconTheme.colorPalette.onSecondary.copy(alpha = 0.5f)
),
leadingComponent = {
FloconIcon(
imageVector = Icons.Outlined.Search,
modifier = Modifier.size(16.dp),
tint = FloconTheme.colorPalette.onSecondary.copy(alpha = 0.7f),
)
},
trailingComponent = {
if (query.isNotEmpty()) {
FloconSmallIconButton(
imageVector = Icons.Outlined.Close,
onClick = { queryChanged("") },
contentDescription = "Clear",
modifier = Modifier.size(16.dp)
)
}
},
containerColor = FloconTheme.colorPalette.secondary,
textStyle = FloconTheme.typography.bodySmall.copy(color = FloconTheme.colorPalette.onSecondary),
contentPadding = PaddingValues(horizontal = 4.dp, vertical = 2.dp),
modifier = Modifier
.padding(start = 12.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = "${selectedResultIndex?.inc() ?: 0}/$totalResults",
modifier = Modifier.widthIn(min = 40.dp),
textAlign = TextAlign.End,
style = FloconTheme.typography.bodyMedium.copy(fontSize = 14.sp),
)
.width(280.dp)
.height(30.dp)
.border(
width = 1.dp,
color = FloconTheme.colorPalette.onPrimary.copy(alpha = 0.2f),
shape = FloconTheme.shapes.medium
)
.focusRequester(focusRequester)
.onPreviewKeyEvent { event ->
if (event.type == KeyEventType.KeyDown) {
when (event.key) {
Key.Enter, Key.NumPadEnter -> {
if (event.isShiftPressed) {
previousClicked()
} else {
nextClicked()
}
true
}
Key.DirectionDown -> {
nextClicked()
true
}
Key.DirectionUp -> {
previousClicked()
true
}
else -> false
}
} else {
false
}
},
)

AnimatedVisibility(visible = totalResults > 0) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.height(32.dp)
.clip(RoundedCornerShape(6.dp))
.background(FloconTheme.colorPalette.primary),
.height(30.dp)
.border(
width = 1.dp,
color = FloconTheme.colorPalette.onPrimary.copy(alpha = 0.2f),
shape = RoundedCornerShape(6.dp)
)
.background(
color = FloconTheme.colorPalette.secondary,
shape = RoundedCornerShape(6.dp)
)
.padding(start = 8.dp, end = 2.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(
text = "${selectedResultIndex?.inc() ?: 0}/$totalResults",
style = FloconTheme.typography.bodySmall,
color = FloconTheme.colorPalette.onSecondary,
)
FloconSmallIconButton(
imageVector = Icons.Outlined.ArrowUpward,
onClick = previousClicked,
contentPadding = PaddingValues(all = 4.dp),
enabled = selectedResultIndex != null,
modifier = Modifier.fillMaxHeight().aspectRatio(1f),
)
VerticalDivider(modifier = Modifier.fillMaxHeight())
VerticalDivider(
modifier = Modifier
.fillMaxHeight(0.6f)
.width(1.dp),
color = FloconTheme.colorPalette.onSecondary.copy(alpha = 0.2f)
)
FloconSmallIconButton(
imageVector = Icons.Outlined.ArrowDownward,
onClick = nextClicked,
Expand All @@ -193,9 +284,15 @@ private fun SearchBar(
}
}
}

FloconHorizontalDivider(
modifier = Modifier.fillMaxWidth(),
color = FloconTheme.colorPalette.secondary
)
}
}


@Preview
@Composable
private fun SearchBarPreview() {
Expand Down
Loading