Add column visibility prefs to all tables (https://github.com/woocommerce/woocommerce-admin/pull/1082)
* Add column prefs to the other tables This adds column prefs to the other remaining report tables. * Table columns: Override defaults with user prefs. * table columns: Add remaining analytics tables * user read/update operation: Combine responses This combines the response handling for the read and update operations.
This commit is contained in:
parent
11176f7b0e
commit
a7aed85244
|
@ -42,10 +42,8 @@ class ReportTable extends Component {
|
|||
}
|
||||
|
||||
return headers.map( header => {
|
||||
if ( shownKeys.includes( header.key ) ) {
|
||||
return header;
|
||||
}
|
||||
return { ...header, hiddenByDefault: true };
|
||||
const hidden = ! shownKeys.includes( header.key );
|
||||
return { ...header, hiddenByDefault: hidden };
|
||||
} );
|
||||
};
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ export default class CategoriesReportTable extends Component {
|
|||
itemIdField="category_id"
|
||||
query={ query }
|
||||
title={ __( 'Categories', 'wc-admin' ) }
|
||||
columnPrefsKey="categories_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -162,6 +162,7 @@ export default class CouponsReportTable extends Component {
|
|||
itemIdField="coupon_id"
|
||||
query={ query }
|
||||
title={ __( 'Coupons', 'wc-admin' ) }
|
||||
columnPrefsKey="coupons_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ export default class CustomersReportTable extends Component {
|
|||
itemIdField="id"
|
||||
query={ query }
|
||||
title={ __( 'Registered Customers', 'wc-admin' ) }
|
||||
columnPrefsKey="customers_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -250,6 +250,7 @@ class OrdersReportTable extends Component {
|
|||
query={ query }
|
||||
tableData={ tableData }
|
||||
title={ __( 'Orders', 'wc-admin' ) }
|
||||
columnPrefsKey="orders_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -178,6 +178,7 @@ export default class VariationsReportTable extends Component {
|
|||
extended_info: true,
|
||||
} }
|
||||
title={ __( 'Variations', 'wc-admin' ) }
|
||||
columnPrefsKey="variations_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -214,6 +214,7 @@ export default class ProductsReportTable extends Component {
|
|||
extended_info: true,
|
||||
} }
|
||||
title={ __( 'Products', 'wc-admin' ) }
|
||||
columnPrefsKey="products_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -154,6 +154,7 @@ export default class TaxesReportTable extends Component {
|
|||
itemIdField="tax_rate_id"
|
||||
query={ query }
|
||||
title={ __( 'Taxes', 'wc-admin' ) }
|
||||
columnPrefsKey="taxes_report_columns"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,9 @@ function readCurrentUserData( resourceNames, fetch ) {
|
|||
|
||||
return [
|
||||
fetch( { path: url } )
|
||||
.then( user => {
|
||||
const userData = mapValues( user.woocommerce_meta, JSON.parse );
|
||||
return { [ 'current-user-data' ]: { data: userData } };
|
||||
} )
|
||||
.then( userToUserDataResource )
|
||||
.catch( error => {
|
||||
return { [ 'current-user-data' ]: { error } };
|
||||
return { [ 'current-user-data' ]: { error: String( error.message ) } };
|
||||
} ),
|
||||
];
|
||||
}
|
||||
|
@ -34,7 +31,16 @@ function readCurrentUserData( resourceNames, fetch ) {
|
|||
|
||||
function updateCurrentUserData( resourceNames, data, fetch ) {
|
||||
const resourceName = 'current-user-data';
|
||||
const userDataFields = [ 'revenue_report_columns' ];
|
||||
const userDataFields = [
|
||||
'categories_report_columns',
|
||||
'coupons_report_columns',
|
||||
'customers_report_columns',
|
||||
'orders_report_columns',
|
||||
'products_report_columns',
|
||||
'revenue_report_columns',
|
||||
'taxes_report_columns',
|
||||
'variations_report_columns',
|
||||
];
|
||||
|
||||
if ( resourceNames.includes( resourceName ) ) {
|
||||
const url = '/wp/v2/users/me';
|
||||
|
@ -44,9 +50,7 @@ function updateCurrentUserData( resourceNames, data, fetch ) {
|
|||
|
||||
return [
|
||||
fetch( { path: url, method: 'POST', data: user } )
|
||||
.then( updatedUserData => {
|
||||
return { [ resourceName ]: { data: updatedUserData.woocommerce_meta } };
|
||||
} )
|
||||
.then( userToUserDataResource )
|
||||
.catch( error => {
|
||||
return { [ resourceName ]: { error } };
|
||||
} ),
|
||||
|
@ -55,6 +59,16 @@ function updateCurrentUserData( resourceNames, data, fetch ) {
|
|||
return [];
|
||||
}
|
||||
|
||||
function userToUserDataResource( user ) {
|
||||
const userData = mapValues( user.woocommerce_meta, data => {
|
||||
if ( ! data || 0 === data.length ) {
|
||||
return '';
|
||||
}
|
||||
return JSON.parse( data );
|
||||
} );
|
||||
return { [ 'current-user-data' ]: { data: userData } };
|
||||
}
|
||||
|
||||
export default {
|
||||
read,
|
||||
update,
|
||||
|
|
|
@ -365,7 +365,14 @@ function wc_admin_register_user_data() {
|
|||
*/
|
||||
function wc_admin_get_user_data_fields() {
|
||||
$user_data_fields = array(
|
||||
'categories_report_columns',
|
||||
'coupons_report_columns',
|
||||
'customers_report_columns',
|
||||
'orders_report_columns',
|
||||
'products_report_columns',
|
||||
'revenue_report_columns',
|
||||
'taxes_report_columns',
|
||||
'variations_report_columns',
|
||||
);
|
||||
|
||||
return apply_filters( 'wc_admin_get_user_data_fields', $user_data_fields );
|
||||
|
|
Loading…
Reference in New Issue