Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit b846715

Browse files
authored
Grid memory leak fix (#599)
* bugfix(core): condition placeholder, pagination crash * bugfix(core): pagination and local params improvement * bugfix(core): category tree loading improvement * bugfix(core): clean code * bugfix(core): clean code * bugfix(core): clean code
1 parent a627f3c commit b846715

File tree

22 files changed

+121
-141
lines changed

22 files changed

+121
-141
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
### Backend base url ###
12
API_BASE_URL=http://localhost:8000/api/v1/

modules/@ergonode/attributes/src/services/attribute/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export const getAll = ({
3131
params,
3232
});
3333

34+
export const getAutocomplete = ({
35+
$axios,
36+
}) => $axios.$get('attributes/autocomplete');
37+
3438
export const getOption = ({
3539
$axios,
3640
id,

modules/@ergonode/categories/src/services/index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,9 @@ export const get = ({
1212
id,
1313
}) => $axios.$get(`categories/${id}`);
1414

15-
export const getAll = ({
15+
export const getAutocomplete = ({
1616
$axios,
17-
filter = '',
18-
}) => $axios.$get('categories', {
19-
params: {
20-
filter,
21-
limit: 9999,
22-
offset: 0,
23-
view: 'list',
24-
field: 'name',
25-
order: 'ASC',
26-
},
27-
});
17+
}) => $axios.$get('categories/autocomplete');
2818

2919
export const remove = ({
3020
$axios,

modules/@ergonode/category-trees/src/models/__tests__/__mocks__/categories.mock.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ export const categoryList = [
66
{
77
id: 'a72bdcce-6bd6-5663-99ae-7bad19307aa6',
88
code: 'code_1',
9-
name: null,
9+
label: null,
1010
elements_count: 0.0,
1111
},
1212
{
1313
id: '4c59d19f-e569-576b-a67f-e2d2094b19f5',
1414
code: 'code_2',
15-
name: null,
15+
label: null,
1616
elements_count: 0,
1717
},
1818
{
1919
id: 'fb471778-cbe7-56ca-ace7-0edd936092d7',
2020
code: 'code_3',
21-
name: null,
21+
label: null,
2222
elements_count: 0,
2323
},
2424
{
2525
id: 'f9e4f5a5-7a87-5efc-a680-cfbdb68b869f',
2626
code: 'code_4',
27-
name: null,
27+
label: null,
2828
elements_count: 0,
2929
},
3030
{
3131
id: 'b07154ca-3e19-5d69-9238-8fe2b0c5e49e',
3232
code: 'code_5',
33-
name: null,
33+
label: null,
3434
elements_count: 0,
3535
},
3636
];

modules/@ergonode/category-trees/src/models/treeMapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export function getParsedTreeData(tree, categories) {
1616
} = treeArray[i].children;
1717
const {
1818
code: categoryCode,
19-
name: categoryName,
20-
} = categories.find(e => e.id === categoryId);
19+
label: categoryName,
20+
} = categories.find(category => category.id === categoryId);
2121
newTree.push({
2222
id: categoryId,
2323
code: categoryCode,

modules/@ergonode/category-trees/src/store/categoryTree/actions.js

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* Copyright © Bold Brand Commerce Sp. z o.o. All rights reserved.
33
* See LICENSE for license details.
44
*/
5+
import {
6+
getAutocomplete,
7+
} from '@Categories/services';
58
import {
69
ALERT_TYPE,
710
} from '@Core/defaults/alerts';
8-
import {
9-
getListItems,
10-
} from '@Core/services/list/getList.service';
1111
import {
1212
getMappedTreeData,
1313
getParsedTreeData,
@@ -103,51 +103,44 @@ export default {
103103
});
104104
// EXTENDED BEFORE METHOD
105105

106+
const [
107+
categoryTreeData,
108+
categoriesData,
109+
] = await Promise.all([
110+
get({
111+
$axios: this.app.$axios,
112+
id,
113+
}),
114+
getAutocomplete({
115+
$axios: this.app.$axios,
116+
}),
117+
]);
118+
106119
const {
107120
language: userLanguageCode,
108121
} = rootState.authentication.user;
109-
const data = await get({
110-
$axios: this.app.$axios,
111-
id,
112-
});
122+
113123
const {
114124
code,
115125
name = '',
116126
categories,
117-
} = data;
127+
} = categoryTreeData;
118128

119129
if (categories.length) {
120-
await getListItems({
121-
$axios: this.app.$axios,
122-
path: `${userLanguageCode}/categories`,
123-
params: {
124-
limit: 99999,
125-
offset: 0,
126-
// TODO: BE has no filter via ID's - we gonna wait for them
127-
// filter: `category_id=${categories.map(category => category.id).join(',')}`,
128-
view: 'list',
129-
field: 'code',
130-
order: 'ASC',
131-
},
132-
onSuccess: (({
133-
items,
134-
}) => {
135-
const treeToSet = getParsedTreeData(categories, items);
130+
const treeToSet = getParsedTreeData(categories, categoriesData);
136131

137-
treeToSet.forEach(e => dispatch('list/setDisabledElement', {
138-
languageCode: userLanguageCode,
139-
elementId: e.id,
140-
disabled: true,
141-
}, {
142-
root: true,
143-
}));
144-
dispatch('gridDesigner/setGridData', treeToSet, {
145-
root: true,
146-
});
147-
dispatch('gridDesigner/setFullGridData', treeToSet, {
148-
root: true,
149-
});
150-
}),
132+
treeToSet.forEach(e => dispatch('list/setDisabledElement', {
133+
languageCode: userLanguageCode,
134+
elementId: e.id,
135+
disabled: true,
136+
}, {
137+
root: true,
138+
}));
139+
dispatch('gridDesigner/setGridData', treeToSet, {
140+
root: true,
141+
});
142+
dispatch('gridDesigner/setFullGridData', treeToSet, {
143+
root: true,
151144
});
152145
}
153146

@@ -170,7 +163,7 @@ export default {
170163
// EXTENDED AFTER METHOD
171164
await this.$extendMethods('@Trees/store/categoryTree/action/getCategoryTree/__after', {
172165
$this: this,
173-
data,
166+
data: categoryTreeData,
174167
});
175168
// EXTENDED AFTER METHOD
176169
} catch (e) {

modules/@ergonode/channels/src/components/Modals/ExportDetailsModalGrid.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export default {
108108
isPrefetchingData: true,
109109
details: [],
110110
downloadLink: '',
111-
localParams: DEFAULT_GRID_FETCH_PARAMS,
112-
pagination: DEFAULT_GRID_PAGINATION,
111+
localParams: DEFAULT_GRID_FETCH_PARAMS(),
112+
pagination: DEFAULT_GRID_PAGINATION(),
113113
};
114114
},
115115
computed: {
@@ -172,16 +172,14 @@ export default {
172172
173173
this.onFetchData();
174174
},
175-
async onFetchData(params = this.localParams) {
176-
this.localParams = params;
177-
175+
async onFetchData() {
178176
await getGridData({
179177
$route: this.$route,
180178
$cookies: this.$cookies,
181179
$axios: this.$axios,
182180
path: `channels/${this.channelId}/exports/${this.exportId}/errors`,
183181
params: {
184-
...params,
182+
...this.localParams,
185183
extended: true,
186184
},
187185
onSuccess: this.onFetchGridDataSuccess,

modules/@ergonode/collections/src/components/Tabs/CollectionProductsTab.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:is-header-visible="true"
2222
:is-border="true"
2323
@cell-value="onCellValueChange"
24+
@preview-row="onPreviewRow"
2425
@delete-row="onRemoveRow"
2526
@pagination="onPaginationChange"
2627
@column-sort="onColumnSortChange"
@@ -76,6 +77,9 @@ import {
7677
import extendedGridComponentsMixin from '@Core/mixins/grid/extendedGridComponentsMixin';
7778
import fetchGridDataMixin from '@Core/mixins/grid/fetchGridDataMixin';
7879
import tabFeedbackMixin from '@Core/mixins/tab/tabFeedbackMixin';
80+
import {
81+
ROUTE_NAME,
82+
} from '@Products/config/routes';
7983
import ActionButton from '@UI/components/ActionButton/ActionButton';
8084
import Button from '@UI/components/Button/Button';
8185
import IconAdd from '@UI/components/Icons/Actions/IconAdd';
@@ -224,6 +228,16 @@ export default {
224228
225229
this.isSubmitting = false;
226230
},
231+
onPreviewRow(args) {
232+
const lastIndex = args.length - 1;
233+
234+
this.$router.push({
235+
name: ROUTE_NAME.PRODUCT_EDIT_GENERAL,
236+
params: {
237+
id: args[lastIndex],
238+
},
239+
});
240+
},
227241
onCellValueChange(cellValues) {
228242
const drafts = cellValues.reduce((prev, {
229243
rowId, columnId, value,
@@ -253,7 +267,7 @@ export default {
253267
async onCreatedData() {
254268
this.isPrefetchingData = true;
255269
256-
await this.onFetchData(this.localParams);
270+
await this.onFetchData();
257271
258272
this.selectedAppModalOption = null;
259273
this.isPrefetchingData = false;

modules/@ergonode/conditions/src/components/ConditionSetDesigner/ConditionSetItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default {
123123
const {
124124
phrase,
125125
} = this.condition;
126-
const placeholders = this.conditionsValues[this.itemId];
126+
const placeholders = this.conditionsValues[this.item.id];
127127
128128
if (!placeholders) return phrase;
129129
return this.replacePlaceholderOnPhrase(placeholders);

modules/@ergonode/core/src/defaults/grid/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ export const DRAGGED_ELEMENT = {
8282

8383
export const DATA_LIMIT = 25;
8484

85-
export const DEFAULT_GRID_FETCH_PARAMS = {
85+
export const DEFAULT_GRID_FETCH_PARAMS = () => ({
8686
offset: 0,
8787
limit: DATA_LIMIT,
8888
filter: {},
8989
sortedColumn: {},
90-
};
90+
});
9191

92-
export const DEFAULT_GRID_PAGINATION = {
92+
export const DEFAULT_GRID_PAGINATION = () => ({
9393
page: 1,
9494
itemsPerPage: DATA_LIMIT,
95-
};
95+
});

modules/@ergonode/core/src/mixins/grid/fetchGridDataMixin.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export default function ({
4343
columns: [],
4444
filterValues: {},
4545
filtered: 0,
46-
localParams: DEFAULT_GRID_FETCH_PARAMS,
47-
pagination: DEFAULT_GRID_PAGINATION,
46+
localParams: DEFAULT_GRID_FETCH_PARAMS(),
47+
pagination: DEFAULT_GRID_PAGINATION(),
4848
};
4949
},
5050
computed: {
@@ -145,9 +145,7 @@ export default function ({
145145

146146
this.onFetchData();
147147
},
148-
async onFetchData(localParams = this.localParams) {
149-
this.localParams = localParams;
150-
148+
async onFetchData() {
151149
await getGridData({
152150
$route: this.$route,
153151
$cookies: this.$cookies,

modules/@ergonode/core/src/mixins/list/fetchListGroupDataMixin.js

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ export default function ({
114114

115115
this.groups[languageCode] = [
116116
...groups,
117-
this.unassignedGroup,
118117
];
119118

119+
this.groups[languageCode].push({
120+
...this.unassignedGroup,
121+
});
122+
120123
this.items[languageCode] = items;
121124

122125
this.groupItemsCount = groupItemsCount;
@@ -133,33 +136,6 @@ export default function ({
133136
this.items[languageCode][UNASSIGNED_GROUP_ID] = items;
134137
this.groupItemsCount[UNASSIGNED_GROUP_ID] = info.filtered;
135138
},
136-
async getGroups(languageCode) {
137-
await getListGroups({
138-
$axios: this.$axios,
139-
path: `${languageCode}/${namespace}/groups`,
140-
languageCode,
141-
onSuccess: payload => this.getGroupsSuccess({
142-
...payload,
143-
languageCode,
144-
}),
145-
});
146-
},
147-
getGroupsSuccess({
148-
groups,
149-
items,
150-
groupItemsCount,
151-
languageCode,
152-
}) {
153-
this.groups = {
154-
...this.groups,
155-
[languageCode]: groups,
156-
};
157-
this.items = {
158-
...this.items,
159-
[languageCode]: items,
160-
};
161-
this.groupItemsCount = groupItemsCount;
162-
},
163139
async getGroupItems({
164140
groupId,
165141
languageCode,

modules/@ergonode/import/src/components/Modals/ImportDetailsModalGrid.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export default {
9898
filterValues: {},
9999
filtered: 0,
100100
isPrefetchingData: true,
101-
localParams: DEFAULT_GRID_FETCH_PARAMS,
102-
pagination: DEFAULT_GRID_PAGINATION,
101+
localParams: DEFAULT_GRID_FETCH_PARAMS(),
102+
pagination: DEFAULT_GRID_PAGINATION(),
103103
};
104104
},
105105
methods: {
@@ -134,16 +134,14 @@ export default {
134134
135135
this.onFetchData();
136136
},
137-
async onFetchData(params = this.localParams) {
138-
this.localParams = params;
139-
137+
async onFetchData() {
140138
await getGridData({
141139
$route: this.$route,
142140
$cookies: this.$cookies,
143141
$axios: this.$axios,
144142
path: `sources/${this.sourceId}/imports/${this.importId}/errors`,
145143
params: {
146-
...params,
144+
...this.localParams,
147145
extended: true,
148146
},
149147
onSuccess: this.onFetchGridDataSuccess,

0 commit comments

Comments
 (0)