Skip to content

Commit

Permalink
Forms: Update responses management with DataViews
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Feb 6, 2025
1 parent 7991e1b commit 8c76076
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Forms: Update responses management with DataViews
1 change: 1 addition & 0 deletions projects/packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@wordpress/compose": "7.17.0",
"@wordpress/core-data": "7.17.0",
"@wordpress/data": "10.17.0",
"@wordpress/dataviews": "4.13.0",
"@wordpress/element": "6.17.0",
"@wordpress/hooks": "4.17.0",
"@wordpress/i18n": "5.17.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function __construct() {
* @access public
*/
public function register_rest_routes() {
// Stats for single resource type.

register_rest_route(
$this->namespace,
$this->rest_base . '/responses',
Expand Down Expand Up @@ -185,6 +183,7 @@ function ( $response ) use ( $base_fields, $data_defaults ) {
$all_fields = array_merge( $base_fields, $data['_feedback_all_fields'] );
return array(
'id' => $response->ID,
'post_status' => $response->post_status,
'uid' => $all_fields['feedback_id'],
'date' => get_the_date( 'c', $response ),
'author_name' => $data['_feedback_author'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { store as coreStore } from '@wordpress/core-data';

Check failure on line 1 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

'coreStore' is defined but never used
import { __ } from '@wordpress/i18n';
import { seen, thumbsDown, thumbsUp } from '@wordpress/icons';
import { doBulkAction } from '../../../data/responses';
import { STORE_NAME } from '../../../state';
import { ACTIONS } from '../../constants';
import InboxResponse from '../../response';

export const viewAction = {
id: 'view-response',
label: __( 'View response', 'jetpack-forms' ),
isPrimary: true,
icon: seen,
RenderModal: ( { items } ) => {
const [ item ] = items;
return <InboxResponse isLoading={ false } response={ item } />;
},
};

export const markAsSpamAction = {
id: 'mark-as-spam',
label: __( 'Mark as spam', 'jetpack-forms' ),
isEligible: item => item.post_status !== 'spam',
supportsBulk: true,
icon: thumbsDown,
async callback( items, { registry } ) {
const itemIds = items.map( ( { id } ) => id );
const { addTabTotals, fetchResponses, removeResponses } = registry.dispatch( STORE_NAME );

Check failure on line 28 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

'addTabTotals' is assigned a value but never used

Check failure on line 28 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

'fetchResponses' is assigned a value but never used
try {
removeResponses( itemIds );
// addTabTotals( {
// [ currentTab ]: -1,
// [ ACTION_TABS[ action ] ]: 1,
// } );
// await registry
// .dispatch( coreStore )
// .saveEntityRecord(
// 'postType',
// 'feedback',
// { id: item.id, status: 'spam' },
// { throwOnError: true }
// );
await doBulkAction( itemIds, ACTIONS.markAsSpam );

// await fetchResponses(
// {
// ...query,
// limit: RESPONSES_FETCH_LIMIT,
// offset: ( currentPage - 1 ) * RESPONSES_FETCH_LIMIT,
// },
// { append: true }
// );
} catch {}

Check failure on line 53 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

Empty block statement
},
};

export const markAsNotSpamAction = {
id: 'mark-as-not-spam',
label: __( 'Not spam', 'jetpack-forms' ),
isEligible: item => item.post_status === 'spam',
supportsBulk: true,
icon: thumbsUp,
async callback( items, { registry } ) {
const itemIds = items.map( ( { id } ) => id );
const { removeResponses } = registry.dispatch( STORE_NAME );
try {
removeResponses( itemIds );
await doBulkAction( itemIds, ACTIONS.markAsNotSpam );
} catch {}

Check failure on line 69 in projects/packages/forms/src/dashboard/inbox/dataviews/actions/index.js

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

Empty block statement
},
};
Loading

0 comments on commit 8c76076

Please sign in to comment.