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 => {
|
return headers.map( header => {
|
||||||
if ( shownKeys.includes( header.key ) ) {
|
const hidden = ! shownKeys.includes( header.key );
|
||||||
return header;
|
return { ...header, hiddenByDefault: hidden };
|
||||||
}
|
|
||||||
return { ...header, hiddenByDefault: true };
|
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ export default class CategoriesReportTable extends Component {
|
||||||
itemIdField="category_id"
|
itemIdField="category_id"
|
||||||
query={ query }
|
query={ query }
|
||||||
title={ __( 'Categories', 'wc-admin' ) }
|
title={ __( 'Categories', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="categories_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,7 @@ export default class CouponsReportTable extends Component {
|
||||||
itemIdField="coupon_id"
|
itemIdField="coupon_id"
|
||||||
query={ query }
|
query={ query }
|
||||||
title={ __( 'Coupons', 'wc-admin' ) }
|
title={ __( 'Coupons', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="coupons_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,7 @@ export default class CustomersReportTable extends Component {
|
||||||
itemIdField="id"
|
itemIdField="id"
|
||||||
query={ query }
|
query={ query }
|
||||||
title={ __( 'Registered Customers', 'wc-admin' ) }
|
title={ __( 'Registered Customers', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="customers_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,6 +250,7 @@ class OrdersReportTable extends Component {
|
||||||
query={ query }
|
query={ query }
|
||||||
tableData={ tableData }
|
tableData={ tableData }
|
||||||
title={ __( 'Orders', 'wc-admin' ) }
|
title={ __( 'Orders', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="orders_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,7 @@ export default class VariationsReportTable extends Component {
|
||||||
extended_info: true,
|
extended_info: true,
|
||||||
} }
|
} }
|
||||||
title={ __( 'Variations', 'wc-admin' ) }
|
title={ __( 'Variations', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="variations_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,6 +214,7 @@ export default class ProductsReportTable extends Component {
|
||||||
extended_info: true,
|
extended_info: true,
|
||||||
} }
|
} }
|
||||||
title={ __( 'Products', 'wc-admin' ) }
|
title={ __( 'Products', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="products_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,7 @@ export default class TaxesReportTable extends Component {
|
||||||
itemIdField="tax_rate_id"
|
itemIdField="tax_rate_id"
|
||||||
query={ query }
|
query={ query }
|
||||||
title={ __( 'Taxes', 'wc-admin' ) }
|
title={ __( 'Taxes', 'wc-admin' ) }
|
||||||
|
columnPrefsKey="taxes_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,9 @@ function readCurrentUserData( resourceNames, fetch ) {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
fetch( { path: url } )
|
fetch( { path: url } )
|
||||||
.then( user => {
|
.then( userToUserDataResource )
|
||||||
const userData = mapValues( user.woocommerce_meta, JSON.parse );
|
|
||||||
return { [ 'current-user-data' ]: { data: userData } };
|
|
||||||
} )
|
|
||||||
.catch( error => {
|
.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 ) {
|
function updateCurrentUserData( resourceNames, data, fetch ) {
|
||||||
const resourceName = 'current-user-data';
|
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 ) ) {
|
if ( resourceNames.includes( resourceName ) ) {
|
||||||
const url = '/wp/v2/users/me';
|
const url = '/wp/v2/users/me';
|
||||||
|
@ -44,9 +50,7 @@ function updateCurrentUserData( resourceNames, data, fetch ) {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
fetch( { path: url, method: 'POST', data: user } )
|
fetch( { path: url, method: 'POST', data: user } )
|
||||||
.then( updatedUserData => {
|
.then( userToUserDataResource )
|
||||||
return { [ resourceName ]: { data: updatedUserData.woocommerce_meta } };
|
|
||||||
} )
|
|
||||||
.catch( error => {
|
.catch( error => {
|
||||||
return { [ resourceName ]: { error } };
|
return { [ resourceName ]: { error } };
|
||||||
} ),
|
} ),
|
||||||
|
@ -55,6 +59,16 @@ function updateCurrentUserData( resourceNames, data, fetch ) {
|
||||||
return [];
|
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 {
|
export default {
|
||||||
read,
|
read,
|
||||||
update,
|
update,
|
||||||
|
|
|
@ -365,7 +365,14 @@ function wc_admin_register_user_data() {
|
||||||
*/
|
*/
|
||||||
function wc_admin_get_user_data_fields() {
|
function wc_admin_get_user_data_fields() {
|
||||||
$user_data_fields = array(
|
$user_data_fields = array(
|
||||||
|
'categories_report_columns',
|
||||||
|
'coupons_report_columns',
|
||||||
|
'customers_report_columns',
|
||||||
|
'orders_report_columns',
|
||||||
|
'products_report_columns',
|
||||||
'revenue_report_columns',
|
'revenue_report_columns',
|
||||||
|
'taxes_report_columns',
|
||||||
|
'variations_report_columns',
|
||||||
);
|
);
|
||||||
|
|
||||||
return apply_filters( 'wc_admin_get_user_data_fields', $user_data_fields );
|
return apply_filters( 'wc_admin_get_user_data_fields', $user_data_fields );
|
||||||
|
|
Loading…
Reference in New Issue