Skip to content

Commit d5c3c88

Browse files
florent37Florent Champigny
andauthored
refact: [DB] scrollbar on logger DB (#475)
Co-authored-by: Florent Champigny <florent@bere.al>
1 parent bd5d300 commit d5c3c88

3 files changed

Lines changed: 42 additions & 34 deletions

File tree

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/database/view/logs/DatabaseQueryLogItemView.kt

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.foundation.layout.Column
55
import androidx.compose.foundation.layout.Row
66
import androidx.compose.foundation.layout.width
7-
import androidx.compose.foundation.text.selection.SelectionContainer
87
import androidx.compose.material3.Text
98
import androidx.compose.runtime.Composable
109
import androidx.compose.ui.Modifier
@@ -21,35 +20,33 @@ fun DatabaseQueryLogItemView(
2120
log: DatabaseQueryUiModel,
2221
modifier: Modifier = Modifier
2322
) {
24-
SelectionContainer {
25-
Row(
26-
modifier = modifier.then(
27-
if (log.isFromOldSession) {
28-
Modifier.alpha(0.8f)
29-
} else Modifier
30-
), horizontalArrangement = Arrangement.spacedBy(8.dp)
31-
) {
23+
Row(
24+
modifier = modifier.then(
25+
if (log.isFromOldSession) {
26+
Modifier.alpha(0.8f)
27+
} else Modifier
28+
), horizontalArrangement = Arrangement.spacedBy(8.dp)
29+
) {
30+
Text(
31+
modifier = Modifier.width(60.dp),
32+
text = log.dateFormatted,
33+
style = FloconTheme.typography.bodySmall,
34+
textAlign = TextAlign.Center,
35+
color = FloconTheme.colorPalette.onSurface
36+
.copy(alpha = 0.6f)
37+
)
38+
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
3239
Text(
33-
modifier = Modifier.width(60.dp),
34-
text = log.dateFormatted,
35-
style = FloconTheme.typography.bodySmall,
36-
textAlign = TextAlign.Center,
37-
color = FloconTheme.colorPalette.onSurface
38-
.copy(alpha = 0.6f)
40+
text = log.sqlQuery,
41+
style = FloconTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace),
42+
color = findColor(log.type)
3943
)
40-
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
44+
log.bindArgs?.let {
4145
Text(
42-
text = log.sqlQuery,
43-
style = FloconTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace),
44-
color = findColor(log.type)
46+
text = "Args: ${log.bindArgs}",
47+
style = FloconTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
48+
color = FloconTheme.colorPalette.onSurface.copy(alpha = 0.8f)
4549
)
46-
log.bindArgs?.let {
47-
Text(
48-
text = "Args: ${log.bindArgs}",
49-
style = FloconTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
50-
color = FloconTheme.colorPalette.onSurface.copy(alpha = 0.8f)
51-
)
52-
}
5350
}
5451
}
5552
}

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/database/view/logs/DatabaseQueryLogsView.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import androidx.compose.foundation.layout.Box
88
import androidx.compose.foundation.layout.Column
99
import androidx.compose.foundation.layout.FlowRow
1010
import androidx.compose.foundation.layout.Row
11+
import androidx.compose.foundation.layout.fillMaxHeight
1112
import androidx.compose.foundation.layout.fillMaxSize
1213
import androidx.compose.foundation.layout.fillMaxWidth
1314
import androidx.compose.foundation.layout.padding
1415
import androidx.compose.foundation.layout.size
1516
import androidx.compose.foundation.lazy.LazyColumn
16-
import androidx.compose.foundation.lazy.LazyRow
17-
import androidx.compose.foundation.lazy.items
17+
import androidx.compose.foundation.lazy.rememberLazyListState
1818
import androidx.compose.foundation.shape.CircleShape
1919
import androidx.compose.foundation.shape.RoundedCornerShape
2020
import androidx.compose.foundation.text.KeyboardActions
@@ -24,7 +24,6 @@ import androidx.compose.material.icons.filled.Add
2424
import androidx.compose.material.icons.filled.Check
2525
import androidx.compose.material.icons.filled.Close
2626
import androidx.compose.material.icons.filled.Remove
27-
import androidx.compose.material.icons.outlined.Download
2827
import androidx.compose.material.icons.outlined.Search
2928
import androidx.compose.material.icons.outlined.Upload
3029
import androidx.compose.material.icons.outlined.UploadFile
@@ -46,17 +45,16 @@ import androidx.paging.compose.collectAsLazyPagingItems
4645
import io.github.openflocon.flocondesktop.common.ui.ContextualView
4746
import io.github.openflocon.flocondesktop.features.database.DatabaseQueryLogsViewModel
4847
import io.github.openflocon.flocondesktop.features.database.model.FilterChipUiModel
49-
import io.github.openflocon.flocondesktop.features.network.list.model.NetworkAction
5048
import io.github.openflocon.library.designsystem.FloconTheme
5149
import io.github.openflocon.library.designsystem.common.FloconContextMenuItem
5250
import io.github.openflocon.library.designsystem.components.FloconDropdownMenuItem
5351
import io.github.openflocon.library.designsystem.components.FloconIcon
54-
import io.github.openflocon.library.designsystem.components.FloconIconButton
55-
import io.github.openflocon.library.designsystem.components.FloconIconToggleButton
5652
import io.github.openflocon.library.designsystem.components.FloconOverflow
5753
import io.github.openflocon.library.designsystem.components.FloconPageTopBar
5854
import io.github.openflocon.library.designsystem.components.FloconTextFieldWithoutM3
55+
import io.github.openflocon.library.designsystem.components.FloconVerticalScrollbar
5956
import io.github.openflocon.library.designsystem.components.defaultPlaceHolder
57+
import io.github.openflocon.library.designsystem.components.rememberFloconScrollbarAdapter
6058
import org.koin.compose.viewmodel.koinViewModel
6159
import org.koin.core.parameter.parametersOf
6260

@@ -75,6 +73,9 @@ fun DatabaseQueryLogsView(
7573
val filterChips by viewModel.filterChips.collectAsStateWithLifecycle()
7674
val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()
7775

76+
val lazyListState = rememberLazyListState()
77+
val scrollAdapter = rememberFloconScrollbarAdapter(lazyListState)
78+
7879
Column(modifier = modifier) {
7980
DatabaseLogsHeader(
8081
modifier = Modifier.fillMaxWidth().border(
@@ -108,11 +109,16 @@ fun DatabaseQueryLogsView(
108109
shape = FloconTheme.shapes.medium
109110
)
110111
) {
111-
LazyColumn(modifier = Modifier.fillMaxSize()) {
112+
LazyColumn(
113+
modifier = Modifier.fillMaxSize(),
114+
state = lazyListState,
115+
) {
112116
items(logs.itemCount) { index ->
113117
val log = logs[index]
114118
if (log != null) {
115119
ContextualView(
120+
modifier = Modifier
121+
.fillMaxWidth(),
116122
items = listOf(
117123
FloconContextMenuItem.Item("Copy Query") {
118124
viewModel.copyQuery(log.sqlQuery)
@@ -149,6 +155,11 @@ fun DatabaseQueryLogsView(
149155
}
150156
}
151157
}
158+
FloconVerticalScrollbar(
159+
adapter = scrollAdapter,
160+
modifier = Modifier.fillMaxHeight()
161+
.align(Alignment.TopEnd),
162+
)
152163
}
153164
}
154165
}

FloconDesktop/data/local/src/commonMain/kotlin/io/github/openflocon/data/local/database/datasource/LocalDatabaseDataSourceRoom.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ internal class LocalDatabaseDataSourceRoom(
305305
}
306306
}
307307

308-
queryString += " ORDER BY timestamp DESC"
308+
queryString += " ORDER BY timestamp ASC"
309309

310310
val query = RoomRawQuery(
311311
sql = queryString,

0 commit comments

Comments
 (0)