Skip to content

Commit ee4e75a

Browse files
PhantomDaveCopilot
andauthored
feat: Enhance Dashboard Widget Configuration (#134)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent c6df0ca commit ee4e75a

30 files changed

+1767
-63
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"EditorConfig.EditorConfig",
3333
"streetsidesoftware.code-spell-checker",
3434
"mtxr.sqltools",
35-
"mtxr.sqltools-driver-pg"
35+
"mtxr.sqltools-driver-pg",
36+
"usernamehw.errorlens"
3637
]
3738
}
3839
},

PhantomDave.BankTracking.Api/Types/Inputs/AddWidgetInput.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ public sealed class AddWidgetInput
1010
public int Y { get; init; }
1111
public int Rows { get; init; }
1212
public int Cols { get; init; }
13+
public string? Title { get; init; }
14+
public string? Subtitle { get; init; }
15+
public string? Config { get; init; }
1316
}

PhantomDave.BankTracking.Api/Types/Inputs/UpdateWidgetInput.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ public sealed class UpdateWidgetInput
1010
public int? Y { get; init; }
1111
public int? Rows { get; init; }
1212
public int? Cols { get; init; }
13+
public string? Title { get; init; }
14+
public string? Subtitle { get; init; }
15+
public string? Config { get; init; }
1316
}

PhantomDave.BankTracking.Api/Types/Mutations/DashboardWidgetMutations.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ public async Task<DashboardWidgetType> AddWidget(
3838
.Build());
3939
}
4040

41+
var title = ValidateAndTrimString(input.Title, "title");
42+
var subtitle = ValidateAndTrimString(input.Subtitle, "subtitle");
43+
4144
var widget = new DashboardWidget
4245
{
4346
DashboardId = input.DashboardId,
4447
Type = input.Type,
4548
X = Math.Max(0, input.X),
4649
Y = Math.Max(0, input.Y),
4750
Rows = input.Rows,
48-
Cols = input.Cols
51+
Cols = input.Cols,
52+
Title = title,
53+
Subtitle = subtitle,
54+
Config = input.Config
4955
};
5056

5157
await unitOfWork.DashboardWidgets.AddAsync(widget);
@@ -125,6 +131,21 @@ public async Task<DashboardWidgetType> UpdateWidget(
125131
widget.Cols = input.Cols.Value;
126132
}
127133

134+
if (input.Title is not null)
135+
{
136+
widget.Title = ValidateAndTrimString(input.Title, "title");
137+
}
138+
139+
if (input.Subtitle is not null)
140+
{
141+
widget.Subtitle = ValidateAndTrimString(input.Subtitle, "subtitle");
142+
}
143+
144+
if (input.Config is not null)
145+
{
146+
widget.Config = input.Config;
147+
}
148+
128149
await unitOfWork.DashboardWidgets.UpdateAsync(widget);
129150
await unitOfWork.SaveChangesAsync();
130151

@@ -164,4 +185,20 @@ public async Task<bool> RemoveWidget(
164185

165186
return true;
166187
}
188+
189+
private static string? ValidateAndTrimString(string? value, string fieldName)
190+
{
191+
if (value is null) return null;
192+
193+
var trimmed = value.Trim();
194+
if (string.IsNullOrEmpty(trimmed))
195+
{
196+
throw new GraphQLException(
197+
ErrorBuilder.New()
198+
.SetMessage($"Widget {fieldName} cannot be empty or whitespace.")
199+
.SetCode("BAD_USER_INPUT")
200+
.Build());
201+
}
202+
return trimmed;
203+
}
167204
}

PhantomDave.BankTracking.Api/Types/ObjectTypes/DashboardWidgetType.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ public class DashboardWidgetType
66
{
77
public int Id { get; set; }
88
public WidgetType WidgetType { get; set; }
9-
public string? Configuration { get; set; }
9+
public string? Title { get; set; }
10+
public string? Subtitle { get; set; }
11+
public string? Config { get; set; }
1012
public int Cols { get; set; }
1113
public int Rows { get; set; }
1214
public int X { get; set; }
@@ -18,6 +20,9 @@ public static DashboardWidgetType FromDashboardWidget(DashboardWidget widget)
1820
{
1921
Id = widget.Id,
2022
WidgetType = widget.Type,
23+
Title = widget.Title,
24+
Subtitle = widget.Subtitle,
25+
Config = widget.Config,
2126
Cols = widget.Cols,
2227
Rows = widget.Rows,
2328
X = widget.X,

PhantomDave.BankTracking.Data/Migrations/20251201141815_AddWidgetTitleSubtitleConfig.Designer.cs

Lines changed: 277 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)