@cloud-ru/uikit-product-calculator 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/hooks/useProductDelete.js +13 -12
- package/dist/esm/hooks/useProductDelete.js +13 -12
- package/package.json +5 -5
- package/src/hooks/useProductDelete.ts +26 -22
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 2.3.0 (2026-10-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **SITE-12293:** update calculator menu ([ea3b498](https://github.com/cloud-ru-tech/uikit-product/commit/ea3b49829332998065599ea4e712ffca5bf6a51c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 2.2.0 (2026-10-19)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -4,27 +4,28 @@ exports.useProductDelete = useProductDelete;
|
|
|
4
4
|
const contexts_1 = require("../contexts");
|
|
5
5
|
const filterNonEmptyArrays_1 = require("../utils/filterNonEmptyArrays");
|
|
6
6
|
const deleteItem = (productId, idx) => (oldValue) => {
|
|
7
|
-
const oldArrayValue = oldValue[productId
|
|
7
|
+
const oldArrayValue = oldValue[productId];
|
|
8
8
|
if (!oldArrayValue) {
|
|
9
9
|
return oldValue;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
const newValue = Object.assign(Object.assign({}, oldValue), { [productId]: oldArrayValue });
|
|
13
|
-
return Object.assign({}, (0, filterNonEmptyArrays_1.filterNonEmptyArrays)(newValue));
|
|
11
|
+
return (0, filterNonEmptyArrays_1.filterNonEmptyArrays)(Object.assign(Object.assign({}, oldValue), { [productId]: oldArrayValue.filter((_, itemIdx) => itemIdx !== idx) }));
|
|
14
12
|
};
|
|
15
13
|
function useProductDelete() {
|
|
16
14
|
const { setSelectedProduct, selectedProduct, products, setProducts, actions: { onProductDelete }, } = (0, contexts_1.useCalculatorContext)();
|
|
17
15
|
return (productId, idx) => {
|
|
16
|
+
const nextProducts = deleteItem(productId, idx)(products);
|
|
18
17
|
setProducts(deleteItem(productId, idx));
|
|
19
18
|
onProductDelete === null || onProductDelete === void 0 ? void 0 : onProductDelete(productId);
|
|
20
|
-
if ((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.id)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
if ((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.id) !== productId) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (selectedProduct.idx > idx) {
|
|
23
|
+
setSelectedProduct({ id: productId, idx: selectedProduct.idx - 1 });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (selectedProduct.idx === idx) {
|
|
27
|
+
const newProductId = Object.keys(nextProducts).find(id => nextProducts[id].length > 0);
|
|
28
|
+
setSelectedProduct(newProductId ? { id: newProductId, idx: 0 } : null);
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { useCalculatorContext } from '../contexts';
|
|
2
2
|
import { filterNonEmptyArrays } from '../utils/filterNonEmptyArrays';
|
|
3
3
|
const deleteItem = (productId, idx) => (oldValue) => {
|
|
4
|
-
const oldArrayValue = oldValue[productId
|
|
4
|
+
const oldArrayValue = oldValue[productId];
|
|
5
5
|
if (!oldArrayValue) {
|
|
6
6
|
return oldValue;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
const newValue = Object.assign(Object.assign({}, oldValue), { [productId]: oldArrayValue });
|
|
10
|
-
return Object.assign({}, filterNonEmptyArrays(newValue));
|
|
8
|
+
return filterNonEmptyArrays(Object.assign(Object.assign({}, oldValue), { [productId]: oldArrayValue.filter((_, itemIdx) => itemIdx !== idx) }));
|
|
11
9
|
};
|
|
12
10
|
export function useProductDelete() {
|
|
13
11
|
const { setSelectedProduct, selectedProduct, products, setProducts, actions: { onProductDelete }, } = useCalculatorContext();
|
|
14
12
|
return (productId, idx) => {
|
|
13
|
+
const nextProducts = deleteItem(productId, idx)(products);
|
|
15
14
|
setProducts(deleteItem(productId, idx));
|
|
16
15
|
onProductDelete === null || onProductDelete === void 0 ? void 0 : onProductDelete(productId);
|
|
17
|
-
if ((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.id)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
if ((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.id) !== productId) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (selectedProduct.idx > idx) {
|
|
20
|
+
setSelectedProduct({ id: productId, idx: selectedProduct.idx - 1 });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (selectedProduct.idx === idx) {
|
|
24
|
+
const newProductId = Object.keys(nextProducts).find(id => nextProducts[id].length > 0);
|
|
25
|
+
setSelectedProduct(newProductId ? { id: newProductId, idx: 0 } : null);
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/uikit-product-calculator",
|
|
3
3
|
"title": "Calculator",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css",
|
|
7
7
|
"*.woff",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"lodash": "^4.18.1",
|
|
62
62
|
"swr": "^2.2.5",
|
|
63
63
|
"@cloud-ru/uikit-product-icons": "^19.2.0",
|
|
64
|
-
"@cloud-ru/uikit-product-mobile-modal": "^3.0.2",
|
|
65
|
-
"@cloud-ru/uikit-product-utils": "^10.0.0",
|
|
66
|
-
"@cloud-ru/uikit-product-mobile-fields": "^3.0.2",
|
|
67
64
|
"@cloud-ru/uikit-product-mobile-dropdown": "^3.0.2",
|
|
68
|
-
"@cloud-ru/uikit-product-mobile-
|
|
65
|
+
"@cloud-ru/uikit-product-mobile-fields": "^3.0.2",
|
|
66
|
+
"@cloud-ru/uikit-product-mobile-modal": "^3.0.2",
|
|
67
|
+
"@cloud-ru/uikit-product-mobile-accordion": "^2.0.2",
|
|
68
|
+
"@cloud-ru/uikit-product-utils": "^10.0.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/lodash": "4.17.24"
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { useCalculatorContext } from '../contexts';
|
|
2
|
-
import { FormValues } from '../types';
|
|
1
|
+
import { ProductsState, useCalculatorContext } from '../contexts';
|
|
3
2
|
import { filterNonEmptyArrays } from '../utils/filterNonEmptyArrays';
|
|
4
3
|
|
|
5
|
-
const deleteItem =
|
|
6
|
-
|
|
4
|
+
const deleteItem =
|
|
5
|
+
(productId: string, idx: number) =>
|
|
6
|
+
(oldValue: ProductsState): ProductsState => {
|
|
7
|
+
const oldArrayValue = oldValue[productId];
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
oldArrayValue.splice(idx ?? 0, 1);
|
|
9
|
+
if (!oldArrayValue) {
|
|
10
|
+
return oldValue;
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return filterNonEmptyArrays({
|
|
14
|
+
...oldValue,
|
|
15
|
+
[productId]: oldArrayValue.filter((_, itemIdx) => itemIdx !== idx),
|
|
16
|
+
});
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
return { ...filterNonEmptyArrays(newValue) };
|
|
20
|
-
};
|
|
21
|
-
|
|
22
19
|
export function useProductDelete() {
|
|
23
20
|
const {
|
|
24
21
|
setSelectedProduct,
|
|
@@ -29,18 +26,25 @@ export function useProductDelete() {
|
|
|
29
26
|
} = useCalculatorContext();
|
|
30
27
|
|
|
31
28
|
return (productId: string, idx: number) => {
|
|
29
|
+
const nextProducts = deleteItem(productId, idx)(products);
|
|
30
|
+
|
|
32
31
|
setProducts(deleteItem(productId, idx));
|
|
33
32
|
|
|
34
33
|
onProductDelete?.(productId);
|
|
35
34
|
|
|
36
|
-
if (selectedProduct?.id
|
|
37
|
-
|
|
35
|
+
if (selectedProduct?.id !== productId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (selectedProduct.idx > idx) {
|
|
40
|
+
setSelectedProduct({ id: productId, idx: selectedProduct.idx - 1 });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (selectedProduct.idx === idx) {
|
|
45
|
+
const newProductId = Object.keys(nextProducts).find(id => nextProducts[id].length > 0);
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
setSelectedProduct({ id: newProductId, idx: 0 });
|
|
41
|
-
} else {
|
|
42
|
-
setSelectedProduct(null);
|
|
43
|
-
}
|
|
47
|
+
setSelectedProduct(newProductId ? { id: newProductId, idx: 0 } : null);
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
}
|