Refactor DocumentSignaturesTab to DocumentSignaturesPage + fix count bug
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -4728,9 +4728,13 @@ type DocumentVersion implements Node {
|
||||
permission(action: String!): Boolean! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureConnection {
|
||||
type DocumentVersionSignatureConnection
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionSignatureConnection"
|
||||
) {
|
||||
edges: [DocumentVersionSignatureEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureEdge {
|
||||
@@ -4745,6 +4749,7 @@ input DocumentVersionSignatureOrder {
|
||||
|
||||
input DocumentVersionSignatureFilter {
|
||||
states: [DocumentVersionSignatureState!]
|
||||
activeContract: Boolean
|
||||
}
|
||||
|
||||
enum DocumentVersionSignatureState
|
||||
|
||||
@@ -67,6 +67,7 @@ type ResolverRoot interface {
|
||||
DocumentVersion() DocumentVersionResolver
|
||||
DocumentVersionConnection() DocumentVersionConnectionResolver
|
||||
DocumentVersionSignature() DocumentVersionSignatureResolver
|
||||
DocumentVersionSignatureConnection() DocumentVersionSignatureConnectionResolver
|
||||
Evidence() EvidenceResolver
|
||||
EvidenceConnection() EvidenceConnectionResolver
|
||||
File() FileResolver
|
||||
@@ -767,8 +768,9 @@ type ComplexityRoot struct {
|
||||
}
|
||||
|
||||
DocumentVersionSignatureConnection struct {
|
||||
Edges func(childComplexity int) int
|
||||
PageInfo func(childComplexity int) int
|
||||
Edges func(childComplexity int) int
|
||||
PageInfo func(childComplexity int) int
|
||||
TotalCount func(childComplexity int) int
|
||||
}
|
||||
|
||||
DocumentVersionSignatureEdge struct {
|
||||
@@ -2032,6 +2034,9 @@ type DocumentVersionSignatureResolver interface {
|
||||
|
||||
Permission(ctx context.Context, obj *types.DocumentVersionSignature, action string) (bool, error)
|
||||
}
|
||||
type DocumentVersionSignatureConnectionResolver interface {
|
||||
TotalCount(ctx context.Context, obj *types.DocumentVersionSignatureConnection) (int, error)
|
||||
}
|
||||
type EvidenceResolver interface {
|
||||
File(ctx context.Context, obj *types.Evidence) (*types.File, error)
|
||||
|
||||
@@ -4468,6 +4473,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
}
|
||||
|
||||
return e.complexity.DocumentVersionSignatureConnection.PageInfo(childComplexity), true
|
||||
case "DocumentVersionSignatureConnection.totalCount":
|
||||
if e.complexity.DocumentVersionSignatureConnection.TotalCount == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.DocumentVersionSignatureConnection.TotalCount(childComplexity), true
|
||||
|
||||
case "DocumentVersionSignatureEdge.cursor":
|
||||
if e.complexity.DocumentVersionSignatureEdge.Cursor == nil {
|
||||
@@ -15028,9 +15039,13 @@ type DocumentVersion implements Node {
|
||||
permission(action: String!): Boolean! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureConnection {
|
||||
type DocumentVersionSignatureConnection
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.DocumentVersionSignatureConnection"
|
||||
) {
|
||||
edges: [DocumentVersionSignatureEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureEdge {
|
||||
@@ -15045,6 +15060,7 @@ input DocumentVersionSignatureOrder {
|
||||
|
||||
input DocumentVersionSignatureFilter {
|
||||
states: [DocumentVersionSignatureState!]
|
||||
activeContract: Boolean
|
||||
}
|
||||
|
||||
enum DocumentVersionSignatureState
|
||||
@@ -29457,6 +29473,8 @@ func (ec *executionContext) fieldContext_DocumentVersion_signatures(ctx context.
|
||||
return ec.fieldContext_DocumentVersionSignatureConnection_edges(ctx, field)
|
||||
case "pageInfo":
|
||||
return ec.fieldContext_DocumentVersionSignatureConnection_pageInfo(ctx, field)
|
||||
case "totalCount":
|
||||
return ec.fieldContext_DocumentVersionSignatureConnection_totalCount(ctx, field)
|
||||
}
|
||||
return nil, fmt.Errorf("no field named %q was found under type DocumentVersionSignatureConnection", field.Name)
|
||||
},
|
||||
@@ -30199,7 +30217,7 @@ func (ec *executionContext) _DocumentVersionSignatureConnection_pageInfo(ctx con
|
||||
return obj.PageInfo, nil
|
||||
},
|
||||
nil,
|
||||
ec.marshalNPageInfo2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
|
||||
ec.marshalNPageInfo2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐPageInfo,
|
||||
true,
|
||||
true,
|
||||
)
|
||||
@@ -30228,6 +30246,35 @@ func (ec *executionContext) fieldContext_DocumentVersionSignatureConnection_page
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _DocumentVersionSignatureConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionSignatureConnection) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
ec.OperationContext,
|
||||
field,
|
||||
ec.fieldContext_DocumentVersionSignatureConnection_totalCount,
|
||||
func(ctx context.Context) (any, error) {
|
||||
return ec.resolvers.DocumentVersionSignatureConnection().TotalCount(ctx, obj)
|
||||
},
|
||||
nil,
|
||||
ec.marshalNInt2int,
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_DocumentVersionSignatureConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "DocumentVersionSignatureConnection",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type Int does not have child fields")
|
||||
},
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _DocumentVersionSignatureEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *types.DocumentVersionSignatureEdge) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
@@ -64805,7 +64852,7 @@ func (ec *executionContext) unmarshalInputDocumentVersionSignatureFilter(ctx con
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"states"}
|
||||
fieldsInOrder := [...]string{"states", "activeContract"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
@@ -64819,6 +64866,13 @@ func (ec *executionContext) unmarshalInputDocumentVersionSignatureFilter(ctx con
|
||||
return it, err
|
||||
}
|
||||
it.States = data
|
||||
case "activeContract":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("activeContract"))
|
||||
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.ActiveContract = data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76206,13 +76260,49 @@ func (ec *executionContext) _DocumentVersionSignatureConnection(ctx context.Cont
|
||||
case "edges":
|
||||
out.Values[i] = ec._DocumentVersionSignatureConnection_edges(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
atomic.AddUint32(&out.Invalids, 1)
|
||||
}
|
||||
case "pageInfo":
|
||||
out.Values[i] = ec._DocumentVersionSignatureConnection_pageInfo(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
atomic.AddUint32(&out.Invalids, 1)
|
||||
}
|
||||
case "totalCount":
|
||||
field := field
|
||||
|
||||
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
}
|
||||
}()
|
||||
res = ec._DocumentVersionSignatureConnection_totalCount(ctx, field, obj)
|
||||
if res == graphql.Null {
|
||||
atomic.AddUint32(&fs.Invalids, 1)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
if field.Deferrable != nil {
|
||||
dfs, ok := deferred[field.Deferrable.Label]
|
||||
di := 0
|
||||
if ok {
|
||||
dfs.AddField(field)
|
||||
di = len(dfs.Values) - 1
|
||||
} else {
|
||||
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
|
||||
deferred[field.Deferrable.Label] = dfs
|
||||
}
|
||||
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
|
||||
return innerFunc(ctx, dfs)
|
||||
})
|
||||
|
||||
// don't run the out.Concurrently() call below
|
||||
out.Values[i] = graphql.Null
|
||||
continue
|
||||
}
|
||||
|
||||
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
|
||||
@@ -16,14 +16,30 @@ package types
|
||||
|
||||
import (
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentVersionSignatureOrderBy OrderBy[coredata.DocumentVersionSignatureOrderField]
|
||||
|
||||
DocumentVersionSignatureConnection struct {
|
||||
TotalCount int
|
||||
Edges []*DocumentVersionSignatureEdge
|
||||
PageInfo PageInfo
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
Filters *coredata.DocumentVersionSignatureFilter
|
||||
}
|
||||
)
|
||||
|
||||
func NewDocumentVersionSignatureConnection(page *page.Page[*coredata.DocumentVersionSignature, coredata.DocumentVersionSignatureOrderField]) *DocumentVersionSignatureConnection {
|
||||
func NewDocumentVersionSignatureConnection(
|
||||
page *page.Page[*coredata.DocumentVersionSignature, coredata.DocumentVersionSignatureOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
filter *coredata.DocumentVersionSignatureFilter,
|
||||
) *DocumentVersionSignatureConnection {
|
||||
edges := make([]*DocumentVersionSignatureEdge, len(page.Data))
|
||||
for i, documentVersionSignature := range page.Data {
|
||||
edges[i] = NewDocumentVersionSignatureEdge(documentVersionSignature, page.Cursor.OrderBy.Field)
|
||||
@@ -31,7 +47,11 @@ func NewDocumentVersionSignatureConnection(page *page.Page[*coredata.DocumentVer
|
||||
|
||||
return &DocumentVersionSignatureConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(page),
|
||||
PageInfo: *NewPageInfo(page),
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
Filters: filter,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1201,18 +1201,14 @@ type DocumentVersionSignature struct {
|
||||
func (DocumentVersionSignature) IsNode() {}
|
||||
func (this DocumentVersionSignature) GetID() gid.GID { return this.ID }
|
||||
|
||||
type DocumentVersionSignatureConnection struct {
|
||||
Edges []*DocumentVersionSignatureEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *DocumentVersionSignature `json:"node"`
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureFilter struct {
|
||||
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
|
||||
States []coredata.DocumentVersionSignatureState `json:"states,omitempty"`
|
||||
ActiveContract *bool `json:"activeContract,omitempty"`
|
||||
}
|
||||
|
||||
type DocumentVersionSignatureOrder struct {
|
||||
|
||||
@@ -1080,10 +1080,16 @@ func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.Doc
|
||||
}
|
||||
|
||||
var signatureStates []coredata.DocumentVersionSignatureState
|
||||
if filter != nil && filter.States != nil {
|
||||
signatureStates = filter.States
|
||||
var activeContract *bool
|
||||
if filter != nil {
|
||||
if filter.States != nil {
|
||||
signatureStates = filter.States
|
||||
}
|
||||
if filter.ActiveContract != nil {
|
||||
activeContract = filter.ActiveContract
|
||||
}
|
||||
}
|
||||
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates)
|
||||
signatureFilter := coredata.NewDocumentVersionSignatureFilter(signatureStates, activeContract)
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
@@ -1093,7 +1099,7 @@ func (r *documentVersionResolver) Signatures(ctx context.Context, obj *types.Doc
|
||||
panic(fmt.Errorf("cannot list document version signatures: %w", err))
|
||||
}
|
||||
|
||||
return types.NewDocumentVersionSignatureConnection(page), nil
|
||||
return types.NewDocumentVersionSignatureConnection(page, r, obj.ID, signatureFilter), nil
|
||||
}
|
||||
|
||||
// Signed is the resolver for the signed field.
|
||||
@@ -1122,7 +1128,7 @@ func (r *documentVersionResolver) Permission(ctx context.Context, obj *types.Doc
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *documentVersionConnectionResolver) TotalCount(ctx context.Context, obj *types.DocumentVersionConnection) (int, error) {
|
||||
if err := r.authorize(ctx, obj.ParentID, probo.ActionEvidenceList); err != nil {
|
||||
if err := r.authorize(ctx, obj.ParentID, probo.ActionDocumentVersionList); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -1137,7 +1143,7 @@ func (r *documentVersionConnectionResolver) TotalCount(ctx context.Context, obj
|
||||
count, err := prb.Documents.CountVersionsForDocumentID(ctx, obj.ParentID, filter)
|
||||
if err != nil {
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("cannot count tasks: %w", err))
|
||||
panic(fmt.Errorf("cannot count document versions: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -1189,6 +1195,32 @@ func (r *documentVersionSignatureResolver) Permission(ctx context.Context, obj *
|
||||
return r.Resolver.Permission(ctx, obj, action)
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *documentVersionSignatureConnectionResolver) TotalCount(ctx context.Context, obj *types.DocumentVersionSignatureConnection) (int, error) {
|
||||
if err := r.authorize(ctx, obj.ParentID, probo.ActionDocumentVersionSignatureList); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *documentVersionResolver:
|
||||
filter := &coredata.DocumentVersionSignatureFilter{}
|
||||
if obj.Filters != nil {
|
||||
filter = obj.Filters
|
||||
}
|
||||
count, err := prb.Documents.CountSignaturesForVersionID(ctx, obj.ParentID, filter)
|
||||
if err != nil {
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("cannot count signatures: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
||||
}
|
||||
|
||||
// File is the resolver for the file field.
|
||||
func (r *evidenceResolver) File(ctx context.Context, obj *types.Evidence) (*types.File, error) {
|
||||
if err := r.authorize(ctx, obj.ID, probo.ActionFileGet); err != nil {
|
||||
@@ -1277,14 +1309,14 @@ func (r *evidenceConnectionResolver) TotalCount(ctx context.Context, obj *types.
|
||||
count, err := prb.Evidences.CountForMeasureID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("cannot count tasks: %w", err))
|
||||
panic(fmt.Errorf("cannot count measure evidence: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
case *taskResolver:
|
||||
count, err := prb.Evidences.CountForTaskID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("cannot count tasks: %w", err))
|
||||
panic(fmt.Errorf("cannot count task evidence: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -8558,6 +8590,11 @@ func (r *Resolver) DocumentVersionSignature() schema.DocumentVersionSignatureRes
|
||||
return &documentVersionSignatureResolver{r}
|
||||
}
|
||||
|
||||
// DocumentVersionSignatureConnection returns schema.DocumentVersionSignatureConnectionResolver implementation.
|
||||
func (r *Resolver) DocumentVersionSignatureConnection() schema.DocumentVersionSignatureConnectionResolver {
|
||||
return &documentVersionSignatureConnectionResolver{r}
|
||||
}
|
||||
|
||||
// Evidence returns schema.EvidenceResolver implementation.
|
||||
func (r *Resolver) Evidence() schema.EvidenceResolver { return &evidenceResolver{r} }
|
||||
|
||||
@@ -8787,6 +8824,7 @@ type documentConnectionResolver struct{ *Resolver }
|
||||
type documentVersionResolver struct{ *Resolver }
|
||||
type documentVersionConnectionResolver struct{ *Resolver }
|
||||
type documentVersionSignatureResolver struct{ *Resolver }
|
||||
type documentVersionSignatureConnectionResolver struct{ *Resolver }
|
||||
type evidenceResolver struct{ *Resolver }
|
||||
type evidenceConnectionResolver struct{ *Resolver }
|
||||
type fileResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user