From 1cc2bd303e9379291fefa33eed14d488d50a8af6 Mon Sep 17 00:00:00 2001 From: frag223 Date: Fri, 16 Jan 2026 13:38:35 +1100 Subject: [PATCH] improving nav and removing dead code --- .../src/lib/components/nav/nav_header.svelte | 24 ++++- internal/database/insights.sql.gen.go | 91 ------------------- internal/database/queries/insights.sql | 33 ------- internal/watchtower/interfaces.go | 10 -- 4 files changed, 19 insertions(+), 139 deletions(-) diff --git a/frontend/src/lib/components/nav/nav_header.svelte b/frontend/src/lib/components/nav/nav_header.svelte index 50442b1..2131aa7 100644 --- a/frontend/src/lib/components/nav/nav_header.svelte +++ b/frontend/src/lib/components/nav/nav_header.svelte @@ -4,6 +4,8 @@ import { fade } from "svelte/transition"; import { transitionConfig } from "$components/nav/transitions"; import { organisations } from "$lib/wailsjs/go/models"; + import { orgSvc } from "$lib/watchtower"; + import { goto, invalidateAll } from "$app/navigation"; type Props = { expand?: boolean; currentOrg: organisations.OrganisationDTO; @@ -33,6 +35,12 @@ let otherOrgs = $derived.by(() => { return allOrgs.filter((o) => o.id !== currentOrg.id); }); + + async function switchOrganisation(orgId: number) { + await orgSvc.setDefault(orgId); + await invalidateAll(); + await goto(resolve("/dashboard")); + }
@@ -60,16 +68,22 @@ Active Organisation - - - {currentOrg.friendly_name} - + { + await switchOrganisation(currentOrg.id); + }} + > + {currentOrg.friendly_name} {#if otherOrgs.length > 0} Other Organisations {#each otherOrgs as org (org.id)} - + { + await switchOrganisation(org.id); + }} + > {org.friendly_name} diff --git a/internal/database/insights.sql.gen.go b/internal/database/insights.sql.gen.go index 0709f51..685beca 100644 --- a/internal/database/insights.sql.gen.go +++ b/internal/database/insights.sql.gen.go @@ -10,52 +10,6 @@ import ( "database/sql" ) -const getPullRequestInsights = `-- name: GetPullRequestInsights :one -WITH average_days_to_merge AS ( - SELECT ROUND((merged_at - created_at) / 86400.0, 2) AS avg_days_to_merge - FROM pull_requests - WHERE state = 'MERGED' - AND created_at >= strftime('%s', 'now', ?) -) -SELECT - ROUND(MIN(avg_days_to_merge),2) AS min_days_to_merge, - ROUND(MAX(avg_days_to_merge),2) AS max_days_to_merge, - ROUND(AVG(avg_days_to_merge),2) AS avg_days_to_merge, - COUNT(*) AS merged, - (SELECT COUNT(*) FROM pull_requests WHERE state = 'CLOSED' AND created_at >= strftime('%s', 'now', ?)) AS closed, - (SELECT COUNT(*) FROM pull_requests WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open -FROM average_days_to_merge -` - -type GetPullRequestInsightsParams struct { - Strftime interface{} - Strftime_2 interface{} - Strftime_3 interface{} -} - -type GetPullRequestInsightsRow struct { - MinDaysToMerge float64 - MaxDaysToMerge float64 - AvgDaysToMerge float64 - Merged int64 - Closed int64 - Open int64 -} - -func (q *Queries) GetPullRequestInsights(ctx context.Context, arg GetPullRequestInsightsParams) (GetPullRequestInsightsRow, error) { - row := q.db.QueryRowContext(ctx, getPullRequestInsights, arg.Strftime, arg.Strftime_2, arg.Strftime_3) - var i GetPullRequestInsightsRow - err := row.Scan( - &i.MinDaysToMerge, - &i.MaxDaysToMerge, - &i.AvgDaysToMerge, - &i.Merged, - &i.Closed, - &i.Open, - ) - return i, err -} - const getPullRequestInsightsByOrg = `-- name: GetPullRequestInsightsByOrg :one WITH pull_request_with_org AS ( @@ -122,51 +76,6 @@ func (q *Queries) GetPullRequestInsightsByOrg(ctx context.Context, arg GetPullRe return i, err } -const getSecuritiesInsights = `-- name: GetSecuritiesInsights :one -WITH average_days_to_fix AS ( - SELECT ROUND((fixed_at - created_at) / 86400, 2) as days_to_fix - FROM securities - WHERE state = 'FIXED' - AND fixed_at IS NOT NULL - AND created_at >= strftime('%s', 'now', ?) -) -SELECT - ROUND(MIN(days_to_fix), 2) AS min_days_to_fix, - ROUND(MAX(days_to_fix), 2) AS max_days_to_fix, - ROUND(AVG(days_to_fix), 2) AS avg_days_to_fix, - (SELECT COUNT(*) FROM securities WHERE state = 'FIXED' AND created_at >= strftime('%s', 'now', ?)) AS fixed, - (SELECT COUNT(*) FROM securities WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open - -FROM average_days_to_fix -` - -type GetSecuritiesInsightsParams struct { - Strftime interface{} - Strftime_2 interface{} - Strftime_3 interface{} -} - -type GetSecuritiesInsightsRow struct { - MinDaysToFix float64 - MaxDaysToFix float64 - AvgDaysToFix float64 - Fixed int64 - Open int64 -} - -func (q *Queries) GetSecuritiesInsights(ctx context.Context, arg GetSecuritiesInsightsParams) (GetSecuritiesInsightsRow, error) { - row := q.db.QueryRowContext(ctx, getSecuritiesInsights, arg.Strftime, arg.Strftime_2, arg.Strftime_3) - var i GetSecuritiesInsightsRow - err := row.Scan( - &i.MinDaysToFix, - &i.MaxDaysToFix, - &i.AvgDaysToFix, - &i.Fixed, - &i.Open, - ) - return i, err -} - const getSecuritiesInsightsByOrg = `-- name: GetSecuritiesInsightsByOrg :one WITH securities_with_org AS ( diff --git a/internal/database/queries/insights.sql b/internal/database/queries/insights.sql index 6f4aac4..2d573c6 100644 --- a/internal/database/queries/insights.sql +++ b/internal/database/queries/insights.sql @@ -1,36 +1,3 @@ --- name: GetPullRequestInsights :one -WITH average_days_to_merge AS ( - SELECT ROUND((merged_at - created_at) / 86400.0, 2) AS avg_days_to_merge - FROM pull_requests - WHERE state = 'MERGED' - AND created_at >= strftime('%s', 'now', ?) -) -SELECT - ROUND(MIN(avg_days_to_merge),2) AS min_days_to_merge, - ROUND(MAX(avg_days_to_merge),2) AS max_days_to_merge, - ROUND(AVG(avg_days_to_merge),2) AS avg_days_to_merge, - COUNT(*) AS merged, - (SELECT COUNT(*) FROM pull_requests WHERE state = 'CLOSED' AND created_at >= strftime('%s', 'now', ?)) AS closed, - (SELECT COUNT(*) FROM pull_requests WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open -FROM average_days_to_merge; - --- name: GetSecuritiesInsights :one -WITH average_days_to_fix AS ( - SELECT ROUND((fixed_at - created_at) / 86400, 2) as days_to_fix - FROM securities - WHERE state = 'FIXED' - AND fixed_at IS NOT NULL - AND created_at >= strftime('%s', 'now', ?) -) -SELECT - ROUND(MIN(days_to_fix), 2) AS min_days_to_fix, - ROUND(MAX(days_to_fix), 2) AS max_days_to_fix, - ROUND(AVG(days_to_fix), 2) AS avg_days_to_fix, - (SELECT COUNT(*) FROM securities WHERE state = 'FIXED' AND created_at >= strftime('%s', 'now', ?)) AS fixed, - (SELECT COUNT(*) FROM securities WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open - -FROM average_days_to_fix; - -- name: GetPullRequestInsightsByOrg :one WITH pull_request_with_org AS ( diff --git a/internal/watchtower/interfaces.go b/internal/watchtower/interfaces.go index 76ca21e..df27ac8 100644 --- a/internal/watchtower/interfaces.go +++ b/internal/watchtower/interfaces.go @@ -1,9 +1,6 @@ package watchtower import ( - "context" - "watchtower/internal/database" - "watchtower/internal/github" ) @@ -13,10 +10,3 @@ type ghClient interface { SearchRepos(owner string, topic string, token string) (github.QuerySearch[github.Repository], error) GetRepoDetails(owner string, repo string, token string) (github.QueryRepository, error) } - -type InsightsStore interface { - GetPullRequestInsights(ctx context.Context, arg database.GetPullRequestInsightsParams) (database.GetPullRequestInsightsRow, error) - GetSecuritiesInsights(ctx context.Context, arg database.GetSecuritiesInsightsParams) (database.GetSecuritiesInsightsRow, error) -} - -var _ InsightsStore = (*database.Queries)(nil)