Skip to content

Commit 4bae990

Browse files
committed
fix(widgets): improve widget handling and UI enhancements
- Change widgetsService.list() to accept dashboardId for scoped widget retrieval - Update TRPC routers to require UUID format for dashboard and widget IDs - Enhance dashboard widgets section with semantic HTML (hgroup, h4/h5 tags) and better layout - Add "Remove" button to widget edit page for easier deletion - Update breadcrumb navigation to include dashboard link when adding widgets - Replace plain text and links with hgroup elements for better structure in dashboard list - Add updateState method to WidgetsService for widget state updates via TRPC - Adjust TRPC widgets.list query to accept dashboardId input for filtered results
1 parent a7c5b25 commit 4bae990

File tree

7 files changed

+66
-46
lines changed

7 files changed

+66
-46
lines changed

web/src/app/pages/dashboards/[dashboardId]/index.page.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,41 @@ import { WidgetsService } from '../../../services/widgets.service';
6161
6262
<hr />
6363
</section>
64+
<hgroup>
65+
<h4>Widgets ({{ dashboardAndWidgets.widgets.length }})</h4>
66+
<p>
67+
<a
68+
href="/dashboards/{{
69+
dashboardAndWidgets.dashboard.id
70+
}}/widgets/add/clock"
71+
>Add clock</a
72+
>
73+
<a
74+
style="padding-left: 1rem;"
75+
href="/dashboards/{{
76+
dashboardAndWidgets.dashboard.id
77+
}}/widgets/add/calendar"
78+
>Add calendar</a
79+
>
80+
</p>
81+
</hgroup>
6482
65-
<h4>Widgets ({{ dashboardAndWidgets.widgets.length }})</h4>
66-
67-
<div class="grid">
68-
<a
69-
href="/dashboards/{{
70-
dashboardAndWidgets.dashboard.id
71-
}}/widgets/add/clock"
72-
>Add clock</a
73-
>
74-
<a
75-
href="/dashboards/{{
76-
dashboardAndWidgets.dashboard.id
77-
}}/widgets/add/calendar"
78-
>Add calendar</a
79-
>
80-
</div>
8183
<hr />
8284
8385
@for (widget of dashboardAndWidgets.widgets; track widget.id) {
8486
<details name="widget" open>
8587
<summary>
86-
{{ widget.type }}
87-
<a
88-
href="/dashboards/{{
89-
dashboardAndWidgets.dashboard.id
90-
}}/widgets/{{ widget.id }}"
91-
>Edit</a
92-
>
93-
<a
94-
style="padding-left: 1rem;"
95-
href="/dashboards/{{
96-
dashboardAndWidgets.dashboard.id
97-
}}/widgets/{{ widget.id }}/delete"
98-
>Delete</a
99-
>
88+
<hgroup>
89+
<h5>{{ widget.type }}</h5>
90+
<p>
91+
<a
92+
href="/dashboards/{{
93+
dashboardAndWidgets.dashboard.id
94+
}}/widgets/{{ widget.id }}"
95+
>Edit</a
96+
>
97+
</p>
98+
</hgroup>
10099
</summary>
101100
<p>{{ widget | json }}</p>
102101
</details>
@@ -129,7 +128,7 @@ export default class DashboardsEditPageComponent {
129128
dashboard => (this.model = dashboard as UpdateDashboardType)
130129
)
131130
),
132-
widgets: this.widgetsService.list(),
131+
widgets: this.widgetsService.list(dashboardId),
133132
})
134133
: of(null)
135134
),

web/src/app/pages/dashboards/[dashboardId]/widgets/[widgetId]/index.page.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ import { WidgetsService } from '../../../../../services/widgets.service';
4040
[model]="model"
4141
></formly-form>
4242
<div class="grid">
43+
<a
44+
href="/dashboards/{{ dashboardAndWidget.dashboard.id }}/widgets/{{
45+
dashboardAndWidget.widget.id
46+
}}/delete"
47+
type="button"
48+
class="secondary"
49+
>Remove</a
50+
>
4351
<button type="submit">Save</button>
4452
</div>
4553
</form>

web/src/app/pages/dashboards/[dashboardId]/widgets/add/[type]/index.page.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import { WidgetsService } from '../../../../../../services/widgets.service';
2121
<nav aria-label="breadcrumb">
2222
<ul>
2323
<li><a href="/dashboards">Dashboards</a></li>
24-
<li>{{ dashboard.name }}</li>
24+
<li>
25+
<a href="/dashboards/{{ dashboard.id }}">{{ dashboard.name }}</a>
26+
</li>
2527
<li>Add {{ model.type }}</li>
2628
</ul>
2729
</nav>

web/src/app/pages/dashboards/index.page.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import { DashboardsService } from '../../services/dashboards.service';
2222
@for (dashboard of dashboards$ | async; track dashboard.id) {
2323
<details name="dashboard" open>
2424
<summary>
25-
{{ dashboard.name }}<br />
26-
<a href="/dashboards/{{ dashboard.id }}">Edit</a>
25+
<hgroup>
26+
<h5>{{ dashboard.name }}</h5>
27+
<p>
28+
<a href="/dashboards/{{ dashboard.id }}">Edit</a>
29+
</p>
30+
</hgroup>
2731
</summary>
2832
<p>{{ dashboard | json }}</p>
2933
</details>

web/src/app/services/widgets.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
22

33
import {
44
CreateWidgetType,
5+
UpdateWidgetStateType,
56
UpdateWidgetType,
67
} from '../../server/types/WidgetSchema';
78
import { injectTrpcClient } from '../trpc-client';
@@ -28,7 +29,11 @@ export class WidgetsService {
2829
return this.trpc.widgets.delete.mutate({ id });
2930
}
3031

31-
list() {
32-
return this.trpc.widgets.list.query();
32+
list(dashboardId: string) {
33+
return this.trpc.widgets.list.query({ dashboardId });
34+
}
35+
36+
updateState(widget: UpdateWidgetStateType) {
37+
return this.trpc.widgets.updateState.mutate(widget);
3338
}
3439
}

web/src/server/trpc/routers/dashboards.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const dashboardsRouter = router({
3636
read: publicProcedure
3737
.input(
3838
z.object({
39-
id: z.string(),
39+
id: z.string().uuid(),
4040
})
4141
)
4242
.output(DashboardSchema)
@@ -76,7 +76,7 @@ export const dashboardsRouter = router({
7676
delete: publicProcedure
7777
.input(
7878
z.object({
79-
id: z.string(),
79+
id: z.string().uuid(),
8080
})
8181
)
8282
.mutation(async ({ input, ctx }) => {
@@ -130,7 +130,7 @@ export const dashboardsRouter = router({
130130
generateQrCode: publicProcedure
131131
.input(
132132
z.object({
133-
dashboardId: z.string(),
133+
dashboardId: z.string().uuid(),
134134
})
135135
)
136136
.output(GenerateQrCodeSchema)

web/src/server/trpc/routers/widgets.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const widgetsRouter = router({
4545
read: publicProcedure
4646
.input(
4747
z.object({
48-
id: z.string(),
48+
id: z.string().uuid(),
4949
})
5050
)
5151
.output(WidgetSchema)
@@ -115,7 +115,7 @@ export const widgetsRouter = router({
115115
delete: publicProcedure
116116
.input(
117117
z.object({
118-
id: z.string(),
118+
id: z.string().uuid(),
119119
})
120120
)
121121
.mutation(async ({ input, ctx }) => {
@@ -134,11 +134,13 @@ export const widgetsRouter = router({
134134
},
135135
});
136136
}),
137-
list: publicProcedure.query(async () => {
138-
return (await prisma.widget.findMany({
139-
where: { deletedAt: null },
140-
})) as WidgetType[];
141-
}),
137+
list: publicProcedure
138+
.input(z.object({ dashboardId: z.string().uuid() }))
139+
.query(async () => {
140+
return (await prisma.widget.findMany({
141+
where: { deletedAt: null },
142+
})) as WidgetType[];
143+
}),
142144
updateState: publicProcedure
143145
.input(UpdateWidgetStateSchema)
144146
.mutation(async ({ input, ctx }) => {

0 commit comments

Comments
 (0)