Skip to content

Commit

Permalink
Converted tab pane to side scroll instead of trying to squish tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 authored and bill-long committed Feb 16, 2024
1 parent 909f0c9 commit 72d45d6
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 68 deletions.
10 changes: 8 additions & 2 deletions src/EventLogExpert.UI/Store/EventTable/EventTableReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ state with
};

[ReducerMethod]
public static EventTableState ReduceSetActiveTable(EventTableState state, EventTableAction.SetActiveTable action) =>
state with { ActiveTableId = state.EventTables.First(table => table.Id.Equals(action.TableId)).Id };
public static EventTableState ReduceSetActiveTable(EventTableState state, EventTableAction.SetActiveTable action)
{
var activeTable = state.EventTables.First(table => table.Id.Equals(action.TableId));

if (activeTable.IsLoading) { return state; }

return state with { ActiveTableId = activeTable.Id };
}

[ReducerMethod]
public static EventTableState ReduceSetOrderBy(EventTableState state, EventTableAction.SetOrderBy action) =>
Expand Down
3 changes: 3 additions & 0 deletions src/EventLogExpert.UI/Store/LoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EventLogExpert.UI.Store.FilterColor;
using EventLogExpert.UI.Store.FilterGroup;
using EventLogExpert.UI.Store.FilterPane;
using EventLogExpert.UI.Store.Settings;
using Fluxor;
using System.Text.Json;
using IDispatcher = Fluxor.IDispatcher;
Expand Down Expand Up @@ -57,6 +58,8 @@ public override void BeforeDispatch(object action)
case FilterPaneAction.SetBasicFilter :
case FilterPaneAction.SetCachedFilter :
case FilterPaneAction.SetFilterDateRange :
case SettingsAction.LoadDatabasesCompleted :
case SettingsAction.LoadSettingsCompleted :
debugLogger.Trace($"Action: {action.GetType()}.");
break;
case EventLogAction.SelectEvent selectEventAction :
Expand Down
49 changes: 15 additions & 34 deletions src/EventLogExpert/Components/SplitLogTabPane.razor
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
@inherits FluxorComponent

@if (EventTableState.Value.EventTables.Count > 1)
{
<div id="tab-pane">
<div class="tab-row">
<div style="max-width: @GetTabWidth()">
<input type="radio" name="tab" id="log" checked
@onclick="() => SetActiveLog(EventTableState.Value.EventTables.First(table => table.IsCombined))" />
<label for="log" tabindex="0">Combined</label>
<div id="tab-pane" hidden="@(EventTableState.Value.EventTables.Count <= 1)">
<div class="tab-row">
@foreach (var table in _sortedTabs)
{
<div class="@GetActiveTab(table)" title="@GetTabTooltip(table)" @onclick="() => SetActiveLog(table)" disabled="@table.IsLoading">
<span>
@if (table.IsLoading)
{
<i class="spinner-border" role="status"></i>
@:&nbsp;
}
@GetTabName(table)
</span>
</div>

@{
var logsTabSorted = EventTableState.Value.EventTables
.Where(l => l.IsCombined is false)
.OrderBy(l => l.ComputerName)
.ThenBy(l => l.LogName)
.ToList();

for (int i = 0; i < logsTabSorted.Count; i++)
{
var log = logsTabSorted[i];
<div style="max-width: @GetTabWidth()" title="@GetTabTooltip(log)">
<input type="radio" name="tab" id="@($"log{i}")" @onclick="() => SetActiveLog(log)" disabled="@log.IsLoading" />
<label for="@($"log{i}")" tabindex="0">
@if (log.IsLoading)
{
<i class="spinner-border" role="status"></i>
@:&nbsp;
}
@GetTabName(log)
</label>
</div>
}
}
</div>
}
</div>
}
</div>
64 changes: 49 additions & 15 deletions src/EventLogExpert/Components/SplitLogTabPane.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,71 @@
using EventLogExpert.UI.Store.EventTable;
using Fluxor;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using IDispatcher = Fluxor.IDispatcher;

namespace EventLogExpert.Components;

public sealed partial class SplitLogTabPane
{
[Inject] private IState<EventTableState> EventTableState { get; init; } = null!;
private EventTableState _eventTableState = null!;

private List<EventTableModel> _sortedTabs = [];

[Inject] private IDispatcher Dispatcher { get; init; } = null!;

private static string GetTabName(EventTableModel table) =>
table.LogType is LogType.File ?
Path.GetFileNameWithoutExtension(table.FileName)!.Split("\\").Last() :
$"{table.LogName} - {table.ComputerName}";
[Inject] private IState<EventTableState> EventTableState { get; init; } = null!;

private static string GetTabTooltip(EventTableModel table) =>
$"{(table.LogType == LogType.File ? "Log File: " : "Live Log: ")} {table.FileName}\n" +
$"Log Name: {table.LogName}\n" +
$"Computer Name: {table.ComputerName}";
[Inject] private IJSRuntime JSRuntime { get; init; } = null!;

private string GetTabWidth()
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var logCount = EventTableState.Value.EventTables.Count;
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("registerTabPaneEvents");
}

return logCount > 4 ? $"{100 / (logCount + 1)}vw" : "20vw";
await base.OnAfterRenderAsync(firstRender);
}

private void SetActiveLog(EventTableModel table)
protected override bool ShouldRender()
{
if (table.IsLoading) { return; }
if (ReferenceEquals(EventTableState.Value, _eventTableState)) { return false; }

Dispatcher.Dispatch(new EventTableAction.SetActiveTable(table.Id));
_eventTableState = EventTableState.Value;

_sortedTabs =
[
.. EventTableState.Value.EventTables
.OrderByDescending(table => table.IsCombined)
.ThenBy(table => table.ComputerName)
.ThenBy(table => table.LogName)
];

return true;
}

private static string GetTabName(EventTableModel table)
{
if (table.IsCombined) { return "Combined"; }

return table.LogType is LogType.File ?
Path.GetFileNameWithoutExtension(table.FileName)!.Split("\\").Last() :
$"{table.LogName} - {table.ComputerName}";
}

private static string GetTabTooltip(EventTableModel table)
{
if (table.IsCombined) { return string.Empty; }

return $"{(table.LogType == LogType.File ? "Log File: " : "Live Log: ")} {table.FileName}\n" +
$"Log Name: {table.LogName}\n" +
$"Computer Name: {table.ComputerName}";
}

private string GetActiveTab(EventTableModel table) =>
EventTableState.Value.ActiveTableId == table.Id ? "tab active" : "tab";

private void SetActiveLog(EventTableModel table) =>
Dispatcher.Dispatch(new EventTableAction.SetActiveTable(table.Id));
}
28 changes: 11 additions & 17 deletions src/EventLogExpert/Components/SplitLogTabPane.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
.tab-row {
display: flex;
align-items: flex-end;
}

text-align: left;
float: none;
position: relative;
.tab {
width: 30ch;
text-align: center;

&:hover > span,
&.active > span {
padding-top: 6px;
border-top: 2px solid var(--clr-lightblue);
}
}

.tab-row > div {
float: left;
display: block;
}

input[type="radio"] {
position: absolute;
top: 0;
left: -9999px;
}

label {
span {
display: block;
margin: 0 1px 0 0;
padding: 4px 22px;
border-radius: 3px 3px 0 0;

/* max-width: calc(100vw / 5); */
overflow: hidden;
user-select: none;
text-overflow: ellipsis;
Expand All @@ -43,12 +43,6 @@ label {
transition: all 0.1s ease-in-out;
}

label:hover,
[id^="log"]:checked + label {
padding-top: 6px;
border-top: 2px solid var(--clr-lightblue);
}

.spinner-border {
font-size: 0.85em;
height: 0.95em;
Expand Down
1 change: 1 addition & 0 deletions src/EventLogExpert/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<script src="js/dropdowns.js"></script>
<script src="js/event_table.js"></script>
<script src="js/modals.js"></script>
<script src="js/tab_pane.js"></script>

</body>

Expand Down
57 changes: 57 additions & 0 deletions src/EventLogExpert/wwwroot/js/tab_pane.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
window.registerTabPaneEvents = () => {
const tabPane = document.getElementById("tab-pane");

if (!tabPane) { return; }

registerTabPaneScroller(tabPane);
};

window.registerTabPaneScroller = (tabPane) => {
let canDrag, isScrolling = false;
let startPos, currentPos;

const preventClick = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
}

tabPane.addEventListener("mousedown", (e) => {
canDrag = true;

startPos = e.pageX - tabPane.offsetLeft;
currentPos = tabPane.scrollLeft;
});

tabPane.addEventListener("mouseup", (e) => {
canDrag = false;

const tabs = tabPane.getElementsByClassName("tab");

if (isScrolling) {
for (let i = 0; i < tabs.length; i++) {
tabs[i].addEventListener("click", preventClick);
}
} else {
for (let i = 0; i < tabs.length; i++) {
tabs[i].removeEventListener("click", preventClick);
}
}

isScrolling = false;
});

tabPane.addEventListener("mousemove", (e) => {
if (!canDrag) { return; }

isScrolling = true;

e.preventDefault();

const offset = e.pageX - tabPane.offsetLeft;
const pos = offset - startPos;

tabPane.scrollLeft = currentPos - pos;
});

tabPane.addEventListener("mouseleave", () => { canDrag = false; });
}

0 comments on commit 72d45d6

Please sign in to comment.