Use datum filter everywhere

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-29 16:03:33 +02:00
parent 2c237b5bfa
commit ad56142798
9 changed files with 27 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<453e3cd4a7a9fdbacd183d097ec95a05>>
* @generated SignedSource<<7e67f2a3d41fbea46b7b8447595302a5>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -316,7 +316,6 @@ return {
"alias": null,
"args": (v5/*: any*/),
"filters": [
"orderBy",
"filter"
],
"handle": "connection",

View File

@@ -54,7 +54,7 @@ const paginatedDataFragment = graphql`
before: $before
orderBy: $order
filter: { snapshotId: $snapshotId }
) @connection(key: "DataPage_data") {
) @connection(key: "DataPage_data", filters: ["filter"]) {
__id
edges {
node {

View File

@@ -59,7 +59,11 @@ export default function DatumDetailsPage(props: Props) {
const deleteDatum = useDeleteDatum(
datumEntry,
ConnectionHandler.getConnectionID(organizationId, "DataPage_data"),
ConnectionHandler.getConnectionID(
organizationId,
"DataPage_data",
{ filter: { snapshotId: snapshotId || null } }
),
);
const vendors = datumEntry?.vendors?.edges.map(edge => edge.node) ?? [];

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<8364d9457b59a3ef50b508ab55991638>>
* @generated SignedSource<<2000fd2ccfcf4b832c51ff71b0326fef>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -394,7 +394,6 @@ return {
"alias": null,
"args": (v15/*: any*/),
"filters": [
"orderBy",
"filter"
],
"handle": "connection",
@@ -422,6 +421,6 @@ return {
};
})();
(node as any).hash = "a60d9b34a83df89eb59ffcd359903ce8";
(node as any).hash = "5d3069a0d856613ccb854033b5b1f14e";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<17f6d8607b6d2a1b575e1251019b8375>>
* @generated SignedSource<<9619ee8f74aea67be931f8c40a8815c8>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -143,11 +143,6 @@ return {
],
"kind": "ObjectValue",
"name": "filter"
},
{
"kind": "Variable",
"name": "orderBy",
"variableName": "order"
}
],
"concreteType": "DatumConnection",
@@ -334,6 +329,6 @@ return {
};
})();
(node as any).hash = "a60d9b34a83df89eb59ffcd359903ce8";
(node as any).hash = "5d3069a0d856613ccb854033b5b1f14e";
export default node;

View File

@@ -153,6 +153,7 @@ func (d *Data) CountByOrganizationID(
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
filter *DatumFilter,
) (int, error) {
q := `
SELECT
@@ -162,12 +163,14 @@ FROM
WHERE
%s
AND organization_id = @organization_id
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment())
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, filter.SQLArguments())
row := conn.QueryRow(ctx, q, args)

View File

@@ -88,6 +88,7 @@ func (s DatumService) GetByOwnerID(
func (s DatumService) CountForOrganizationID(
ctx context.Context,
organizationID gid.GID,
filter *coredata.DatumFilter,
) (int, error) {
var count int
@@ -95,7 +96,7 @@ func (s DatumService) CountForOrganizationID(
ctx,
func(conn pg.Conn) (err error) {
data := coredata.Data{}
count, err = data.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
count, err = data.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID, filter)
if err != nil {
return fmt.Errorf("cannot count data: %w", err)
}

View File

@@ -30,6 +30,7 @@ type (
Resolver any
ParentID gid.GID
Filter *DatumFilter
}
)
@@ -37,6 +38,7 @@ func NewDataConnection(
p *page.Page[*coredata.Datum, coredata.DatumOrderField],
parentType any,
parentID gid.GID,
filter *DatumFilter,
) *DatumConnection {
edges := make([]*DatumEdge, len(p.Data))
for i, datum := range p.Data {
@@ -49,6 +51,7 @@ func NewDataConnection(
Resolver: parentType,
ParentID: parentID,
Filter: filter,
}
}

View File

@@ -558,7 +558,12 @@ func (r *datumConnectionResolver) TotalCount(ctx context.Context, obj *types.Dat
switch obj.Resolver.(type) {
case *organizationResolver:
count, err := prb.Data.CountForOrganizationID(ctx, obj.ParentID)
datumFilter := coredata.NewDatumFilter(nil)
if obj.Filter != nil {
datumFilter = coredata.NewDatumFilter(&obj.Filter.SnapshotID)
}
count, err := prb.Data.CountForOrganizationID(ctx, obj.ParentID, datumFilter)
if err != nil {
return 0, fmt.Errorf("cannot count data: %w", err)
}
@@ -3672,7 +3677,7 @@ func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization
panic(fmt.Errorf("cannot list organization data: %w", err))
}
return types.NewDataConnection(page, r, obj.ID), nil
return types.NewDataConnection(page, r, obj.ID, filter), nil
}
// Audits is the resolver for the audits field.