Skip to content

Commit

Permalink
chore: Refactor methods and remove redundant return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Aug 17, 2024
1 parent 9eb16ab commit 7c6a60d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/KubeUI/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public static object GetRequiredService(this Application? app, Type type)
}
}

public static T Set<T>(this T control, Func<T,T> func) where T : Control
public static T Set<T>(this T control, Action<T> func) where T : Control
{
return func.Invoke(control);
func.Invoke(control);

return control;
}

public static TDataGrid Columns<TDataGrid>(this TDataGrid container, params DataGridColumn[] items) where TDataGrid : DataGrid
Expand Down
1 change: 0 additions & 1 deletion src/KubeUI/Views/ClusterListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ protected override object Build(ClusterListViewModel? vm)
]);

Dispatcher.UIThread.Post(() => x.Columns[0].Sort(ListSortDirection.Ascending));
return x;
}),
]);
}
Expand Down
16 changes: 12 additions & 4 deletions src/KubeUI/Views/ClusterView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Markup.Declarative;
using Avalonia.Styling;
using k8s.Models;
using LiveChartsCore.Defaults;
using LiveChartsCore.Measure;
Expand Down Expand Up @@ -28,7 +29,14 @@ private void S_timer_Tick(object? sender, EventArgs e)
}
}

private static SolidColorPaint _color = new(SKColors.White);
private static SolidColorPaint GetColor()
{
if (Application.Current.ActualThemeVariant == ThemeVariant.Dark)
{
return new(SKColors.White);
}
return new(SKColors.Black);
}

private DispatcherTimer _timer = new();

Expand All @@ -37,7 +45,7 @@ public static void SetSeries(string name, PieSeries<ObservableValue> series)
series.Name = name;
series.DataLabelsPosition = PolarLabelsPosition.Start;
series.DataLabelsFormatter = point => $"{point.Coordinate.PrimaryValue}";
series.DataLabelsPaint = _color;
series.DataLabelsPaint = GetColor();
series.InnerRadius = 20;
series.RelativeOuterRadius = 8;
series.RelativeInnerRadius = 8;
Expand All @@ -46,7 +54,7 @@ public static void SetSeries(string name, PieSeries<ObservableValue> series)

public static LabelVisual SetTitle(string name) => new LabelVisual()
{
Paint = _color,
Paint = GetColor(),
Text = name,
TextSize = 25,
};
Expand All @@ -56,7 +64,7 @@ public static void SetSeries(string name, PieSeries<ObservableValue> series)
new Style<PieChart>()
.Setter(PieChart.InitialRotationProperty, -90.0)
.Setter(PieChart.LegendPositionProperty, LegendPosition.Bottom)
.Setter(PieChart.LegendTextPaintProperty, _color)
.Setter(PieChart.LegendTextPaintProperty, GetColor())
.Setter(PieChart.MaxAngleProperty, 270.0)
];

Expand Down
1 change: 0 additions & 1 deletion src/KubeUI/Views/ResourceYamlView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ protected override object Build(ResourceYamlViewModel? vm)
x.Options.ShowBoxForControlCharacters = false;
x.Options.EnableHyperlinks = false;
x.Options.EnableEmailHyperlinks = false;
return x;
})
.Document(@vm.YamlDocument, BindingMode.OneWay)
.FontFamily(new FontFamily("Consolas,Menlo,Monospace"))
Expand Down
1 change: 0 additions & 1 deletion src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected override object Build(PodConsoleViewModel? vm)
x.Options.ShowBoxForControlCharacters = false;
x.Options.EnableHyperlinks = false;
x.Options.EnableEmailHyperlinks = false;
return x;
})
.OnTextChanged((sender, e) => {
editor.ScrollToEnd();
Expand Down
1 change: 0 additions & 1 deletion src/KubeUI/Views/Workloads/Pod/PodLogsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected override object Build(PodLogsViewModel? vm)
if (ViewModel?.AutoScrollToBottom == true)
editor.ScrollToEnd();
};
return x;
})
.Document(@vm.Logs, BindingMode.OneWay)
.FontFamily(new FontFamily("Consolas,Menlo,Monospace"))
Expand Down
1 change: 0 additions & 1 deletion src/KubeUI/Views/Workloads/Pod/PortForwarderListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ protected override object Build(PortForwarderListViewModel? vm)
);

Dispatcher.UIThread.Post(() => x.Columns[0].Sort(ListSortDirection.Ascending));
return x;
}),
]);
}
Expand Down

0 comments on commit 7c6a60d

Please sign in to comment.