Skip to content

Commit 6fc7ab6

Browse files
committed
Refactoring and bug fixes
1 parent ee96ccd commit 6fc7ab6

22 files changed

Lines changed: 233 additions & 279 deletions

File tree

locales/admin/en.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
"products_preorder": "Pre-order",
6666
"products_inStock": "In stock",
6767
"products_stockStatus": "Stock status",
68-
"products_onlyEnabled": "Only enabled",
69-
"products_onlyDiscontinued": "Only discontinued",
70-
"products_onlyOnSale": "Only on sale",
68+
"products_discontinued": "Discontinued",
69+
"products_onSale": "On sale",
7170
"products_search": "Search products",
7271
"products_aboutDelete": "{count} products is about to be permanently deleted. You can’t undo this action.",
7372
"products_regularPrice": "Regular price",

src/admin/client/layouts/products/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Categories from 'modules/product-categories/list';
66
export default () => (
77
<div className="row row--no-gutter col-full-height">
88
<div className="col-xs-3 col--no-gutter scroll col-categories">
9-
<Categories showAll={true} showAdd={false} opened={false}/>
9+
<Categories showAll={true}/>
1010
<ProductsFilter />
1111
</div>
1212
<div className="col-xs-9 col--no-gutter scroll">

src/admin/client/lib/helper.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const formatNumber = (number = 0, settings) => {
1+
export const formatNumber = (number = 0, settings) => {
22
const x = 3;
33

44
const re = '\\d(?=(\\d{' + x + '})+' + (settings.decimal_number > 0
@@ -13,11 +13,16 @@ const formatNumber = (number = 0, settings) => {
1313
};
1414

1515
const amountPattern = '{amount}';
16-
const formatCurrency = (number = 0, settings) => {
16+
export const formatCurrency = (number = 0, settings) => {
1717
return settings.currency_format.replace(amountPattern, formatNumber(number, settings));
1818
}
1919

20-
module.exports = {
21-
formatNumber,
22-
formatCurrency
23-
};
20+
export const getThumbnailUrl = (originalUrl, width) => {
21+
if(originalUrl && originalUrl.length > 0) {
22+
const pos = originalUrl.lastIndexOf('/');
23+
const thumbnailUrl = originalUrl.substring(0, pos) + `/${width}/` + originalUrl.substring(pos + 1);
24+
return thumbnailUrl;
25+
} else {
26+
return '';
27+
}
28+
}

src/admin/client/modules/customers/list/components/item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ListItem } from 'material-ui/List';
55
import Divider from 'material-ui/Divider';
66
import FontIcon from 'material-ui/FontIcon';
77
import messages from 'lib/text'
8-
import helper from 'lib/helper'
8+
import * as helper from 'lib/helper'
99
import style from './style.css'
1010

1111
const CustomersListItem = ({ customer, onSelect, selected, settings }) => {

src/admin/client/modules/orders/list/components/item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ListItem } from 'material-ui/List';
55
import Divider from 'material-ui/Divider';
66
import FontIcon from 'material-ui/FontIcon';
77
import messages from 'lib/text'
8-
import helper from 'lib/helper'
8+
import * as helper from 'lib/helper'
99
import style from './style.css'
1010
import moment from 'moment';
1111

src/admin/client/modules/product-categories/components/list.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class Categories extends React.Component {
4545
nestedItems={this.getChildren(selectedId, allItems, item.id, opened)}
4646
leftIcon={<FontIcon className="material-icons">{item.enabled ? 'folder' : 'visibility_off'}</FontIcon>}
4747
onTouchTap={() => { this.props.onSelect(item.id) }}
48-
/>
48+
/>
4949
}
5050

5151
getChildren(selectedId, allItems, id, opened){
@@ -62,10 +62,11 @@ export default class Categories extends React.Component {
6262
selectedId,
6363
items,
6464
onCreate,
65-
showAll,
66-
showRoot,
67-
showAdd,
68-
opened = true
65+
showAll = false,
66+
showRoot = false,
67+
showAdd = false,
68+
rootName = messages.productCategories_root,
69+
opened = false
6970
} = this.props;
7071

7172

@@ -76,7 +77,7 @@ export default class Categories extends React.Component {
7677
<List>
7778
{showRoot &&
7879
<ListItem
79-
primaryText={messages.productCategories_root}
80+
primaryText={rootName}
8081
style={'root' === selectedId ? styles.selectedItem : styles.item}
8182
innerDivStyle={styles.innerItem}
8283
leftIcon={<FontIcon className="material-icons">home</FontIcon>}

src/admin/client/modules/products/actionTypes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ export const PRODUCT_DETAIL_ERASE = 'PRODUCT_DETAIL_ERASE'
1010
export const PRODUCTS_MORE_REQUEST = 'PRODUCTS_MORE_REQUEST'
1111
export const PRODUCTS_MORE_RECEIVE = 'PRODUCTS_MORE_RECEIVE'
1212

13-
export const PRODUCTS_FILTER_SET_SEARCH = 'PRODUCTS_FILTER_SET_SEARCH'
14-
export const PRODUCTS_FILTER_SET_ENABLED = 'PRODUCTS_FILTER_SET_ENABLED'
15-
export const PRODUCTS_FILTER_SET_DISCONTINUED = 'PRODUCTS_FILTER_SET_DISCONTINUED'
16-
export const PRODUCTS_FILTER_SET_ONSALE = 'PRODUCTS_FILTER_SET_ONSALE'
17-
export const PRODUCTS_FILTER_SET_STOCK = 'PRODUCTS_FILTER_SET_STOCK'
13+
export const PRODUCTS_SET_FILTER = 'PRODUCTS_SET_FILTER'
1814

1915
export const PRODUCTS_SELECT = 'PRODUCTS_SELECT'
2016
export const PRODUCTS_DESELECT = 'PRODUCTS_DESELECT'

src/admin/client/modules/products/actions.js

Lines changed: 55 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ function requestMoreProducts() {
4242
}
4343
}
4444

45-
function receiveProductsMore(items) {
45+
function receiveProductsMore({ has_more, total_count, data }) {
4646
return {
4747
type: t.PRODUCTS_MORE_RECEIVE,
48-
items
48+
has_more,
49+
total_count,
50+
data
4951
}
5052
}
5153

52-
function receiveProducts(items) {
54+
function receiveProducts({ has_more, total_count, data }) {
5355
return {
5456
type: t.PRODUCTS_RECEIVE,
55-
items
57+
has_more,
58+
total_count,
59+
data
5660
}
5761
}
5862

@@ -89,38 +93,10 @@ export function selectAllProduct() {
8993
}
9094
}
9195

92-
export function setFilterSearch(value) {
96+
export function setFilter(filter) {
9397
return {
94-
type: t.PRODUCTS_FILTER_SET_SEARCH,
95-
search: value
96-
}
97-
}
98-
99-
export function setFilterStock(value) {
100-
return {
101-
type: t.PRODUCTS_FILTER_SET_STOCK,
102-
stock_status: value
103-
}
104-
}
105-
106-
export function setFilterEnabled(value) {
107-
return {
108-
type: t.PRODUCTS_FILTER_SET_ENABLED,
109-
enabled: value
110-
}
111-
}
112-
113-
export function setFilterDiscontinued(value) {
114-
return {
115-
type: t.PRODUCTS_FILTER_SET_DISCONTINUED,
116-
discontinued: value
117-
}
118-
}
119-
120-
export function setFilterOnSale(value) {
121-
return {
122-
type: t.PRODUCTS_FILTER_SET_ONSALE,
123-
on_sale: value
98+
type: t.PRODUCTS_SET_FILTER,
99+
filter: filter
124100
}
125101
}
126102

@@ -162,49 +138,49 @@ function successCreateProduct(id) {
162138
}
163139
}
164140

165-
export function fetchProducts() {
166-
return (dispatch, getState) => {
167-
const state = getState();
168-
if (!state.products.isFetching) {
169-
dispatch(requestProducts());
170-
dispatch(deselectAllProduct());
171-
172-
let filter = { limit: 20, fields: 'id,name,category_id,category_name,sku,images,enabled,discontinued,stock_status,stock_quantity,price,on_sale,regular_price' };
173-
filter.search = state.products.filter_search;
141+
const getFilter = (state, offset = 0) => {
142+
let filter = {
143+
limit: 50,
144+
fields: 'id,name,category_id,category_name,sku,images,enabled,discontinued,stock_status,stock_quantity,price,on_sale,regular_price',
145+
search: state.products.filter.search,
146+
offset: offset
147+
}
174148

175-
if(state.products.filter_stock_status && state.products.filter_stock_status !== 'all') {
176-
filter.stock_status = state.products.filter_stock_status;
177-
}
149+
if(state.productCategories.selectedId !== null && state.productCategories.selectedId !== 'all') {
150+
filter.category_id = state.productCategories.selectedId;
151+
}
178152

179-
if(state.productCategories.selectedId) {
180-
filter.category_id = state.productCategories.selectedId;
181-
}
153+
if(state.products.filter.stockStatus !== null) {
154+
filter.stock_status = state.products.filter.stockStatus;
155+
}
182156

183-
if(state.products.filter_enabled) {
184-
filter.enabled = true;
185-
}
157+
if(state.products.filter.enabled !== null) {
158+
filter.enabled = state.products.filter.enabled;
159+
}
186160

187-
if(state.products.filter_discontinued) {
188-
filter.discontinued = true;
189-
}
161+
if(state.products.filter.discontinued !== null) {
162+
filter.discontinued = state.products.filter.discontinued;
163+
}
190164

191-
if(state.products.filter_on_sale) {
192-
filter.on_sale = true;
193-
}
165+
if(state.products.filter.onSale !== null) {
166+
filter.on_sale = state.products.filter.onSale;
167+
}
194168

195-
return api.products.list(filter)
196-
.then(({status, json}) => {
197-
let products = json.data;
169+
return filter;
170+
}
198171

199-
products = product.sort((a,b) => (a.position - b.position ));
172+
export function fetchProducts() {
173+
return (dispatch, getState) => {
174+
const state = getState();
175+
if (!state.products.loadingItems) {
176+
dispatch(requestProducts());
177+
dispatch(deselectAllProduct());
200178

201-
products.forEach((element, index, theArray) => {
202-
if(theArray[index].name === '') {
203-
theArray[index].name = `<${messages.draft}>`;
204-
}
205-
})
179+
let filter = getFilter(state);
206180

207-
dispatch(receiveProducts(products))
181+
return api.products.list(filter)
182+
.then(({status, json}) => {
183+
dispatch(receiveProducts(json))
208184
})
209185
.catch(error => {
210186
dispatch(receiveProductsError(error));
@@ -216,49 +192,19 @@ export function fetchProducts() {
216192
export function fetchMoreProducts() {
217193
return (dispatch, getState) => {
218194
const state = getState();
219-
dispatch(requestMoreProducts());
220-
221-
let filter = { limit: 50, fields: 'id,name,category_id,category_name,sku,images,enabled,discontinued,stock_status,stock_quantity,price,on_sale,regular_price' };
222-
filter.offset = state.products.items.length;
223-
filter.search = state.products.filter_search;
224-
225-
if(state.products.filter_stock_status && state.products.filter_stock_status !== 'all') {
226-
filter.stock_status = state.products.filter_stock_status;
227-
}
195+
if (!state.products.loadingItems) {
196+
dispatch(requestMoreProducts());
228197

229-
if(state.productCategories.selectedId) {
230-
filter.category_id = state.productCategories.selectedId;
231-
}
232-
233-
if(state.products.filter_enabled) {
234-
filter.enabled = true;
235-
}
198+
let filter = getFilter(state, state.products.items.length);
236199

237-
if(state.products.filter_discontinued) {
238-
filter.discontinued = true;
239-
}
240-
241-
if(state.products.filter_on_sale) {
242-
filter.on_sale = true;
243-
}
244-
245-
return api.products.list(filter)
246-
.then(({status, json}) => {
247-
let products = json.data;
248-
249-
products = products.sort((a,b) => (a.position - b.position ));
250-
251-
products.forEach((element, index, theArray) => {
252-
if(theArray[index].name === '') {
253-
theArray[index].name = `<${messages.draft}>`;
254-
}
200+
return api.products.list(filter)
201+
.then(({status, json}) => {
202+
dispatch(receiveProductsMore(json))
255203
})
256-
257-
dispatch(receiveProductsMore(products))
258-
})
259-
.catch(error => {
260-
dispatch(receiveProductsError(error));
261-
});
204+
.catch(error => {
205+
dispatch(receiveProductsError(error));
206+
});
207+
}
262208
}
263209
}
264210

src/admin/client/modules/products/filter/components/fields.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)