From d7a4c1ff8587ecafa8e26353a8282e7f7142f17e Mon Sep 17 00:00:00 2001 From: "Dennis (via Claude+Gemma)" Date: Sat, 23 May 2026 07:00:45 +0200 Subject: [PATCH] =?UTF-8?q?feat(saved-views):=20Saved-Filter-Views=20f?= =?UTF-8?q?=C3=BCr=20TimeEntries=20(named=20presets)=20[tsc:fail]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phase14-state.json | 3 +- .phase15-state.json | 5 + GENERATION_LOG.md | 28 ++ apps/api/src/db/schema.ts | 9 + apps/api/src/routes/saved-views.ts | 91 +++++++ apps/web/src/pages/TimeEntries.tsx | 418 ++++++++++++++++------------- scripts/phase15_features.py | 211 +++++++++++++++ 7 files changed, 573 insertions(+), 192 deletions(-) create mode 100644 .phase15-state.json create mode 100644 apps/api/src/routes/saved-views.ts create mode 100644 scripts/phase15_features.py diff --git a/.phase14-state.json b/.phase14-state.json index 5b9bb9e..dd65479 100644 --- a/.phase14-state.json +++ b/.phase14-state.json @@ -6,6 +6,7 @@ "markdown-editor", "quick-add-popover", "time-spent-widget", - "dashboard-customization" + "dashboard-customization", + "file-attach-to-entry" ] } \ No newline at end of file diff --git a/.phase15-state.json b/.phase15-state.json new file mode 100644 index 0000000..2c2af8f --- /dev/null +++ b/.phase15-state.json @@ -0,0 +1,5 @@ +{ + "completed_features": [], + "current_feature": "saved-views", + "started_at": "2026-05-23T06:57:51.069062" +} \ No newline at end of file diff --git a/GENERATION_LOG.md b/GENERATION_LOG.md index 1ed2f2b..70ec380 100644 --- a/GENERATION_LOG.md +++ b/GENERATION_LOG.md @@ -1748,3 +1748,31 @@ src/index.ts(27,25): error TS2769: No overload matches this call. Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy +- `06:55:44` **INFO** Committed feature file-attach-to-entry +- `06:55:44` **INFO** Pushed: rc=0 + +## Phase-14 Run beendet (2026-05-23 06:55:44) + +- `06:55:44` **INFO** OK: 0, Attempted: 5, Total: 5 + +## 🚀 Phase-15 Codegen-Run gestartet (2026-05-23 06:57:51) + + +## Phase-3 Feature: saved-views (2026-05-23 06:57:51) + +- `06:57:51` **INFO** Description: Saved-Filter-Views für TimeEntries (named presets) +- `06:57:51` **INFO** Generating apps/api/src/db/schema.ts (ERWEITERT — füge `savedViews` pgTable: id (uuid pk), userId (uuid refe…) +- `06:58:26` **INFO** wrote 4097 chars in 35.0s (attempt 1) +- `06:58:26` **INFO** Generating apps/api/src/routes/saved-views.ts (Fastify-Plugin /api/saved-views. CRUD: GET (list user's views, optiona…) +- `06:58:48` **INFO** wrote 2348 chars in 22.1s (attempt 1) +- `06:58:48` **INFO** Generating apps/web/src/pages/TimeEntries.tsx (ERWEITERT — füge Saved-Views-Dropdown ins Filter-Bar: Auswahl lädt Fil…) +- `07:00:44` **INFO** wrote 14967 chars in 115.9s (attempt 1) +- `07:00:44` **INFO** Running tsc --noEmit on api… +- `07:00:45` **WARN** tsc errors: +src/index.ts(27,25): error TS2769: No overload matches this call. + Overload 1 of 3, '(plugin: FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. + Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error | undefined) => void): void'. + Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. + Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index cef24b4..016b701 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -92,4 +92,13 @@ export const webhooks = pgTable("webhooks", { active: boolean("active").notNull().default(true), createdAt: timestamp("created_at").notNull().defaultNow(), createdBy: uuid("created_by").references(() => users.id) +}) + +export const savedViews = pgTable("saved_views", { + id: uuid("id").primaryKey().defaultRandom(), + userId: uuid("user_id").references(() => users.id), + name: text("name").notNull(), + entityType: text("entity_type").notNull(), + filters: text("filters").notNull(), + createdAt: timestamp("created_at").notNull().defaultNow() }) \ No newline at end of file diff --git a/apps/api/src/routes/saved-views.ts b/apps/api/src/routes/saved-views.ts new file mode 100644 index 0000000..0d0b028 --- /dev/null +++ b/apps/api/src/routes/saved-views.ts @@ -0,0 +1,91 @@ +import { FastifyInstance } from "fastify" +import { db } from "../db" +import { savedViews } from "../db/schema" +import { eq, and } from "drizzle-orm" +import { z } from "zod" + +const SavedViewSchema = z.object({ + name: z.string().min(1), + entityType: z.string(), + filters: z.record(z.any()).optional(), + sort: z.record(z.any()).optional(), +}) + +const SavedViewUpdateSchema = SavedViewSchema.partial() + +export default async function savedViewRoutes(fastify: FastifyInstance) { + fastify.addHook("preHandler", async (request, reply) => { + try { + await request.jwtVerify() + } catch (err) { + return reply.code(401).send({ message: "Unauthorized" }) + } + }) + + fastify.get("/", async (request, reply) => { + const user = request.user as any + const { entityType } = request.query as { entityType?: string } + + const conds = [eq(savedViews.userId, user.id)] + if (entityType) { + conds.push(eq(savedViews.entityType, entityType)) + } + + const results = await db + .select() + .from(savedViews) + .where(and(...conds)) + .orderBy(savedViews.name) + + return results + }) + + fastify.post("/", async (request, reply) => { + const user = request.user as any + const body = SavedViewSchema.parse(request.body) + + const [view] = await db + .insert(savedViews) + .values({ + ...body, + userId: user.id, + }) + .returning() + + return reply.code(201).send(view) + }) + + fastify.patch("/:id", async (request, reply) => { + const user = request.user as any + const { id } = request.params as { id: string } + const body = SavedViewUpdateSchema.parse(request.body) + + const [view] = await db + .update(savedViews) + .set(body) + .where(and(eq(savedViews.id, id), eq(savedViews.userId, user.id))) + .returning() + + if (!view) { + return reply.code(404).send({ message: "Saved view not found" }) + } + + return view + }) + + fastify.delete("/:id", async (request, reply) => { + const user = request.user as any + const { id } = request.params as { id: string } + + const [view] = await db + .delete(savedViews) + .where(and(eq(savedViews.id, id), eq(savedViews.userId, user.id))) + .returning() + + if (!view) { + return reply.code(404).send({ message: "Saved view not found" }) + } + + return reply.code(204).send() + }) +} \ No newline at end of file diff --git a/apps/web/src/pages/TimeEntries.tsx b/apps/web/src/pages/TimeEntries.tsx index e1d2856..674901d 100644 --- a/apps/web/src/pages/TimeEntries.tsx +++ b/apps/web/src/pages/TimeEntries.tsx @@ -3,7 +3,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query" import { api } from "../lib/api" import { EmptyState } from "../components/EmptyState" import { LoadingSpinner } from "../components/LoadingSpinner" -import type { TimeEntryInsert } from "@emberclone/shared" +import type { TimeEntryInsert, SavedView } from "@emberclone/shared" function renderSimpleMarkdown(text: string | null) { if (!text) return null @@ -47,6 +47,11 @@ export default function TimeEntries() { }) }) + const { data: savedViews } = useQuery({ + queryKey: ["saved-views", "time-entries"], + queryFn: () => api.listSavedViews({ entityType: 'time-entries' }) + }) + const createMutation = useMutation({ mutationFn: (data: Partial) => api.createTimeEntry(data), onSuccess: () => { @@ -81,6 +86,20 @@ export default function TimeEntries() { } }) + const saveViewMutation = useMutation({ + mutationFn: (view: { name: string, filters: any }) => api.createSavedView(view), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["saved-views", "time-entries"] }) + } + }) + + const deleteViewMutation = useMutation({ + mutationFn: (id: string) => api.deleteSavedView(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["saved-views", "time-entries"] }) + } + }) + const filteredEntries = useMemo(() => { if (!entries) return [] return entries.filter(entry => @@ -132,230 +151,247 @@ export default function TimeEntries() { ) } - const toggleRow = (id: string) => { - setExpandedRows(prev => ({ ...prev, [id]: !prev[id] })) + const handleSaveCurrentView = () => { + const name = prompt("Enter a name for this view:") + if (!name) return + saveViewMutation.mutate({ + name, + filters: { ...filters, entityType: 'time-entries' } + }) } - if (isError) return
Error loading time entries.
+ const applySavedView = (view: SavedView) => { + try { + const parsed = JSON.parse(view.filters) + setFilters({ + search: parsed.search || "", + from: parsed.from || "", + to: parsed.to || "" + }) + } catch (e) { + console.error("Failed to parse saved view filters", e) + } + } + + if (isError) return
Error loading time entries.
return ( -
-
-

Time Tracking

-

Manage your work logs and project hours

-
- -
-

Log New Entry

-
-
-
- - setFormData({...formData, description: e.target.value})} - /> -
-
- - setFormData({...formData, startTime: e.target.value})} - /> -
-
- - setFormData({...formData, endTime: e.target.value})} - /> -
-
-
-
- - setFormData({...formData, projectId: e.target.value})} - /> -
-
- -