Add state history for task state

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-30 15:58:33 -08:00
parent 48d6f3c7fb
commit 31f750cf52
12 changed files with 1271 additions and 41 deletions

View File

@@ -192,6 +192,13 @@ type Task implements Node {
description: String!
state: TaskState!
stateTransisions(
first: Int
after: CursorKey
last: Int
before: CursorKey
): TaskStateTransitionConnection! @goField(forceResolver: true)
evidences(
first: Int
after: CursorKey
@@ -203,6 +210,25 @@ type Task implements Node {
updatedAt: Datetime!
}
type TaskStateTransitionConnection {
edges: [TaskStateTransitionEdge!]!
pageInfo: PageInfo!
}
type TaskStateTransitionEdge {
cursor: CursorKey!
node: TaskStateTransition!
}
type TaskStateTransition {
id: ID!
fromState: TaskState
toState: TaskState!
reason: String
createdAt: Datetime!
updatedAt: Datetime!
}
type EvidenceConnection {
edges: [EvidenceEdge!]!
pageInfo: PageInfo!

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package types
import (
"github.com/getprobo/probo/pkg/probo/coredata"
"github.com/getprobo/probo/pkg/probo/coredata/page"
)
func NewTaskStateTransitionConnection(
p *page.Page[*coredata.TaskStateTransition],
) *TaskStateTransitionConnection {
var edges = make([]*TaskStateTransitionEdge, len(p.Data))
for i := range edges {
edges[i] = NewTaskStateTransitionEdge(p.Data[i])
}
return &TaskStateTransitionConnection{
Edges: edges,
PageInfo: NewPageInfo(p),
}
}
func NewTaskStateTransitionEdge(tst *coredata.TaskStateTransition) *TaskStateTransitionEdge {
return &TaskStateTransitionEdge{
Cursor: tst.CursorKey(),
Node: NewTaskStateTransition(tst),
}
}
func NewTaskStateTransition(tst *coredata.TaskStateTransition) *TaskStateTransition {
var fromState *TaskState
if tst.FromState != nil {
val := TaskState((*tst.FromState).String())
fromState = &val
}
return &TaskStateTransition{
ID: tst.ID,
FromState: fromState,
ToState: TaskState(tst.ToState.String()),
Reason: tst.Reason,
CreatedAt: tst.CreatedAt,
UpdatedAt: tst.UpdatedAt,
}
}

View File

@@ -148,13 +148,14 @@ type Query struct {
}
type Task struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
State TaskState `json:"state"`
Evidences *EvidenceConnection `json:"evidences"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID gid.GID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
State TaskState `json:"state"`
StateTransisions *TaskStateTransitionConnection `json:"stateTransisions"`
Evidences *EvidenceConnection `json:"evidences"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Task) IsNode() {}
@@ -170,6 +171,25 @@ type TaskEdge struct {
Node *Task `json:"node"`
}
type TaskStateTransition struct {
ID gid.GID `json:"id"`
FromState *TaskState `json:"fromState,omitempty"`
ToState TaskState `json:"toState"`
Reason *string `json:"reason,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type TaskStateTransitionConnection struct {
Edges []*TaskStateTransitionEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type TaskStateTransitionEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *TaskStateTransition `json:"node"`
}
type Vendor struct {
ID gid.GID `json:"id"`
Name string `json:"name"`

View File

@@ -104,6 +104,18 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
return nil, gqlerror.Errorf("node %q not found", id)
}
// StateTransisions is the resolver for the stateTransisions field.
func (r *taskResolver) StateTransisions(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskStateTransitionConnection, error) {
cursor := types.NewCursor(first, after, last, before)
page, err := r.svc.ListTaskStateTransitions(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list control tasks: %w", err)
}
return types.NewTaskStateTransitionConnection(page), nil
}
// Evidences is the resolver for the evidences field.
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceConnection, error) {
cursor := types.NewCursor(first, after, last, before)