gnodet commented on code in PR #24600:
URL: https://github.com/apache/camel/pull/24600#discussion_r3569926166


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ActivityTab.java:
##########
@@ -0,0 +1,467 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import dev.tamboui.layout.Constraint;
+import dev.tamboui.layout.Layout;
+import dev.tamboui.layout.Rect;
+import dev.tamboui.style.Style;
+import dev.tamboui.terminal.Frame;
+import dev.tamboui.text.Line;
+import dev.tamboui.text.Span;
+import dev.tamboui.text.Text;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.widgets.block.Block;
+import dev.tamboui.widgets.block.BorderType;
+import dev.tamboui.widgets.block.Borders;
+import dev.tamboui.widgets.paragraph.Paragraph;
+import dev.tamboui.widgets.scrollbar.ScrollbarState;
+import dev.tamboui.widgets.table.Cell;
+import dev.tamboui.widgets.table.Row;
+import dev.tamboui.widgets.table.Table;
+import org.apache.camel.util.TimeUtils;
+import org.apache.camel.util.json.JsonObject;
+
+class ActivityTab extends AbstractTableTab {
+
+    private final ScrollbarState detailScrollState = new ScrollbarState();
+    private int detailScroll;
+    private int detailHScroll;
+    private boolean wordWrap = true;
+    private boolean paused;
+    private List<ActivityEntry> pausedSnapshot;
+    private int timeFilterIndex;
+    private static final String[] TIME_FILTERS = { "all", "1m", "5m", "15m", 
"30m", "1h" };
+    private static final long[] TIME_FILTER_MILLIS = { 0, 60_000, 300_000, 
900_000, 1_800_000, 3_600_000 };
+
+    ActivityTab(MonitorContext ctx) {
+        super(ctx, "exchange", "route", "elapsed", "since");
+    }
+
+    @Override
+    protected int getRowCount() {
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        if (info == null) {
+            return 0;
+        }
+        return filteredActivity(info).size();
+    }
+
+    @Override
+    public void onTabSelected() {
+        IntegrationInfo info = ctx.findSelectedIntegration();
+        if (info != null && !info.activity.isEmpty() && tableState.selected() 
== null) {
+            tableState.select(0);
+        }
+    }
+
+    @Override
+    protected boolean handleTabKeyEvent(KeyEvent ke) {
+        if (ke.isConfirm()) {
+            return true;
+        }
+        if (ke.isChar('w')) {
+            wordWrap = !wordWrap;
+            return true;
+        }
+        if (ke.isChar(' ')) {
+            paused = !paused;
+            if (paused) {
+                IntegrationInfo info = ctx.findSelectedIntegration();
+                pausedSnapshot = info != null ? new ArrayList<>(info.activity) 
: List.of();
+            } else {
+                pausedSnapshot = null;
+            }
+            return true;
+        }
+        if (ke.isChar('t')) {
+            timeFilterIndex = (timeFilterIndex + 1) % TIME_FILTERS.length;
+            return true;
+        }
+        if (ke.isPageUp()) {
+            detailScroll = Math.max(0, detailScroll - 10);
+            return true;
+        }
+        if (ke.isPageDown()) {
+            detailScroll += 10;
+            return true;
+        }
+        if (ke.isLeft()) {
+            detailHScroll = Math.max(0, detailHScroll - 5);
+            return true;
+        }
+        if (ke.isRight()) {
+            detailHScroll += 5;
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void navigateUp() {
+        detailScroll = 0;
+        super.navigateUp();
+    }
+
+    @Override
+    public void navigateDown() {
+        detailScroll = 0;
+        super.navigateDown();
+    }
+
+    @Override
+    protected void renderContent(Frame frame, Rect area, IntegrationInfo info) 
{
+        List<ActivityEntry> sorted = filteredActivity(info);
+
+        List<Row> rows = new ArrayList<>();
+        for (ActivityEntry ae : sorted) {
+            String ago = ae.timestamp > 0
+                    ? TimeUtils.printSince(ae.timestamp) : "";
+            String status = ae.failed ? "FAILED" : "OK";
+            Style statusStyle = ae.failed ? Theme.error() : Theme.success();
+            String elapsed = ae.elapsed + "ms";
+
+            String sends = ae.endpointSends.isEmpty() ? "" : 
String.valueOf(ae.endpointSends.size());
+
+            rows.add(Row
+                    .from(
+                            Cell.from(ae.exchangeId != null ? ae.exchangeId : 
""),
+                            Cell.from(Span.styled(ae.routeId != null ? 
ae.routeId : "", Style.EMPTY.fg(Theme.accent()))),
+                            Cell.from(Span.styled(status, statusStyle)),
+                            Cell.from(elapsed),
+                            Cell.from(sends),
+                            Cell.from(ago),
+                            Cell.from(ae.fromEndpointUri != null ? 
ae.fromEndpointUri : "")));
+        }
+
+        if (rows.isEmpty()) {
+            rows.add(emptyRow("No activity captured", 7));
+        }
+
+        ActivityEntry selectedEntry = null;
+        Integer sel = tableState.selected();
+        if (sel != null && sel >= 0 && sel < sorted.size()) {
+            selectedEntry = sorted.get(sel);
+        }
+        boolean showDetail = selectedEntry != null;
+
+        List<Constraint> constraints = new ArrayList<>();
+        constraints.add(Constraint.length(4));
+        if (showDetail) {
+            constraints.add(Constraint.length(13));
+            constraints.add(Constraint.fill());
+        } else {
+            constraints.add(Constraint.fill());
+        }
+        List<Rect> chunks = Layout.vertical()
+                .constraints(constraints)
+                .split(area);
+
+        renderStatsPanel(frame, chunks.get(0), sorted);
+
+        Table table = Table.builder()
+                .rows(rows)
+                .header(Row.from(
+                        Cell.from(Span.styled(sortLabel("EXCHANGE", 
"exchange"), sortStyle("exchange"))),
+                        Cell.from(Span.styled(sortLabel("ROUTE", "route"), 
sortStyle("route"))),
+                        Cell.from(Span.styled("STATUS", Style.EMPTY.bold())),
+                        Cell.from(Span.styled(sortLabel("ELAPSED", "elapsed"), 
sortStyle("elapsed"))),
+                        Cell.from(Span.styled("SENDS", Style.EMPTY.bold())),
+                        Cell.from(Span.styled(sortLabel("SINCE", "since"), 
sortStyle("since"))),
+                        Cell.from(Span.styled("ENDPOINT", 
Style.EMPTY.bold()))))
+                .widths(
+                        Constraint.length(38),
+                        Constraint.length(20),
+                        Constraint.length(8),
+                        Constraint.length(10),
+                        Constraint.length(7),
+                        Constraint.length(8),
+                        Constraint.fill())
+                .highlightStyle(Theme.selectionBg())
+                .highlightSpacing(Table.HighlightSpacing.ALWAYS)
+                
.block(Block.builder().borderType(BorderType.ROUNDED).borders(Borders.ALL)
+                        .title(" Activity [" + sorted.size() + "] ").build())
+                .build();
+
+        lastTableArea = chunks.get(1);
+        frame.renderStatefulWidget(table, chunks.get(1), tableState);
+        renderScrollbar(frame, sorted.size());
+
+        if (showDetail) {
+            renderDetail(frame, chunks.get(2), selectedEntry);
+        }
+    }
+
+    private void renderStatsPanel(Frame frame, Rect area, List<ActivityEntry> 
entries) {
+        int total = entries.size();
+        int failed = 0;
+        long maxElapsed = 0;
+        long oldestTs = Long.MAX_VALUE;
+        long newestTs = 0;
+        long[] elapsedValues = new long[total];
+
+        for (int i = 0; i < total; i++) {
+            ActivityEntry ae = entries.get(i);
+            elapsedValues[i] = ae.elapsed;
+            if (ae.failed) {
+                failed++;
+            }
+            if (ae.elapsed > maxElapsed) {
+                maxElapsed = ae.elapsed;
+            }
+            if (ae.timestamp > 0 && ae.timestamp < oldestTs) {
+                oldestTs = ae.timestamp;
+            }
+            if (ae.timestamp > newestTs) {
+                newestTs = ae.timestamp;
+            }
+        }
+
+        java.util.Arrays.sort(elapsedValues);

Review Comment:
   nit: Per project import conventions, this should use `import 
java.util.Arrays;` at the top of the file and `Arrays.sort(elapsedValues)` 
here. The CI rewrite plugin should catch this automatically.
   
   ```suggestion
           Arrays.sort(elapsedValues);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to