Skip to content

Commit ae0ac0a

Browse files
authored
feat: filter entries by isRead and isStarred (#485)
1 parent 4c83c41 commit ae0ac0a

File tree

4 files changed

+464
-13
lines changed

4 files changed

+464
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
## [Unreleased]
44

55
- feat: Deprecate `PhoneField.phoneFormat` in favor of `PhoneField.phoneFormatType`, and add new `GfPhoneFormat` type. Props @chetanupare, @justlevine.
6+
- feat: Add support for filtering entries by `isRead` and `isStarred` statuses.
67
- fix: Correctly resolve `AddressField.defaultState`, `AddressField.defaultProvince` based on the `addressType`. H/t @byanko-bot
78
- fix: Set the default `AddressField.inputs.label` for the State/Province and Zip/Postal inputs based on the `addressType`. H/t @byanko-bot
89
- chore: Update Composer and NPM deps.
910
- tests: Improve cleanup and factory instantiation for better local isolation.
11+
- tests: Backfill tests for Entry connection args.
1012

1113
## [v0.13.3]
1214

src/Connection/EntriesConnection.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function register(): void {
6060
'fromType' => 'RootQuery',
6161
'toType' => SubmittedEntry::$type,
6262
'fromFieldName' => 'gfSubmittedEntries',
63-
'connectionArgs' => self::get_filtered_connection_args( [ 'formIds', 'dateFilters', 'fieldFilters', 'fieldFiltersMode', 'orderby', 'status' ] ),
63+
'connectionArgs' => self::get_filtered_connection_args( [ 'formIds', 'dateFilters', 'fieldFilters', 'fieldFiltersMode', 'isRead', 'isStarred', 'orderby', 'status' ] ),
6464
'resolve' => static function ( $root, array $args, AppContext $context, ResolveInfo $info ) {
6565
return Factory::resolve_entries_connection( $root, $args, $context, $info );
6666
},
@@ -82,10 +82,6 @@ public static function get_connection_args(): array {
8282
'type' => EntryTypeEnum::$type,
8383
'description' => static fn () => __( 'Entry status. Default is `SUBMITTED`. Currently no other types are supported.', 'wp-graphql-gravity-forms' ),
8484
],
85-
'formIds' => [
86-
'type' => [ 'list_of' => 'ID' ],
87-
'description' => static fn () => __( 'Array of form IDs to limit the entries to. Exclude this argument to query all forms.', 'wp-graphql-gravity-forms' ),
88-
],
8985
'fieldFilters' => [
9086
'type' => [ 'list_of' => EntriesFieldFiltersInput::$type ],
9187
'description' => static fn () => __( 'Field-specific filters to apply.', 'wp-graphql-gravity-forms' ),
@@ -94,6 +90,18 @@ public static function get_connection_args(): array {
9490
'type' => FieldFiltersModeEnum::$type,
9591
'description' => static fn () => __( 'Whether to filter by ALL or ANY of the field filters. Default is ALL.', 'wp-graphql-gravity-forms' ),
9692
],
93+
'formIds' => [
94+
'type' => [ 'list_of' => 'ID' ],
95+
'description' => static fn () => __( 'Array of form IDs to limit the entries to. Exclude this argument to query all forms.', 'wp-graphql-gravity-forms' ),
96+
],
97+
'isRead' => [
98+
'type' => 'Boolean',
99+
'description' => static fn () => __( 'Whether to limit to read or unread entries. Default is to include both.', 'wp-graphql-gravity-forms' ),
100+
],
101+
'isStarred' => [
102+
'type' => 'Boolean',
103+
'description' => static fn () => __( 'Whether to limit to starred or unstarred entries. Default is to include both.', 'wp-graphql-gravity-forms' ),
104+
],
97105
'orderby' => [
98106
'type' => EntriesConnectionOrderbyInput::$type,
99107
'description' => static fn () => __( 'How to sort the entries.', 'wp-graphql-gravity-forms' ),

src/Data/Connection/EntriesConnectionResolver.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,28 @@ private function prepare_search_criteria( array $args ): array {
294294
);
295295
}
296296

297+
// Add isRead filter to field_filters.
298+
if ( isset( $args['where']['isRead'] ) ) {
299+
if ( ! isset( $search_criteria['field_filters'] ) ) {
300+
$search_criteria['field_filters'] = [ 'mode' => FieldFiltersModeEnum::ALL ];
301+
}
302+
$search_criteria['field_filters'][] = [
303+
'key' => 'is_read',
304+
'value' => (bool) $args['where']['isRead'],
305+
];
306+
}
307+
308+
// Add isStarred filter to field_filters.
309+
if ( isset( $args['where']['isStarred'] ) ) {
310+
if ( ! isset( $search_criteria['field_filters'] ) ) {
311+
$search_criteria['field_filters'] = [ 'mode' => FieldFiltersModeEnum::ALL ];
312+
}
313+
$search_criteria['field_filters'][] = [
314+
'key' => 'is_starred',
315+
'value' => (bool) $args['where']['isStarred'],
316+
];
317+
}
318+
297319
return $search_criteria;
298320
}
299321

0 commit comments

Comments
 (0)