refactor: move integrations to top-level settings with install-wide configs (#787)
* refactor: move integrations to top-level settings with install-wide configs Jira and Linear configurations are now install-wide singletons rather than per-workspace duplicates, and the GitHub/Jira/Linear settings pages live under /settings/integrations instead of being nested inside each workspace. Issue and PR watchers stay per-workspace via a workspace switcher inside each integration page. Backend ships one-shot migrations that promote the most-recently-updated row and copy its secret onto the new global key. * fix: address review feedback on integrations refactor Fix migration crash on installs whose jira_configs predate the auth-health columns by selecting only guaranteed-present legacy columns and falling back to defaults for the rest. Cover the empty-legacy-table and pre-health-columns upgrade paths with new store tests. On the frontend, refactor useIntegrationEnabled to take string parameters instead of an inline options object so getSnapshot stays referentially stable across renders, and stop dispatching a misleading no-op sync event when localStorage.setItem fails in private mode. * fix: hydrate workspace list on integration settings pages The integration pages wrapped their content in a fresh StateProvider, which created a nested store scope with an empty initial state and shadowed the settings layout's hydrated workspace list. WorkspaceScopedSection then saw zero workspaces and rendered the "Create a workspace to configure this integration" empty state even when the user had workspaces. Drop the redundant StateProvider from the jira and linear pages so they share the layout's store. The github page switches to StateHydrator so it can still seed the GitHub OAuth status without resetting the rest of the store. * refactor(integrations): flatten watcher tables, pick workspace in create dialog Hiding watchers behind a workspace switcher made the list invisible at a glance — a user with multiple workspaces had to flip between each one to see what was configured. Replace the switcher with a flat table that lists every watch across every workspace, with a Workspace column for context, and move workspace selection into the create dialog so the user picks once when the watcher is born. Backend: jira list-issue-watches and github list-review-watches / list-issue-watches accept the workspace_id query param as optional; when omitted, the corresponding store ListAll* method returns rows across every workspace. Per-row mutations still require workspace_id as the IDOR guard. Frontend: useReviewWatches / useIssueWatches / useJiraIssueWatches gain a three-state contract — string for one workspace, undefined for all workspaces, null to skip fetching. Watch tables grow an optional showWorkspace column. Watch dialogs accept an optional workspaceId prop; when absent, the dialog renders a workspace dropdown for the create flow (disabled when editing existing rows so refs aren't orphaned). Github review-watch-dialog crossed the 600-line lint cap so the prompt editor moved to review-watch-prompt-field.tsx. * fix(integrations): make watcher step dropdown reactive across workspace switches Switching to a workspace whose workflows had to be fetched left the workflow step dropdown stuck — the user could pick a workflow but the step Select either showed the previous workflow's steps or appeared inert. The cause was the per-dialog useWorkflowSteps hook deferring its empty-state reset via Promise.resolve().then(() => setSteps([])) to dodge a setState-in-effect lint rule, which let stale steps survive into the next render and gave Radix nothing to anchor the popover to during the in-flight fetch. Hoist the hook into a shared useWorkflowSteps that resets via React's official setState-during-render pattern, exposes a loading flag, and returns a stepPlaceholder helper so the Select can render "Loading steps…" or "No steps in this workflow" instead of an empty popover. The Step Select is now also disabled while loading or when there are no steps, making the state of the dropdown unambiguous. * fix: address PR review feedback on integrations refactor Backend: - linear migration: add column-presence guard mirroring the Jira fix so installs that upgraded from the original Linear schema (without org_slug / last_checked_at / last_ok / last_error) don't crash startup with "no such column"; add TestStore_MigrateLegacyPerWorkspaceTable_PreHealthColumns - jira/handlers.go: drop the now-unused errMsgWorkspaceIDRequired constant that was failing golangci-lint - jira/mock_controller_test.go (new): cover setAuthHealth happy-path and invalid-JSON-rejection so the singleton-shaped payload is locked in Frontend: - useIntegrationAvailable: gate the auth-health probe on loaded && enabled so disabled integrations don't poll /config every 90s - use-workflow-steps: initialize loading to !!workflowId so edit-mode opens show "Loading steps…" instead of "No steps in this workflow" before the first fetch lands - use-workflow-steps.test.ts (new): cover the empty/non-empty workflowId, workflow switch, fetch error, and stepPlaceholder branches - use-linear-enabled.test: tighten the legacy-key migration assertion to pin the migrated value rather than just verifying key cleanup --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
This commit is contained in:
@@ -14,11 +14,6 @@ import (
|
||||
ws "github.com/kandev/kandev/pkg/websocket"
|
||||
)
|
||||
|
||||
// errMsgWorkspaceIDRequired is the response body returned when a handler is
|
||||
// invoked without the workspace_id query parameter. Centralised because the
|
||||
// linter flags repeated string literals at three or more occurrences.
|
||||
const errMsgWorkspaceIDRequired = "workspace_id required"
|
||||
|
||||
// RegisterRoutes wires the Linear HTTP and WebSocket handlers.
|
||||
func RegisterRoutes(router *gin.Engine, dispatcher *ws.Dispatcher, svc *Service, log *logger.Logger) {
|
||||
ctrl := &Controller{service: svc, logger: log}
|
||||
@@ -49,12 +44,7 @@ func (c *Controller) RegisterHTTPRoutes(router *gin.Engine) {
|
||||
// --- HTTP handlers ---
|
||||
|
||||
func (c *Controller) httpGetConfig(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
cfg, err := c.service.GetConfig(ctx.Request.Context(), workspaceID)
|
||||
cfg, err := c.service.GetConfig(ctx.Request.Context())
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -85,12 +75,7 @@ func (c *Controller) httpSetConfig(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpDeleteConfig(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
if err := c.service.DeleteConfig(ctx.Request.Context(), workspaceID); err != nil {
|
||||
if err := c.service.DeleteConfig(ctx.Request.Context()); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -112,12 +97,7 @@ func (c *Controller) httpTestConfig(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpListTeams(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
teams, err := c.service.ListTeams(ctx.Request.Context(), workspaceID)
|
||||
teams, err := c.service.ListTeams(ctx.Request.Context())
|
||||
if err != nil {
|
||||
c.writeClientError(ctx, err)
|
||||
return
|
||||
@@ -126,13 +106,12 @@ func (c *Controller) httpListTeams(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpListStates(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
teamKey := ctx.Query("team_key")
|
||||
if workspaceID == "" || teamKey == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "workspace_id and team_key required"})
|
||||
if teamKey == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "team_key required"})
|
||||
return
|
||||
}
|
||||
states, err := c.service.ListStates(ctx.Request.Context(), workspaceID, teamKey)
|
||||
states, err := c.service.ListStates(ctx.Request.Context(), teamKey)
|
||||
if err != nil {
|
||||
c.writeClientError(ctx, err)
|
||||
return
|
||||
@@ -141,11 +120,6 @@ func (c *Controller) httpListStates(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpSearchIssues(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
filter := SearchFilter{
|
||||
Query: ctx.Query("query"),
|
||||
TeamKey: ctx.Query("team_key"),
|
||||
@@ -156,7 +130,7 @@ func (c *Controller) httpSearchIssues(ctx *gin.Context) {
|
||||
}
|
||||
pageToken := ctx.Query("page_token")
|
||||
maxResults, _ := strconv.Atoi(ctx.Query("max_results"))
|
||||
result, err := c.service.SearchIssues(ctx.Request.Context(), workspaceID, filter, pageToken, maxResults)
|
||||
result, err := c.service.SearchIssues(ctx.Request.Context(), filter, pageToken, maxResults)
|
||||
if err != nil {
|
||||
c.writeClientError(ctx, err)
|
||||
return
|
||||
@@ -165,13 +139,8 @@ func (c *Controller) httpSearchIssues(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpGetIssue(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
id := ctx.Param("id")
|
||||
issue, err := c.service.GetIssue(ctx.Request.Context(), workspaceID, id)
|
||||
issue, err := c.service.GetIssue(ctx.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.writeClientError(ctx, err)
|
||||
return
|
||||
@@ -180,11 +149,6 @@ func (c *Controller) httpGetIssue(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func (c *Controller) httpSetIssueState(ctx *gin.Context) {
|
||||
workspaceID := ctx.Query("workspace_id")
|
||||
if workspaceID == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": errMsgWorkspaceIDRequired})
|
||||
return
|
||||
}
|
||||
id := ctx.Param("id")
|
||||
var req struct {
|
||||
StateID string `json:"stateId"`
|
||||
@@ -193,7 +157,7 @@ func (c *Controller) httpSetIssueState(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "stateId required"})
|
||||
return
|
||||
}
|
||||
if err := c.service.SetIssueState(ctx.Request.Context(), workspaceID, id, req.StateID); err != nil {
|
||||
if err := c.service.SetIssueState(ctx.Request.Context(), id, req.StateID); err != nil {
|
||||
c.writeClientError(ctx, err)
|
||||
return
|
||||
}
|
||||
@@ -201,14 +165,14 @@ func (c *Controller) httpSetIssueState(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// errCodeLinearNotConfigured is the wire-level code surfaced to the UI when
|
||||
// the workspace has no saved Linear credentials.
|
||||
// Linear has no saved credentials.
|
||||
const errCodeLinearNotConfigured = "LINEAR_NOT_CONFIGURED"
|
||||
|
||||
// writeClientError maps service-level errors to HTTP responses.
|
||||
func (c *Controller) writeClientError(ctx *gin.Context, err error) {
|
||||
if errors.Is(err, ErrNotConfigured) {
|
||||
ctx.JSON(http.StatusServiceUnavailable, gin.H{
|
||||
"error": "Linear is not configured for this workspace",
|
||||
"error": "Linear is not configured",
|
||||
"code": errCodeLinearNotConfigured,
|
||||
})
|
||||
return
|
||||
@@ -268,13 +232,7 @@ func wsFail(msg *ws.Message, err error) (*ws.Message, error) {
|
||||
|
||||
func wsGetConfig(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
return func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
var p struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
}
|
||||
if err := msg.ParsePayload(&p); err != nil || p.WorkspaceID == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "workspaceId required", nil)
|
||||
}
|
||||
cfg, err := svc.GetConfig(ctx, p.WorkspaceID)
|
||||
cfg, err := svc.GetConfig(ctx)
|
||||
if err != nil {
|
||||
return wsFail(msg, err)
|
||||
}
|
||||
@@ -301,13 +259,7 @@ func wsSetConfig(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.M
|
||||
|
||||
func wsDeleteConfig(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
return func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
var p struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
}
|
||||
if err := msg.ParsePayload(&p); err != nil || p.WorkspaceID == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "workspaceId required", nil)
|
||||
}
|
||||
if err := svc.DeleteConfig(ctx, p.WorkspaceID); err != nil {
|
||||
if err := svc.DeleteConfig(ctx); err != nil {
|
||||
return wsFail(msg, err)
|
||||
}
|
||||
return wsReply(msg, gin.H{"deleted": true})
|
||||
@@ -331,16 +283,15 @@ func wsTestConfig(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.
|
||||
func wsGetIssue(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
return func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
var p struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
Identifier string `json:"identifier"`
|
||||
Identifier string `json:"identifier"`
|
||||
}
|
||||
if err := msg.ParsePayload(&p); err != nil {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "invalid payload", nil)
|
||||
}
|
||||
if p.WorkspaceID == "" || p.Identifier == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "workspaceId and identifier required", nil)
|
||||
if p.Identifier == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "identifier required", nil)
|
||||
}
|
||||
issue, err := svc.GetIssue(ctx, p.WorkspaceID, p.Identifier)
|
||||
issue, err := svc.GetIssue(ctx, p.Identifier)
|
||||
if err != nil {
|
||||
return wsFail(msg, err)
|
||||
}
|
||||
@@ -351,17 +302,16 @@ func wsGetIssue(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Me
|
||||
func wsSetIssueState(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
return func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
var p struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
IssueID string `json:"issueId"`
|
||||
StateID string `json:"stateId"`
|
||||
IssueID string `json:"issueId"`
|
||||
StateID string `json:"stateId"`
|
||||
}
|
||||
if err := msg.ParsePayload(&p); err != nil {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "invalid payload", nil)
|
||||
}
|
||||
if p.WorkspaceID == "" || p.IssueID == "" || p.StateID == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "workspaceId, issueId, stateId required", nil)
|
||||
if p.IssueID == "" || p.StateID == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "issueId and stateId required", nil)
|
||||
}
|
||||
if err := svc.SetIssueState(ctx, p.WorkspaceID, p.IssueID, p.StateID); err != nil {
|
||||
if err := svc.SetIssueState(ctx, p.IssueID, p.StateID); err != nil {
|
||||
return wsFail(msg, err)
|
||||
}
|
||||
return wsReply(msg, gin.H{"transitioned": true})
|
||||
@@ -370,13 +320,7 @@ func wsSetIssueState(svc *Service) func(ctx context.Context, msg *ws.Message) (*
|
||||
|
||||
func wsListTeams(svc *Service) func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
return func(ctx context.Context, msg *ws.Message) (*ws.Message, error) {
|
||||
var p struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
}
|
||||
if err := msg.ParsePayload(&p); err != nil || p.WorkspaceID == "" {
|
||||
return ws.NewError(msg.ID, msg.Action, ws.ErrorCodeBadRequest, "workspaceId required", nil)
|
||||
}
|
||||
teams, err := svc.ListTeams(ctx, p.WorkspaceID)
|
||||
teams, err := svc.ListTeams(ctx)
|
||||
if err != nil {
|
||||
return wsFail(msg, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user